10#ifndef MUELU_ZOLTAN2GRAPHADAPTER_HPP_
11#define MUELU_ZOLTAN2GRAPHADAPTER_HPP_
15#if defined(HAVE_MUELU_ZOLTAN2)
17#include <Teuchos_RCP.hpp>
18#include <Teuchos_Comm.hpp>
19#include <Teuchos_ArrayView.hpp>
20#include <Xpetra_Map.hpp>
21#include <Zoltan2_InputTraits.hpp>
22#include <Zoltan2_GraphAdapter.hpp>
23#include <Zoltan2_StridedData.hpp>
24#include <Zoltan2_PartitioningSolution.hpp>
25#include "MueLu_LWGraph.hpp"
33struct InputTraits<
MueLu::LWGraph<LocalOrdinal, GlobalOrdinal, Node> > {
38 typedef Zoltan2::default_part_t
part_t;
40 static inline std::string
name() {
return "MueLu::Graph"; }
42 Z2_STATIC_ASSERT_TYPES
48template <
typename User,
typename UserCoord = User>
51#ifndef DOXYGEN_SHOULD_SKIP_THIS
52 typedef typename Zoltan2::InputTraits<User>::scalar_t scalar_t;
53 typedef typename Zoltan2::InputTraits<User>::offset_t offset_t;
54 typedef typename Zoltan2::InputTraits<User>::lno_t lno_t;
55 typedef typename Zoltan2::InputTraits<User>::gno_t gno_t;
56 typedef typename Zoltan2::InputTraits<User>::part_t part_t;
57 typedef typename Zoltan2::InputTraits<User>::node_t node_t;
58 typedef User xgraph_t;
60 typedef UserCoord userCoord_t;
64 const Teuchos::RCP<const Teuchos::Comm<int> >
getComm()
const {
return graph_->GetComm(); }
65 const Teuchos::RCP<const Xpetra::Map<lno_t, gno_t, node_t> >
getRowMap()
const {
return graph_->GetDomainMap(); }
66 const RCP<const Xpetra::Map<lno_t, gno_t, node_t> >
getColMap()
const {
69 Teuchos::RCP<const Xpetra::Map<lno_t, gno_t, node_t> > map =
graph_->GetImportMap();
70 if (map.is_null()) map =
graph_->GetDomainMap();
77 void getLocalRowView(lno_t LocalRow, Teuchos::ArrayView<const lno_t> &indices)
const {
78 indices =
graph_->getNeighborVertices_av(LocalRow);
95 int nVtxWeights = 0,
int nEdgeWeights = 0);
109 void setWeights(
const scalar_t *val,
int stride,
int idx);
189 ids =
getRowMap()->getLocalElementList().getRawPtr();
194 void getEdgesView(
const offset_t *&offsets,
const gno_t *&adjIds)
const {
195 offsets =
offs_.getRawPtr();
204 std::ostringstream emsg;
205 emsg << __FILE__ <<
":" << __LINE__
206 <<
" Invalid vertex weight index " << idx << std::endl;
207 throw std::runtime_error(emsg.str());
220 std::ostringstream emsg;
221 emsg << __FILE__ <<
":" << __LINE__
222 <<
" Invalid edge weight index " << idx << std::endl;
223 throw std::runtime_error(emsg.str());
227 edgeWeights_[idx].getStridedList(length, weights, stride);
230 template <
typename Adapter>
232 const Zoltan2::PartitioningSolution<Adapter> &solution)
const {
233 TEUCHOS_TEST_FOR_EXCEPTION(1, std::invalid_argument,
"applyPartitionlingSolution not implemeneted");
236 template <
typename Adapter>
238 const Zoltan2::PartitioningSolution<Adapter> &solution)
const {
239 TEUCHOS_TEST_FOR_EXCEPTION(1, std::invalid_argument,
"applyPartitionlingSolution not implemeneted");
245 RCP<const Teuchos::Comm<int> >
comm_;
258 ArrayRCP<Zoltan2::StridedData<lno_t, scalar_t> >
coords_;
265template <
typename User,
typename UserCoord>
267 const RCP<const User> &ingraph,
int nVtxWgts,
int nEdgeWgts)
273 , nWeightsPerVertex_(nVtxWgts)
275 , vertexDegreeWeight_()
276 , nWeightsPerEdge_(nEdgeWgts)
280 typedef Zoltan2::StridedData<lno_t, scalar_t> input_t;
291 offset_t *offs =
const_cast<offset_t *
>(
offs_.getRawPtr());
295 adjids =
const_cast<gno_t *
>(
adjids_.getRawPtr());
299 for (
size_t v = 0; v < nvtx; v++) {
300 ArrayView<const lno_t> nbors;
302 offs[v + 1] = offs[v] + nbors.size();
303 for (offset_t e = offs[v], i = 0; e < offs[v + 1]; e++) {
304 adjids[e] =
getColMap()->getGlobalElement(nbors[i++]);
319template <
typename User,
typename UserCoord>
321 const scalar_t *weightVal,
int stride,
int idx) {
322 if (this->getPrimaryEntityType() == Zoltan2::GRAPH_VERTEX)
323 setVertexWeights(weightVal, stride, idx);
325 setEdgeWeights(weightVal, stride, idx);
329template <
typename User,
typename UserCoord>
331 const scalar_t *weightVal,
int stride,
int idx) {
332 typedef Zoltan2::StridedData<lno_t, scalar_t> input_t;
334 if (idx < 0 || idx >= nWeightsPerVertex_) {
335 std::ostringstream emsg;
336 emsg << __FILE__ <<
":" << __LINE__
337 <<
" Invalid vertex weight index " << idx << std::endl;
338 throw std::runtime_error(emsg.str());
341 size_t nvtx = getLocalNumVertices();
342 ArrayRCP<const scalar_t> weightV(weightVal, 0, nvtx * stride,
false);
343 vertexWeights_[idx] = input_t(weightV, stride);
347template <
typename User,
typename UserCoord>
350 if (this->getPrimaryEntityType() == Zoltan2::GRAPH_VERTEX)
351 setVertexWeightIsDegree(idx);
353 std::ostringstream emsg;
354 emsg << __FILE__ <<
"," << __LINE__
355 <<
" error: setWeightIsNumberOfNonZeros is supported only for"
356 <<
" vertices" << std::endl;
357 throw std::runtime_error(emsg.str());
362template <
typename User,
typename UserCoord>
365 if (idx < 0 || idx >= nWeightsPerVertex_) {
366 std::ostringstream emsg;
367 emsg << __FILE__ <<
":" << __LINE__
368 <<
" Invalid vertex weight index " << idx << std::endl;
369 throw std::runtime_error(emsg.str());
372 vertexDegreeWeight_[idx] =
true;
376template <
typename User,
typename UserCoord>
378 const scalar_t *weightVal,
int stride,
int idx) {
379 typedef Zoltan2::StridedData<lno_t, scalar_t> input_t;
381 if (idx < 0 || idx >= nWeightsPerEdge_) {
382 std::ostringstream emsg;
383 emsg << __FILE__ <<
":" << __LINE__
384 <<
" Invalid edge weight index " << idx << std::endl;
385 throw std::runtime_error(emsg.str());
388 size_t nedges = getLocalNumEdges();
389 ArrayRCP<const scalar_t> weightV(weightVal, 0, nedges * stride,
false);
390 edgeWeights_[idx] = input_t(weightV, stride);
MueLu::DefaultLocalOrdinal LocalOrdinal
MueLu::DefaultGlobalOrdinal GlobalOrdinal
void setEdgeWeights(const scalar_t *val, int stride, int idx)
Provide a pointer to edge weights.
size_t getLocalNumEdges() const
ArrayRCP< Zoltan2::StridedData< lno_t, scalar_t > > vertexWeights_
RCP< const Teuchos::Comm< int > > comm_
void applyPartitioningSolution(const User &in, RCP< User > &out, const Zoltan2::PartitioningSolution< Adapter > &solution) const
RCP< const User > getUserGraph() const
Access to user's graph.
ArrayRCP< Zoltan2::StridedData< lno_t, scalar_t > > coords_
void getEdgeWeightsView(const scalar_t *&weights, int &stride, int idx) const
ArrayRCP< const gno_t > adjids_
MueLuGraphBaseAdapter(const RCP< const User > &ingraph, int nVtxWeights=0, int nEdgeWeights=0)
Constructor for graph with no weights or coordinates.
void getEdgesView(const offset_t *&offsets, const gno_t *&adjIds) const
RCP< const User > ingraph_
size_t getLocalNumEntries() const
size_t getLocalNumCols() const
bool useDegreeAsVertexWeight(int idx) const
const Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
MueLu::GraphBase Compatibility Layer.
ArrayRCP< Zoltan2::StridedData< lno_t, scalar_t > > edgeWeights_
void setVertexWeightIsDegree(int idx)
Specify an index for which the vertex weight should be the degree of the vertex.
RCP< const xgraph_t > graph_
void applyPartitioningSolution(const User &in, User *&out, const Zoltan2::PartitioningSolution< Adapter > &solution) const
int getNumWeightsPerEdge() const
void getLocalRowView(lno_t LocalRow, Teuchos::ArrayView< const lno_t > &indices) const
ArrayRCP< const offset_t > offs_
void setWeights(const scalar_t *val, int stride, int idx)
Provide a pointer to weights for the primary entity type.
size_t getLocalNumVertices() const
void getVertexWeightsView(const scalar_t *&weights, int &stride, int idx) const
ArrayRCP< bool > vertexDegreeWeight_
void getVertexIDsView(const gno_t *&ids) const
const Teuchos::RCP< const Xpetra::Map< lno_t, gno_t, node_t > > getRowMap() const
size_t getLocalNumRows() const
const RCP< const Xpetra::Map< lno_t, gno_t, node_t > > getColMap() const
int getNumWeightsPerVertex() const
~MueLuGraphBaseAdapter()
Destructor.
void setVertexWeights(const scalar_t *val, int stride, int idx)
Provide a pointer to vertex weights.
RCP< const xgraph_t > getXpetraGraph() const
Access to Xpetra-wrapped user's graph.
void setWeightIsDegree(int idx)
Specify an index for which the weight should be the degree of the entity.
Namespace for MueLu classes and methods.