47 #ifndef MUELU_ZOLTAN2GRAPHADAPTER_HPP_
48 #define MUELU_ZOLTAN2GRAPHADAPTER_HPP_
52 #if defined(HAVE_MUELU_ZOLTAN2)
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>
62 #include "MueLu_LWGraph.hpp"
70 struct InputTraits<MueLu::LWGraph<LocalOrdinal, GlobalOrdinal, Node> > {
75 typedef Zoltan2::default_part_t
part_t;
77 static inline std::string
name() {
return "MueLu::Graph"; }
79 Z2_STATIC_ASSERT_TYPES
85 template <
typename User,
typename UserCoord = User>
88 #ifndef DOXYGEN_SHOULD_SKIP_THIS
89 typedef typename Zoltan2::InputTraits<User>::scalar_t scalar_t;
90 typedef typename Zoltan2::InputTraits<User>::offset_t offset_t;
91 typedef typename Zoltan2::InputTraits<User>::lno_t lno_t;
92 typedef typename Zoltan2::InputTraits<User>::gno_t gno_t;
93 typedef typename Zoltan2::InputTraits<User>::part_t part_t;
94 typedef typename Zoltan2::InputTraits<User>::node_t node_t;
95 typedef User xgraph_t;
97 typedef UserCoord userCoord_t;
115 indices =
graph_->getNeighborVertices_av(LocalRow);
132 int nVtxWeights = 0,
int nEdgeWeights = 0);
146 void setWeights(
const scalar_t *val,
int stride,
int idx);
226 ids =
getRowMap()->getLocalElementList().getRawPtr();
231 void getEdgesView(
const offset_t *&offsets,
const gno_t *&adjIds)
const {
241 std::ostringstream emsg;
242 emsg << __FILE__ <<
":" << __LINE__
243 <<
" Invalid vertex weight index " << idx << std::endl;
244 throw std::runtime_error(emsg.str());
257 std::ostringstream emsg;
258 emsg << __FILE__ <<
":" << __LINE__
259 <<
" Invalid edge weight index " << idx << std::endl;
260 throw std::runtime_error(emsg.str());
264 edgeWeights_[idx].getStridedList(length, weights, stride);
267 template <
typename Adapter>
269 const Zoltan2::PartitioningSolution<Adapter> &solution)
const {
273 template <
typename Adapter>
275 const Zoltan2::PartitioningSolution<Adapter> &solution)
const {
302 template <
typename User,
typename UserCoord>
310 , nWeightsPerVertex_(nVtxWgts)
312 , vertexDegreeWeight_()
313 , nWeightsPerEdge_(nEdgeWgts)
317 typedef Zoltan2::StridedData<lno_t, scalar_t> input_t;
336 for (
size_t v = 0; v < nvtx; v++) {
339 offs[v + 1] = offs[v] + nbors.
size();
340 for (offset_t e = offs[v], i = 0; e < offs[v + 1]; e++) {
341 adjids[e] =
getColMap()->getGlobalElement(nbors[i++]);
349 arcp(
new bool[nWeightsPerVertex_], 0, nWeightsPerVertex_,
true);
356 template <
typename User,
typename UserCoord>
358 const scalar_t *weightVal,
int stride,
int idx) {
359 if (this->getPrimaryEntityType() == Zoltan2::GRAPH_VERTEX)
360 setVertexWeights(weightVal, stride, idx);
362 setEdgeWeights(weightVal, stride, idx);
366 template <
typename User,
typename UserCoord>
368 const scalar_t *weightVal,
int stride,
int idx) {
369 typedef Zoltan2::StridedData<lno_t, scalar_t> input_t;
371 if (idx < 0 || idx >= nWeightsPerVertex_) {
372 std::ostringstream emsg;
373 emsg << __FILE__ <<
":" << __LINE__
374 <<
" Invalid vertex weight index " << idx << std::endl;
375 throw std::runtime_error(emsg.str());
378 size_t nvtx = getLocalNumVertices();
380 vertexWeights_[idx] = input_t(weightV, stride);
384 template <
typename User,
typename UserCoord>
387 if (this->getPrimaryEntityType() == Zoltan2::GRAPH_VERTEX)
388 setVertexWeightIsDegree(idx);
390 std::ostringstream emsg;
391 emsg << __FILE__ <<
"," << __LINE__
392 <<
" error: setWeightIsNumberOfNonZeros is supported only for"
393 <<
" vertices" << std::endl;
394 throw std::runtime_error(emsg.str());
399 template <
typename User,
typename UserCoord>
402 if (idx < 0 || idx >= nWeightsPerVertex_) {
403 std::ostringstream emsg;
404 emsg << __FILE__ <<
":" << __LINE__
405 <<
" Invalid vertex weight index " << idx << std::endl;
406 throw std::runtime_error(emsg.str());
409 vertexDegreeWeight_[idx] =
true;
413 template <
typename User,
typename UserCoord>
415 const scalar_t *weightVal,
int stride,
int idx) {
416 typedef Zoltan2::StridedData<lno_t, scalar_t> input_t;
418 if (idx < 0 || idx >= nWeightsPerEdge_) {
419 std::ostringstream emsg;
420 emsg << __FILE__ <<
":" << __LINE__
421 <<
" Invalid edge weight index " << idx << std::endl;
422 throw std::runtime_error(emsg.str());
425 size_t nedges = getLocalNumEdges();
427 edgeWeights_[idx] = input_t(weightV, stride);
432 #endif // HAVE_MUELU_ZOLTAN2
RCP< const User > ingraph_
void setWeightIsDegree(int idx)
Specify an index for which the weight should be the degree of the entity.
MueLu::DefaultLocalOrdinal LocalOrdinal
void setEdgeWeights(const scalar_t *val, int stride, int idx)
Provide a pointer to edge weights.
void getLocalRowView(lno_t LocalRow, Teuchos::ArrayView< const lno_t > &indices) const
const Teuchos::RCP< const Xpetra::Map< lno_t, gno_t, node_t > > getRowMap() const
ArrayRCP< Zoltan2::StridedData< lno_t, scalar_t > > coords_
ArrayRCP< const offset_t > offs_
size_t getLocalNumRows() const
void applyPartitioningSolution(const User &in, RCP< User > &out, const Zoltan2::PartitioningSolution< Adapter > &solution) const
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
size_t getLocalNumEdges() const
ArrayRCP< const gno_t > adjids_
void getEdgesView(const offset_t *&offsets, const gno_t *&adjIds) const
int getNumWeightsPerEdge() const
RCP< const xgraph_t > graph_
void setWeights(const scalar_t *val, int stride, int idx)
Provide a pointer to weights for the primary entity type.
void resize(const size_type n, const T &val=T())
~MueLuGraphBaseAdapter()
Destructor.
RCP< const xgraph_t > getXpetraGraph() const
Access to Xpetra-wrapped user's graph.
int getNumWeightsPerVertex() const
void getVertexIDsView(const gno_t *&ids) const
MueLu::DefaultGlobalOrdinal GlobalOrdinal
void setVertexWeightIsDegree(int idx)
Specify an index for which the vertex weight should be the degree of the vertex.
size_t getLocalNumCols() const
void setVertexWeights(const scalar_t *val, int stride, int idx)
Provide a pointer to vertex weights.
const Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
MueLu::GraphBase Compatibility Layer.
size_t getLocalNumVertices() const
bool useDegreeAsVertexWeight(int idx) const
void getVertexWeightsView(const scalar_t *&weights, int &stride, int idx) const
void applyPartitioningSolution(const User &in, User *&out, const Zoltan2::PartitioningSolution< Adapter > &solution) const
MueLuGraphBaseAdapter(const RCP< const User > &ingraph, int nVtxWeights=0, int nEdgeWeights=0)
Constructor for graph with no weights or coordinates.
ArrayRCP< Zoltan2::StridedData< lno_t, scalar_t > > vertexWeights_
ArrayRCP< Zoltan2::StridedData< lno_t, scalar_t > > edgeWeights_
ArrayRCP< bool > vertexDegreeWeight_
void getEdgeWeightsView(const scalar_t *&weights, int &stride, int idx) const
RCP< const User > getUserGraph() const
Access to user's graph.
size_t getLocalNumEntries() const
const RCP< const Xpetra::Map< lno_t, gno_t, node_t > > getColMap() const
RCP< const Teuchos::Comm< int > > comm_