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;
97 typedef UserCoord userCoord_t;
114 int nVtxWeights=0,
int nEdgeWeights=0);
128 void setWeights(
const scalar_t *val,
int stride,
int idx);
209 ids = graph_->getRowMap()->getNodeElementList().getRawPtr();
216 offsets = offs_.getRawPtr();
225 env_->localInputAssertion(__FILE__, __LINE__,
"invalid weight index",
228 vertexWeights_[idx].getStridedList(length, weights, stride);
237 env_->localInputAssertion(__FILE__, __LINE__,
"invalid weight index",
240 edgeWeights_[idx].getStridedList(length, weights, stride);
244 template <
typename Adapter>
248 template <
typename Adapter>
254 RCP<const User > ingraph_;
255 RCP<const xgraph_t > graph_;
256 RCP<const Comm<int> > comm_;
258 ArrayRCP<const lno_t> offs_;
259 ArrayRCP<const gno_t> adjids_;
261 int nWeightsPerVertex_;
262 ArrayRCP<StridedData<lno_t, scalar_t> > vertexWeights_;
263 ArrayRCP<bool> vertexDegreeWeight_;
265 int nWeightsPerEdge_;
266 ArrayRCP<StridedData<lno_t, scalar_t> > edgeWeights_;
269 ArrayRCP<StridedData<lno_t, scalar_t> > coords_;
274 RCP<const Environment> env_;
281 template <
typename User,
typename UserCoord>
283 const RCP<const User> &ingraph,
int nVtxWgts,
int nEdgeWgts):
284 ingraph_(ingraph), graph_(), comm_() , offs_(), adjids_(),
285 nWeightsPerVertex_(nVtxWgts), vertexWeights_(), vertexDegreeWeight_(),
286 nWeightsPerEdge_(nEdgeWgts), edgeWeights_(),
287 coordinateDim_(0), coords_(),
292 graph_ = rcp_const_cast<
const xgraph_t>(
294 comm_ = graph_->getComm();
295 size_t nvtx = graph_->getNodeNumRows();
296 size_t nedges = graph_->getNodeNumEntries();
302 lno_t *offs =
new lno_t [n];
303 env_->localMemoryAssertion(__FILE__, __LINE__, n, offs);
305 gno_t *adjids = NULL;
307 adjids =
new gno_t [nedges];
308 env_->localMemoryAssertion(__FILE__, __LINE__, nedges, adjids);
312 for (
size_t v=0; v < nvtx; v++){
313 ArrayView<const lno_t> nbors;
314 graph_->getLocalRowView(v, nbors);
315 offs[v+1] = offs[v] + nbors.size();
316 for (lno_t e=offs[v], i=0; e < offs[v+1]; e++)
317 adjids[e] = graph_->getColMap()->getGlobalElement(nbors[i++]);
320 offs_ = arcp(offs, 0, n,
true);
321 adjids_ = arcp(adjids, 0, nedges,
true);
323 if (nWeightsPerVertex_ > 0) {
325 arcp(
new input_t[nWeightsPerVertex_], 0, nWeightsPerVertex_,
true);
326 vertexDegreeWeight_ =
327 arcp(
new bool[nWeightsPerVertex_], 0, nWeightsPerVertex_,
true);
328 for (
int i=0; i < nWeightsPerVertex_; i++)
329 vertexDegreeWeight_[i] =
false;
332 if (nWeightsPerEdge_ > 0)
333 edgeWeights_ = arcp(
new input_t[nWeightsPerEdge_], 0, nWeightsPerEdge_,
true);
337 template <
typename User,
typename UserCoord>
339 const scalar_t *weightVal,
int stride,
int idx)
348 template <
typename User,
typename UserCoord>
350 const scalar_t *weightVal,
int stride,
int idx)
353 env_->localInputAssertion(__FILE__, __LINE__,
"invalid vertex weight index",
356 ArrayRCP<const scalar_t> weightV(weightVal, 0, nvtx*stride,
false);
357 vertexWeights_[idx] = input_t(weightV, stride);
361 template <
typename User,
typename UserCoord>
368 std::ostringstream emsg;
369 emsg << __FILE__ <<
"," << __LINE__
370 <<
" error: setWeightIsNumberOfNonZeros is supported only for" 371 <<
" vertices" << std::endl;
372 throw std::runtime_error(emsg.str());
377 template <
typename User,
typename UserCoord>
381 env_->localInputAssertion(__FILE__, __LINE__,
"invalid vertex weight index",
384 vertexDegreeWeight_[idx] =
true;
388 template <
typename User,
typename UserCoord>
390 const scalar_t *weightVal,
int stride,
int idx)
393 env_->localInputAssertion(__FILE__, __LINE__,
"invalid edge weight index",
396 ArrayRCP<const scalar_t> weightV(weightVal, 0, nedges*stride,
false);
397 edgeWeights_[idx] = input_t(weightV, stride);
401 template <
typename User,
typename UserCoord>
402 template<
typename Adapter>
404 const User &in, User *&out,
409 ArrayRCP<gno_t> importList;
413 (solution,
this, importList);
419 importList.getRawPtr());
425 template <
typename User,
typename UserCoord>
426 template<
typename Adapter>
428 const User &in, RCP<User> &out,
433 ArrayRCP<gno_t> importList;
437 (solution,
this, importList);
443 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.
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.