47#ifndef MUELU_ZOLTAN2GRAPHADAPTER_HPP_
48#define MUELU_ZOLTAN2GRAPHADAPTER_HPP_
52#if defined(HAVE_MUELU_ZOLTAN2)
54#include <Teuchos_RCP.hpp>
55#include <Teuchos_Comm.hpp>
56#include <Teuchos_ArrayView.hpp>
57#include <Xpetra_Map.hpp>
58#include <Zoltan2_InputTraits.hpp>
59#include <Zoltan2_GraphAdapter.hpp>
60#include <Zoltan2_StridedData.hpp>
61#include <Zoltan2_PartitioningSolution.hpp>
72struct InputTraits<
MueLu::GraphBase<LocalOrdinal,GlobalOrdinal,Node> >
78 typedef Zoltan2::default_part_t
part_t;
80 static inline std::string
name() {
return "MueLu::Graph";}
82 Z2_STATIC_ASSERT_TYPES
89template <
typename User,
typename UserCoord=User>
93#ifndef DOXYGEN_SHOULD_SKIP_THIS
94 typedef typename Zoltan2::InputTraits<User>::scalar_t scalar_t;
95 typedef typename Zoltan2::InputTraits<User>::offset_t offset_t;
96 typedef typename Zoltan2::InputTraits<User>::lno_t lno_t;
97 typedef typename Zoltan2::InputTraits<User>::gno_t gno_t;
98 typedef typename Zoltan2::InputTraits<User>::part_t part_t;
99 typedef typename Zoltan2::InputTraits<User>::node_t node_t;
100 typedef User xgraph_t;
102 typedef UserCoord userCoord_t;
106 const Teuchos::RCP< const Teuchos::Comm< int > >
getComm()
const {
return graph_->GetComm();}
107 const Teuchos::RCP< const Xpetra::Map<lno_t, gno_t, node_t> >
getRowMap()
const {
return graph_->GetDomainMap();}
108 const RCP< const Xpetra::Map<lno_t, gno_t, node_t> >
getColMap()
const {
111 Teuchos::RCP<const Xpetra::Map<lno_t,gno_t,node_t> > map =
graph_->GetImportMap();
112 if(map.is_null()) map =
graph_->GetDomainMap();
119 void getLocalRowView(lno_t LocalRow, Teuchos::ArrayView< const lno_t > &indices)
const {
120 indices =
graph_->getNeighborVertices(LocalRow);
139 int nVtxWeights=0,
int nEdgeWeights=0);
153 void setWeights(
const scalar_t *val,
int stride,
int idx);
234 ids =
getRowMap()->getLocalElementList().getRawPtr();
239 void getEdgesView(
const offset_t *&offsets,
const gno_t *&adjIds)
const
241 offsets =
offs_.getRawPtr();
252 std::ostringstream emsg;
253 emsg << __FILE__ <<
":" << __LINE__
254 <<
" Invalid vertex weight index " << idx << std::endl;
255 throw std::runtime_error(emsg.str());
271 std::ostringstream emsg;
272 emsg << __FILE__ <<
":" << __LINE__
273 <<
" Invalid edge weight index " << idx << std::endl;
274 throw std::runtime_error(emsg.str());
279 edgeWeights_[idx].getStridedList(length, weights, stride);
283 template <
typename Adapter>
285 const Zoltan2::PartitioningSolution<Adapter> &solution)
const {
286 TEUCHOS_TEST_FOR_EXCEPTION(1, std::invalid_argument,
"applyPartitionlingSolution not implemeneted");
289 template <
typename Adapter>
291 const Zoltan2::PartitioningSolution<Adapter> &solution)
const {
292 TEUCHOS_TEST_FOR_EXCEPTION(1, std::invalid_argument,
"applyPartitionlingSolution not implemeneted");
300 RCP<const Teuchos::Comm<int> >
comm_;
313 ArrayRCP<Zoltan2::StridedData<lno_t, scalar_t> >
coords_;
322template <
typename User,
typename UserCoord>
324 const RCP<const User> &ingraph,
int nVtxWgts,
int nEdgeWgts):
325 ingraph_(ingraph), graph_(), comm_() , offs_(), adjids_(),
326 nWeightsPerVertex_(nVtxWgts), vertexWeights_(), vertexDegreeWeight_(),
327 nWeightsPerEdge_(nEdgeWgts), edgeWeights_(),
328 coordinateDim_(0), coords_()
330 typedef Zoltan2::StridedData<lno_t,scalar_t> input_t;
341 offset_t* offs =
const_cast<offset_t*
>(
offs_.getRawPtr());
345 adjids =
const_cast<gno_t*
>(
adjids_.getRawPtr());
349 for (
size_t v=0; v < nvtx; v++){
350 ArrayView<const lno_t> nbors;
352 offs[v+1] = offs[v] + nbors.size();
353 for (offset_t e=offs[v], i=0; e < offs[v+1]; e++) {
354 adjids[e] =
getColMap()->getGlobalElement(nbors[i++]);
371template <
typename User,
typename UserCoord>
373 const scalar_t *weightVal,
int stride,
int idx)
375 if (this->getPrimaryEntityType() == Zoltan2::GRAPH_VERTEX)
376 setVertexWeights(weightVal, stride, idx);
378 setEdgeWeights(weightVal, stride, idx);
382template <
typename User,
typename UserCoord>
384 const scalar_t *weightVal,
int stride,
int idx)
386 typedef Zoltan2::StridedData<lno_t,scalar_t> input_t;
388 if(idx<0 || idx >= nWeightsPerVertex_)
390 std::ostringstream emsg;
391 emsg << __FILE__ <<
":" << __LINE__
392 <<
" Invalid vertex weight index " << idx << std::endl;
393 throw std::runtime_error(emsg.str());
396 size_t nvtx = getLocalNumVertices();
397 ArrayRCP<const scalar_t> weightV(weightVal, 0, nvtx*stride,
false);
398 vertexWeights_[idx] = input_t(weightV, stride);
402template <
typename User,
typename UserCoord>
406 if (this->getPrimaryEntityType() == Zoltan2::GRAPH_VERTEX)
407 setVertexWeightIsDegree(idx);
409 std::ostringstream emsg;
410 emsg << __FILE__ <<
"," << __LINE__
411 <<
" error: setWeightIsNumberOfNonZeros is supported only for"
412 <<
" vertices" << std::endl;
413 throw std::runtime_error(emsg.str());
418template <
typename User,
typename UserCoord>
422 if(idx<0 || idx >= nWeightsPerVertex_)
424 std::ostringstream emsg;
425 emsg << __FILE__ <<
":" << __LINE__
426 <<
" Invalid vertex weight index " << idx << std::endl;
427 throw std::runtime_error(emsg.str());
430 vertexDegreeWeight_[idx] =
true;
434template <
typename User,
typename UserCoord>
436 const scalar_t *weightVal,
int stride,
int idx)
438 typedef Zoltan2::StridedData<lno_t,scalar_t> input_t;
440 if(idx<0 || idx >= nWeightsPerEdge_)
442 std::ostringstream emsg;
443 emsg << __FILE__ <<
":" << __LINE__
444 <<
" Invalid edge weight index " << idx << std::endl;
445 throw std::runtime_error(emsg.str());
448 size_t nedges = getLocalNumEdges();
449 ArrayRCP<const scalar_t> weightV(weightVal, 0, nedges*stride,
false);
450 edgeWeights_[idx] = input_t(weightV, stride);
MueLu::DefaultLocalOrdinal LocalOrdinal
MueLu::DefaultGlobalOrdinal GlobalOrdinal
RCP< const xgraph_t > graph_
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
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.
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
RCP< const User > ingraph_
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.