14 #ifndef _ZOLTAN2_XPETRACRSGRAPHADAPTER_HPP_
15 #define _ZOLTAN2_XPETRACRSGRAPHADAPTER_HPP_
22 #include <Xpetra_CrsGraph.hpp>
47 template <
typename User,
typename UserCoord=User>
52 #ifndef DOXYGEN_SHOULD_SKIP_THIS
59 typedef Xpetra::CrsGraph<lno_t, gno_t, node_t>
xgraph_t;
61 typedef UserCoord userCoord_t;
76 int nVtxWeights=0,
int nEdgeWeights=0);
173 ids = graph_->getRowMap()->getLocalElementList().getRawPtr();
180 offsets = offs_.getRawPtr();
187 int idx)
const override
189 if(idx<0 || idx >= nWeightsPerVertex_)
191 std::ostringstream emsg;
192 emsg << __FILE__ <<
":" << __LINE__
193 <<
" Invalid vertex weight index " << idx << std::endl;
194 throw std::runtime_error(emsg.str());
199 vertexWeights_[idx].getStridedList(length, weights, stride);
208 if(idx<0 || idx >= nWeightsPerEdge_)
210 std::ostringstream emsg;
211 emsg << __FILE__ <<
":" << __LINE__
212 <<
" Invalid edge weight index " << idx << std::endl;
213 throw std::runtime_error(emsg.str());
218 edgeWeights_[idx].getStridedList(length, weights, stride);
221 template <
typename Adapter>
225 template <
typename Adapter>
231 RCP<const User > ingraph_;
232 RCP<const xgraph_t > graph_;
233 RCP<const Comm<int> > comm_;
235 ArrayRCP<const offset_t> offs_;
236 ArrayRCP<const gno_t> adjids_;
238 int nWeightsPerVertex_;
239 ArrayRCP<StridedData<lno_t, scalar_t> > vertexWeights_;
240 ArrayRCP<bool> vertexDegreeWeight_;
242 int nWeightsPerEdge_;
243 ArrayRCP<StridedData<lno_t, scalar_t> > edgeWeights_;
246 ArrayRCP<StridedData<lno_t, scalar_t> > coords_;
254 template <
typename User,
typename UserCoord>
256 const RCP<const User> &ingraph,
int nVtxWgts,
int nEdgeWgts):
257 ingraph_(ingraph), graph_(), comm_() , offs_(), adjids_(),
258 nWeightsPerVertex_(nVtxWgts), vertexWeights_(), vertexDegreeWeight_(),
259 nWeightsPerEdge_(nEdgeWgts), edgeWeights_(),
260 coordinateDim_(0), coords_()
265 graph_ = rcp_const_cast<
const xgraph_t>(
270 comm_ = graph_->getComm();
271 size_t nvtx = graph_->getLocalNumRows();
272 size_t nedges = graph_->getLocalNumEntries();
282 std::cerr <<
"Error: " << __FILE__ <<
", " << __LINE__<< std::endl;
283 std::cerr << n <<
" objects" << std::endl;
284 throw std::bad_alloc();
287 gno_t *adjids = NULL;
290 adjids =
new gno_t [nedges];
294 std::cerr <<
"Error: " << __FILE__ <<
", " << __LINE__<< std::endl;
295 std::cerr << nedges <<
" objects" << std::endl;
296 throw std::bad_alloc();
301 for (
size_t v=0; v < nvtx; v++){
302 ArrayView<const lno_t> nbors;
303 graph_->getLocalRowView(v, nbors);
304 offs[v+1] = offs[v] + nbors.size();
305 for (
offset_t e=offs[v], i=0; e < offs[v+1]; e++)
306 adjids[e] = graph_->getColMap()->getGlobalElement(nbors[i++]);
309 offs_ = arcp(offs, 0, n,
true);
310 adjids_ = arcp(adjids, 0, nedges,
true);
312 if (nWeightsPerVertex_ > 0) {
314 arcp(
new input_t[nWeightsPerVertex_], 0, nWeightsPerVertex_,
true);
315 vertexDegreeWeight_ =
316 arcp(
new bool[nWeightsPerVertex_], 0, nWeightsPerVertex_,
true);
317 for (
int i=0; i < nWeightsPerVertex_; i++)
318 vertexDegreeWeight_[i] =
false;
321 if (nWeightsPerEdge_ > 0)
322 edgeWeights_ = arcp(
new input_t[nWeightsPerEdge_], 0, nWeightsPerEdge_,
true);
326 template <
typename User,
typename UserCoord>
328 const scalar_t *weightVal,
int stride,
int idx)
331 setVertexWeights(weightVal, stride, idx);
333 setEdgeWeights(weightVal, stride, idx);
337 template <
typename User,
typename UserCoord>
339 const scalar_t *weightVal,
int stride,
int idx)
343 if(idx<0 || idx >= nWeightsPerVertex_)
345 std::ostringstream emsg;
346 emsg << __FILE__ <<
":" << __LINE__
347 <<
" Invalid vertex weight index " << idx << std::endl;
348 throw std::runtime_error(emsg.str());
351 size_t nvtx = getLocalNumVertices();
352 ArrayRCP<const scalar_t> weightV(weightVal, 0, nvtx*stride,
false);
353 vertexWeights_[idx] = input_t(weightV, stride);
357 template <
typename User,
typename UserCoord>
362 setVertexWeightIsDegree(idx);
364 std::ostringstream emsg;
365 emsg << __FILE__ <<
"," << __LINE__
366 <<
" error: setWeightIsNumberOfNonZeros is supported only for"
367 <<
" vertices" << std::endl;
368 throw std::runtime_error(emsg.str());
373 template <
typename User,
typename UserCoord>
377 if(idx<0 || idx >= nWeightsPerVertex_)
379 std::ostringstream emsg;
380 emsg << __FILE__ <<
":" << __LINE__
381 <<
" Invalid vertex weight index " << idx << std::endl;
382 throw std::runtime_error(emsg.str());
385 vertexDegreeWeight_[idx] =
true;
389 template <
typename User,
typename UserCoord>
391 const scalar_t *weightVal,
int stride,
int idx)
395 if(idx<0 || idx >= nWeightsPerEdge_)
397 std::ostringstream emsg;
398 emsg << __FILE__ <<
":" << __LINE__
399 <<
" Invalid edge weight index " << idx << std::endl;
400 throw std::runtime_error(emsg.str());
403 size_t nedges = getLocalNumEdges();
404 ArrayRCP<const scalar_t> weightV(weightVal, 0, nedges*stride,
false);
405 edgeWeights_[idx] = input_t(weightV, stride);
409 template <
typename User,
typename UserCoord>
410 template<
typename Adapter>
412 const User &in, User *&out,
417 ArrayRCP<gno_t> importList;
421 (solution,
this, importList);
427 importList.getRawPtr());
433 template <
typename User,
typename UserCoord>
434 template<
typename Adapter>
436 const User &in, RCP<User> &out,
441 ArrayRCP<gno_t> importList;
445 (solution,
this, importList);
451 importList.getRawPtr());
Helper functions for Partitioning Problems.
RCP< const xgraph_t > getXpetraGraph() const
Access to Xpetra-wrapped user's graph.
#define Z2_FORWARD_EXCEPTIONS
Forward an exception back through call stack.
typename InputTraits< User >::scalar_t scalar_t
void setVertexWeightsHost(typename Base::ConstWeightsHostView &val, int idx)
GraphAdapter defines the interface for graph-based user data.
void setWeightsHost(typename Base::ConstWeightsHostView &val, int idx)
void setWeights(const scalar_t *val, int stride, int idx)
Provide a pointer to weights for the primary entity type.
map_t::global_ordinal_type gno_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.
size_t getLocalNumVertices() const override
Returns the number of vertices on this process.
typename InputTraits< User >::part_t part_t
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.
void getVertexWeightsView(const scalar_t *&weights, int &stride, int idx) const override
Provide a pointer to the vertex weights, if any.
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.
typename InputTraits< User >::node_t node_t
A PartitioningSolution is a solution to a partitioning problem.
int getNumWeightsPerEdge() const override
Returns the number (0 or greater) of edge weights.
size_t getLocalNumEdges() const override
Returns the number of edges on this process.
typename InputTraits< User >::gno_t gno_t
void setVertexWeightsDevice(typename Base::ConstWeightsDeviceView &val, int idx)
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 setEdgeWeights(const scalar_t *val, int stride, int idx)
Provide a pointer to edge weights.
void getVertexIDsView(const gno_t *&ids) const override
typename InputTraits< User >::offset_t offset_t
void getEdgeWeightsView(const scalar_t *&weights, int &stride, int idx) const override
Provide a pointer to the edge weights, if any.
void getEdgesView(const offset_t *&offsets, const gno_t *&adjIds) const override
int getNumWeightsPerVertex() const override
Returns the number (0 or greater) of weights per vertex.
Defines the GraphAdapter interface.
void setVertexWeightIsDegree(int idx)
Specify an index for which the vertex weight should be the degree of the vertex.
typename InputTraits< User >::lno_t lno_t
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
void setEdgeWeightsDevice(typename Base::ConstWeightsDeviceView &val, int idx)
bool useDegreeAsVertexWeight(int idx) const override
Indicate whether vertex weight with index idx should be the global degree of the vertex.
void setEdgeWeightsHost(typename Base::ConstWeightsHostView &val, int idx)
void setWeightsDevice(typename Base::ConstWeightsDeviceView &val, int idx)
This file defines the StridedData class.
Zoltan2::BasicUserTypes< zscalar_t, zlno_t, zgno_t > user_t