50#ifndef _ZOLTAN2_XPETRACRSGRAPHADAPTER_HPP_
51#define _ZOLTAN2_XPETRACRSGRAPHADAPTER_HPP_
58#include <Xpetra_CrsGraph.hpp>
83template <
typename User,
typename UserCoord=User>
88#ifndef DOXYGEN_SHOULD_SKIP_THIS
95 typedef Xpetra::CrsGraph<lno_t, gno_t, node_t>
xgraph_t;
97 typedef UserCoord userCoord_t;
114 int nVtxWeights=0,
int nEdgeWeights=0);
209 ids = graph_->getRowMap()->getLocalElementList().getRawPtr();
216 offsets = offs_.getRawPtr();
225 if(idx<0 || idx >= nWeightsPerVertex_)
227 std::ostringstream emsg;
228 emsg << __FILE__ <<
":" << __LINE__
229 <<
" Invalid vertex weight index " << idx << std::endl;
230 throw std::runtime_error(emsg.str());
235 vertexWeights_[idx].getStridedList(length,
weights, stride);
244 if(idx<0 || idx >= nWeightsPerEdge_)
246 std::ostringstream emsg;
247 emsg << __FILE__ <<
":" << __LINE__
248 <<
" Invalid edge weight index " << idx << std::endl;
249 throw std::runtime_error(emsg.str());
254 edgeWeights_[idx].getStridedList(length,
weights, stride);
258 template <
typename Adapter>
262 template <
typename Adapter>
268 RCP<const User > ingraph_;
269 RCP<const xgraph_t > graph_;
270 RCP<const Comm<int> > comm_;
272 ArrayRCP<const offset_t> offs_;
273 ArrayRCP<const gno_t> adjids_;
275 int nWeightsPerVertex_;
276 ArrayRCP<StridedData<lno_t, scalar_t> > vertexWeights_;
277 ArrayRCP<bool> vertexDegreeWeight_;
279 int nWeightsPerEdge_;
280 ArrayRCP<StridedData<lno_t, scalar_t> > edgeWeights_;
283 ArrayRCP<StridedData<lno_t, scalar_t> > coords_;
291template <
typename User,
typename UserCoord>
293 const RCP<const User> &ingraph,
int nVtxWgts,
int nEdgeWgts):
294 ingraph_(ingraph), graph_(), comm_() , offs_(), adjids_(),
295 nWeightsPerVertex_(nVtxWgts), vertexWeights_(), vertexDegreeWeight_(),
296 nWeightsPerEdge_(nEdgeWgts), edgeWeights_(),
297 coordinateDim_(0), coords_()
302 graph_ = rcp_const_cast<const xgraph_t>(
307 comm_ = graph_->getComm();
308 size_t nvtx = graph_->getLocalNumRows();
309 size_t nedges = graph_->getLocalNumEntries();
319 std::cerr <<
"Error: " << __FILE__ <<
", " << __LINE__<< std::endl;
320 std::cerr << n <<
" objects" << std::endl;
321 throw std::bad_alloc();
324 gno_t *adjids = NULL;
327 adjids =
new gno_t [nedges];
331 std::cerr <<
"Error: " << __FILE__ <<
", " << __LINE__<< std::endl;
332 std::cerr << nedges <<
" objects" << std::endl;
333 throw std::bad_alloc();
338 for (
size_t v=0; v < nvtx; v++){
339 ArrayView<const lno_t> nbors;
340 graph_->getLocalRowView(v, nbors);
341 offs[v+1] = offs[v] + nbors.size();
342 for (
offset_t e=offs[v], i=0; e < offs[v+1]; e++)
343 adjids[e] = graph_->getColMap()->getGlobalElement(nbors[i++]);
346 offs_ = arcp(offs, 0, n,
true);
347 adjids_ = arcp(adjids, 0, nedges,
true);
349 if (nWeightsPerVertex_ > 0) {
351 arcp(
new input_t[nWeightsPerVertex_], 0, nWeightsPerVertex_,
true);
352 vertexDegreeWeight_ =
353 arcp(
new bool[nWeightsPerVertex_], 0, nWeightsPerVertex_,
true);
354 for (
int i=0; i < nWeightsPerVertex_; i++)
355 vertexDegreeWeight_[i] =
false;
358 if (nWeightsPerEdge_ > 0)
359 edgeWeights_ = arcp(
new input_t[nWeightsPerEdge_], 0, nWeightsPerEdge_,
true);
363template <
typename User,
typename UserCoord>
365 const scalar_t *weightVal,
int stride,
int idx)
368 setVertexWeights(weightVal, stride, idx);
370 setEdgeWeights(weightVal, stride, idx);
374template <
typename User,
typename UserCoord>
376 const scalar_t *weightVal,
int stride,
int idx)
380 if(idx<0 || idx >= nWeightsPerVertex_)
382 std::ostringstream emsg;
383 emsg << __FILE__ <<
":" << __LINE__
384 <<
" Invalid vertex weight index " << idx << std::endl;
385 throw std::runtime_error(emsg.str());
388 size_t nvtx = getLocalNumVertices();
389 ArrayRCP<const scalar_t> weightV(weightVal, 0, nvtx*stride,
false);
390 vertexWeights_[idx] = input_t(weightV, stride);
394template <
typename User,
typename UserCoord>
399 setVertexWeightIsDegree(idx);
401 std::ostringstream emsg;
402 emsg << __FILE__ <<
"," << __LINE__
403 <<
" error: setWeightIsNumberOfNonZeros is supported only for"
404 <<
" vertices" << std::endl;
405 throw std::runtime_error(emsg.str());
410template <
typename User,
typename UserCoord>
414 if(idx<0 || idx >= nWeightsPerVertex_)
416 std::ostringstream emsg;
417 emsg << __FILE__ <<
":" << __LINE__
418 <<
" Invalid vertex weight index " << idx << std::endl;
419 throw std::runtime_error(emsg.str());
422 vertexDegreeWeight_[idx] =
true;
426template <
typename User,
typename UserCoord>
428 const scalar_t *weightVal,
int stride,
int idx)
432 if(idx<0 || idx >= nWeightsPerEdge_)
434 std::ostringstream emsg;
435 emsg << __FILE__ <<
":" << __LINE__
436 <<
" Invalid edge weight index " << idx << std::endl;
437 throw std::runtime_error(emsg.str());
440 size_t nedges = getLocalNumEdges();
441 ArrayRCP<const scalar_t> weightV(weightVal, 0, nedges*stride,
false);
442 edgeWeights_[idx] = input_t(weightV, stride);
446template <
typename User,
typename UserCoord>
447 template<
typename Adapter>
449 const User &in, User *&out,
454 ArrayRCP<gno_t> importList;
458 (solution,
this, importList);
464 importList.getRawPtr());
470template <
typename User,
typename UserCoord>
471 template<
typename Adapter>
473 const User &in, RCP<User> &out,
478 ArrayRCP<gno_t> importList;
482 (solution,
this, importList);
488 importList.getRawPtr());
Zoltan2::BasicUserTypes< zscalar_t, zlno_t, zgno_t > user_t
#define Z2_FORWARD_EXCEPTIONS
Forward an exception back through call stack.
Defines the GraphAdapter interface.
Helper functions for Partitioning Problems.
This file defines the StridedData class.
Traits of Xpetra classes, including migration method.
InputTraits< User >::node_t node_t
InputTraits< User >::offset_t offset_t
InputTraits< User >::part_t part_t
InputTraits< User >::scalar_t scalar_t
InputTraits< User >::lno_t lno_t
InputTraits< User >::gno_t gno_t
GraphAdapter defines the interface for graph-based user data.
A PartitioningSolution is a solution to a partitioning problem.
The StridedData class manages lists of weights or coordinates.
Provides access for Zoltan2 to Xpetra::CrsGraph data.
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.
size_t getLocalNumVertices() const
Returns the number of vertices on this process.
~XpetraCrsGraphAdapter()
Destructor.
void setWeights(const scalar_t *val, int stride, int idx)
Provide a pointer to weights for the primary entity type.
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 PartitioningSolution< Adapter > &solution) const
void setVertexWeights(const scalar_t *val, int stride, int idx)
Provide a pointer to vertex weights.
void getVertexWeightsView(const scalar_t *&weights, int &stride, int idx) const
Provide a pointer to the vertex weights, if any.
size_t getLocalNumEdges() const
Returns the number of edges on this process.
void setEdgeWeights(const scalar_t *val, int stride, int idx)
Provide a pointer to edge weights.
bool useDegreeAsVertexWeight(int idx) const
Indicate whether vertex weight with index idx should be the global degree of the vertex.
XpetraCrsGraphAdapter(const RCP< const User > &ingraph, int nVtxWeights=0, int nEdgeWeights=0)
Constructor for graph with no weights or coordinates.
void getEdgeWeightsView(const scalar_t *&weights, int &stride, int idx) const
Provide a pointer to the edge weights, if any.
RCP< const User > getUserGraph() const
Access to user's graph.
void getEdgesView(const offset_t *&offsets, const gno_t *&adjIds) const
int getNumWeightsPerEdge() const
Returns the number (0 or greater) of edge weights.
int getNumWeightsPerVertex() const
Returns the number (0 or greater) of weights per vertex.
void getVertexIDsView(const gno_t *&ids) const
map_t::global_ordinal_type gno_t
Created by mbenlioglu on Aug 31, 2020.
size_t getImportList(const PartitioningSolution< SolutionAdapter > &solution, const DataAdapter *const data, ArrayRCP< typename DataAdapter::gno_t > &imports)
From a PartitioningSolution, get a list of IDs to be imported. Assumes part numbers in PartitioningSo...
Defines the traits required for Tpetra, Eptra and Xpetra objects.
static RCP< User > doMigration(const User &from, size_t numLocalRows, const gno_t *myNewRows)
Migrate the object Given a user object and a new row distribution, create and return a new user objec...