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 if(idx<0 || idx >= nWeightsPerVertex_)
226 std::ostringstream emsg;
227 emsg << __FILE__ <<
":" << __LINE__
228 <<
" Invalid vertex weight index " << idx << std::endl;
229 throw std::runtime_error(emsg.str());
234 vertexWeights_[idx].getStridedList(length, weights, stride);
243 if(idx<0 || idx >= nWeightsPerEdge_)
245 std::ostringstream emsg;
246 emsg << __FILE__ <<
":" << __LINE__
247 <<
" Invalid edge weight index " << idx << std::endl;
248 throw std::runtime_error(emsg.str());
253 edgeWeights_[idx].getStridedList(length, weights, stride);
257 template <
typename Adapter>
261 template <
typename Adapter>
267 RCP<const User > ingraph_;
268 RCP<const xgraph_t > graph_;
269 RCP<const Comm<int> > comm_;
271 ArrayRCP<const lno_t> offs_;
272 ArrayRCP<const gno_t> adjids_;
274 int nWeightsPerVertex_;
275 ArrayRCP<StridedData<lno_t, scalar_t> > vertexWeights_;
276 ArrayRCP<bool> vertexDegreeWeight_;
278 int nWeightsPerEdge_;
279 ArrayRCP<StridedData<lno_t, scalar_t> > edgeWeights_;
282 ArrayRCP<StridedData<lno_t, scalar_t> > coords_;
290 template <
typename User,
typename UserCoord>
292 const RCP<const User> &ingraph,
int nVtxWgts,
int nEdgeWgts):
293 ingraph_(ingraph), graph_(), comm_() , offs_(), adjids_(),
294 nWeightsPerVertex_(nVtxWgts), vertexWeights_(), vertexDegreeWeight_(),
295 nWeightsPerEdge_(nEdgeWgts), edgeWeights_(),
296 coordinateDim_(0), coords_()
301 graph_ = rcp_const_cast<
const xgraph_t>(
306 comm_ = graph_->getComm();
307 size_t nvtx = graph_->getNodeNumRows();
308 size_t nedges = graph_->getNodeNumEntries();
318 std::cerr <<
"Error: " << __FILE__ <<
", " << __LINE__<< std::endl;
319 std::cerr << n <<
" objects" << std::endl;
320 throw std::bad_alloc();
323 gno_t *adjids = NULL;
326 adjids =
new gno_t [nedges];
330 std::cerr <<
"Error: " << __FILE__ <<
", " << __LINE__<< std::endl;
331 std::cerr << nedges <<
" objects" << std::endl;
332 throw std::bad_alloc();
337 for (
size_t v=0; v < nvtx; v++){
338 ArrayView<const lno_t> nbors;
339 graph_->getLocalRowView(v, nbors);
340 offs[v+1] = offs[v] + nbors.size();
341 for (
lno_t e=offs[v], i=0; e < offs[v+1]; e++)
342 adjids[e] = graph_->getColMap()->getGlobalElement(nbors[i++]);
345 offs_ = arcp(offs, 0, n,
true);
346 adjids_ = arcp(adjids, 0, nedges,
true);
348 if (nWeightsPerVertex_ > 0) {
350 arcp(
new input_t[nWeightsPerVertex_], 0, nWeightsPerVertex_,
true);
351 vertexDegreeWeight_ =
352 arcp(
new bool[nWeightsPerVertex_], 0, nWeightsPerVertex_,
true);
353 for (
int i=0; i < nWeightsPerVertex_; i++)
354 vertexDegreeWeight_[i] =
false;
357 if (nWeightsPerEdge_ > 0)
358 edgeWeights_ = arcp(
new input_t[nWeightsPerEdge_], 0, nWeightsPerEdge_,
true);
362 template <
typename User,
typename UserCoord>
364 const scalar_t *weightVal,
int stride,
int idx)
373 template <
typename User,
typename UserCoord>
375 const scalar_t *weightVal,
int stride,
int idx)
379 if(idx<0 || idx >= nWeightsPerVertex_)
381 std::ostringstream emsg;
382 emsg << __FILE__ <<
":" << __LINE__
383 <<
" Invalid vertex weight index " << idx << std::endl;
384 throw std::runtime_error(emsg.str());
388 ArrayRCP<const scalar_t> weightV(weightVal, 0, nvtx*stride,
false);
389 vertexWeights_[idx] = input_t(weightV, stride);
393 template <
typename User,
typename UserCoord>
400 std::ostringstream emsg;
401 emsg << __FILE__ <<
"," << __LINE__
402 <<
" error: setWeightIsNumberOfNonZeros is supported only for" 403 <<
" vertices" << std::endl;
404 throw std::runtime_error(emsg.str());
409 template <
typename User,
typename UserCoord>
413 if(idx<0 || idx >= nWeightsPerVertex_)
415 std::ostringstream emsg;
416 emsg << __FILE__ <<
":" << __LINE__
417 <<
" Invalid vertex weight index " << idx << std::endl;
418 throw std::runtime_error(emsg.str());
421 vertexDegreeWeight_[idx] =
true;
425 template <
typename User,
typename UserCoord>
427 const scalar_t *weightVal,
int stride,
int idx)
431 if(idx<0 || idx >= nWeightsPerEdge_)
433 std::ostringstream emsg;
434 emsg << __FILE__ <<
":" << __LINE__
435 <<
" Invalid edge weight index " << idx << std::endl;
436 throw std::runtime_error(emsg.str());
440 ArrayRCP<const scalar_t> weightV(weightVal, 0, nedges*stride,
false);
441 edgeWeights_[idx] = input_t(weightV, stride);
445 template <
typename User,
typename UserCoord>
446 template<
typename Adapter>
448 const User &in, User *&out,
453 ArrayRCP<gno_t> importList;
457 (solution,
this, importList);
463 importList.getRawPtr());
469 template <
typename User,
typename UserCoord>
470 template<
typename Adapter>
472 const User &in, RCP<User> &out,
477 ArrayRCP<gno_t> importList;
481 (solution,
this, importList);
487 importList.getRawPtr());
int getNumWeightsPerEdge() const
Returns the number (0 or greater) of edge weights.
void getVertexIDsView(const gno_t *&ids) const
Sets pointers to this process' graph entries.
InputTraits< User >::scalar_t scalar_t
~XpetraCrsGraphAdapter()
Destructor.
Helper functions for Partitioning Problems.
#define Z2_FORWARD_EXCEPTIONS
Forward an exception back through call stack.
bool useDegreeAsVertexWeight(int idx) const
Indicate whether vertex weight with index idx should be the global degree of the vertex.
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.
RCP< const xgraph_t > getXpetraGraph() const
Access to Xpetra-wrapped user's graph.
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.
size_t getLocalNumEdges() const
Returns the number of edges on this process.
Traits of Xpetra classes, including migration method.
RCP< const User > getUserGraph() const
Access to user's graph.
size_t getLocalNumVertices() const
Returns the number of vertices on this process.
static RCP< User > convertToXpetra(const RCP< User > &a)
Convert the object to its Xpetra wrapped version.
int getNumWeightsPerVertex() const
Returns the number (0 or greater) of weights per vertex.
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.
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.
InputTraits< User >::part_t part_t
void setEdgeWeights(const scalar_t *val, int stride, int idx)
Provide a pointer to edge weights.
void applyPartitioningSolution(const User &in, User *&out, const PartitioningSolution< Adapter > &solution) const
enum GraphEntityType getPrimaryEntityType() const
Returns the entity to be partitioned, ordered, colored, etc. Valid values are GRAPH_VERTEX or GRAPH_E...
void getVertexWeightsView(const scalar_t *&weights, int &stride, int idx) const
void getEdgesView(const lno_t *&offsets, const gno_t *&adjIds) const
Gets adjacency lists for all vertices in a compressed sparse row (CSR) format.
Defines the GraphAdapter interface.
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 getEdgeWeightsView(const scalar_t *&weights, int &stride, int idx) const
This file defines the StridedData class.