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
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()->getNodeElementList().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_;
291 template <
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_->getNodeNumRows();
309 size_t nedges = graph_->getNodeNumEntries();
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);
363 template <
typename User,
typename UserCoord>
365 const scalar_t *weightVal,
int stride,
int idx)
368 setVertexWeights(weightVal, stride, idx);
370 setEdgeWeights(weightVal, stride, idx);
374 template <
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);
394 template <
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());
410 template <
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;
426 template <
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);
446 template <
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());
470 template <
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());