10 #ifndef MUELU_ZOLTAN2GRAPHADAPTER_HPP_
11 #define MUELU_ZOLTAN2GRAPHADAPTER_HPP_
15 #if defined(HAVE_MUELU_ZOLTAN2)
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"
33 struct 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
48 template <
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;
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 {
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 {
236 template <
typename Adapter>
238 const Zoltan2::PartitioningSolution<Adapter> &solution)
const {
265 template <
typename User,
typename UserCoord>
273 , nWeightsPerVertex_(nVtxWgts)
275 , vertexDegreeWeight_()
276 , nWeightsPerEdge_(nEdgeWgts)
280 typedef Zoltan2::StridedData<lno_t, scalar_t> input_t;
299 for (
size_t v = 0; v < nvtx; v++) {
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++]);
312 arcp(
new bool[nWeightsPerVertex_], 0, nWeightsPerVertex_,
true);
319 template <
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);
329 template <
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();
343 vertexWeights_[idx] = input_t(weightV, stride);
347 template <
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());
362 template <
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;
376 template <
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();
390 edgeWeights_[idx] = input_t(weightV, stride);
395 #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_