50 #ifndef _ZOLTAN2_XPETRACRSGRAPHADAPTER_HPP_ 51 #define _ZOLTAN2_XPETRACRSGRAPHADAPTER_HPP_ 58 #include <Xpetra_CrsGraph.hpp> 83 template <
typename User,
typename UserCoord=User>
88 #ifndef DOXYGEN_SHOULD_SKIP_THIS 94 typedef Xpetra::CrsGraph<lno_t, gno_t, node_t>
xgraph_t;
96 typedef UserCoord userCoord_t;
113 int nVtxWeights=0,
int nEdgeWeights=0);
127 void setWeights(
const scalar_t *val,
int stride,
int idx);
208 ids = graph_->getRowMap()->getNodeElementList().getRawPtr();
215 offsets = offs_.getRawPtr();
224 env_->localInputAssertion(__FILE__, __LINE__,
"invalid weight index",
227 vertexWeights_[idx].getStridedList(length, weights, stride);
236 env_->localInputAssertion(__FILE__, __LINE__,
"invalid weight index",
239 edgeWeights_[idx].getStridedList(length, weights, stride);
243 template <
typename Adapter>
247 template <
typename Adapter>
253 RCP<const User > ingraph_;
254 RCP<const xgraph_t > graph_;
255 RCP<const Comm<int> > comm_;
257 ArrayRCP<const lno_t> offs_;
258 ArrayRCP<const gno_t> adjids_;
260 int nWeightsPerVertex_;
261 ArrayRCP<StridedData<lno_t, scalar_t> > vertexWeights_;
262 ArrayRCP<bool> vertexDegreeWeight_;
264 int nWeightsPerEdge_;
265 ArrayRCP<StridedData<lno_t, scalar_t> > edgeWeights_;
268 ArrayRCP<StridedData<lno_t, scalar_t> > coords_;
273 RCP<const Environment> env_;
280 template <
typename User,
typename UserCoord>
282 const RCP<const User> &ingraph,
int nVtxWgts,
int nEdgeWgts):
283 ingraph_(ingraph), graph_(), comm_() , offs_(), adjids_(),
284 nWeightsPerVertex_(nVtxWgts), vertexWeights_(), vertexDegreeWeight_(),
285 nWeightsPerEdge_(nEdgeWgts), edgeWeights_(),
286 coordinateDim_(0), coords_(),
292 graph_ = rcp_const_cast<
const xgraph_t>(
297 comm_ = graph_->getComm();
298 size_t nvtx = graph_->getNodeNumRows();
299 size_t nedges = graph_->getNodeNumEntries();
306 env_->localMemoryAssertion(__FILE__, __LINE__, n, offs);
308 gno_t *adjids = NULL;
310 adjids =
new gno_t [nedges];
311 env_->localMemoryAssertion(__FILE__, __LINE__, nedges, adjids);
315 for (
size_t v=0; v < nvtx; v++){
316 ArrayView<const lno_t> nbors;
317 graph_->getLocalRowView(v, nbors);
318 offs[v+1] = offs[v] + nbors.size();
319 for (
lno_t e=offs[v], i=0; e < offs[v+1]; e++)
320 adjids[e] = graph_->getColMap()->getGlobalElement(nbors[i++]);
323 offs_ = arcp(offs, 0, n,
true);
324 adjids_ = arcp(adjids, 0, nedges,
true);
326 if (nWeightsPerVertex_ > 0) {
328 arcp(
new input_t[nWeightsPerVertex_], 0, nWeightsPerVertex_,
true);
329 vertexDegreeWeight_ =
330 arcp(
new bool[nWeightsPerVertex_], 0, nWeightsPerVertex_,
true);
331 for (
int i=0; i < nWeightsPerVertex_; i++)
332 vertexDegreeWeight_[i] =
false;
335 if (nWeightsPerEdge_ > 0)
336 edgeWeights_ = arcp(
new input_t[nWeightsPerEdge_], 0, nWeightsPerEdge_,
true);
340 template <
typename User,
typename UserCoord>
342 const scalar_t *weightVal,
int stride,
int idx)
351 template <
typename User,
typename UserCoord>
353 const scalar_t *weightVal,
int stride,
int idx)
356 env_->localInputAssertion(__FILE__, __LINE__,
"invalid vertex weight index",
359 ArrayRCP<const scalar_t> weightV(weightVal, 0, nvtx*stride,
false);
360 vertexWeights_[idx] = input_t(weightV, stride);
364 template <
typename User,
typename UserCoord>
371 std::ostringstream emsg;
372 emsg << __FILE__ <<
"," << __LINE__
373 <<
" error: setWeightIsNumberOfNonZeros is supported only for" 374 <<
" vertices" << std::endl;
375 throw std::runtime_error(emsg.str());
380 template <
typename User,
typename UserCoord>
384 env_->localInputAssertion(__FILE__, __LINE__,
"invalid vertex weight index",
387 vertexDegreeWeight_[idx] =
true;
391 template <
typename User,
typename UserCoord>
393 const scalar_t *weightVal,
int stride,
int idx)
396 env_->localInputAssertion(__FILE__, __LINE__,
"invalid edge weight index",
399 ArrayRCP<const scalar_t> weightV(weightVal, 0, nedges*stride,
false);
400 edgeWeights_[idx] = input_t(weightV, stride);
404 template <
typename User,
typename UserCoord>
405 template<
typename Adapter>
407 const User &in, User *&out,
412 ArrayRCP<gno_t> importList;
416 (solution,
this, importList);
422 importList.getRawPtr());
428 template <
typename User,
typename UserCoord>
429 template<
typename Adapter>
431 const User &in, RCP<User> &out,
436 ArrayRCP<gno_t> importList;
440 (solution,
this, importList);
446 importList.getRawPtr());
InputTraits< User >::scalar_t scalar_t
~XpetraCrsGraphAdapter()
Destructor.
bool useDegreeAsVertexWeight(int idx) const
Indicate whether vertex weight with index idx should be the global degree of the vertex.
Helper functions for Partitioning Problems.
RCP< const xgraph_t > getXpetraGraph() const
Access to Xpetra-wrapped user's graph.
fast typical checks for valid arguments
#define Z2_FORWARD_EXCEPTIONS
Forward an exception back through call stack.
InputTraits< User >::gno_t gno_t
GraphAdapter defines the interface for graph-based user data.
void setWeights(const scalar_t *val, int stride, int idx)
Provide a pointer to weights for the primary entity type.
InputTraits< User >::lno_t lno_t
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...
Provides access for Zoltan2 to Xpetra::CrsGraph data.
Traits of Xpetra classes, including migration method.
int getNumWeightsPerEdge() const
Returns the number (0 or greater) of edge weights.
RCP< const User > getUserGraph() const
Access to user's graph.
static RCP< User > convertToXpetra(const RCP< User > &a)
Convert the object to its Xpetra wrapped version.
size_t getLocalNumEdges() const
Returns the number of edges on this process.
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...
XpetraCrsGraphAdapter(const RCP< const User > &ingraph, int nVtxWeights=0, int nEdgeWeights=0)
Constructor for graph with no weights or coordinates.
A PartitioningSolution is a solution to a partitioning problem.
int getNumWeightsPerVertex() const
Returns the number (0 or greater) of weights per vertex.
void setWeightIsDegree(int idx)
Specify an index for which the weight should be the degree of the entity.
The StridedData class manages lists of weights or coordinates.
void getEdgesView(const lno_t *&offsets, const gno_t *&adjIds) const
Gets adjacency lists for all vertices in a compressed sparse row (CSR) format.
InputTraits< User >::part_t part_t
The user parameters, debug, timing and memory profiling output objects, and error checking methods...
void setEdgeWeights(const scalar_t *val, int stride, int idx)
Provide a pointer to edge weights.
void getEdgeWeightsView(const scalar_t *&weights, int &stride, int idx) const
void getVertexIDsView(const gno_t *&ids) const
Sets pointers to this process' graph entries.
enum GraphEntityType getPrimaryEntityType() const
Returns the entity to be partitioned, ordered, colored, etc. Valid values are GRAPH_VERTEX or GRAPH_E...
Defines the GraphAdapter interface.
void getVertexWeightsView(const scalar_t *&weights, int &stride, int idx) const
void setVertexWeightIsDegree(int idx)
Specify an index for which the vertex weight should be the degree of the vertex.
void setVertexWeights(const scalar_t *val, int stride, int idx)
Provide a pointer to vertex weights.
void applyPartitioningSolution(const User &in, User *&out, const PartitioningSolution< Adapter > &solution) const
This file defines the StridedData class.
size_t getLocalNumVertices() const
Returns the number of vertices on this process.