Zoltan2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Zoltan2_TpetraRowGraphAdapter.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Zoltan2: A package of combinatorial algorithms for scientific computing
4 //
5 // Copyright 2012 NTESS and the Zoltan2 contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
14 #ifndef _ZOLTAN2_TPETRAROWGRAPHADAPTER_HPP_
15 #define _ZOLTAN2_TPETRAROWGRAPHADAPTER_HPP_
16 
17 #include "Kokkos_DualView.hpp"
18 #include "Kokkos_UnorderedMap.hpp"
19 #include <Tpetra_RowGraph.hpp>
20 #include <Zoltan2_GraphAdapter.hpp>
22 #include <Zoltan2_StridedData.hpp>
23 #include <string>
24 
25 namespace Zoltan2 {
26 
48 template <typename User, typename UserCoord = User>
49 class TpetraRowGraphAdapter : public GraphAdapter<User, UserCoord> {
50 
51 public:
52 #ifndef DOXYGEN_SHOULD_SKIP_THIS
53  using scalar_t = typename InputTraits<User>::scalar_t;
54  using offset_t = typename InputTraits<User>::offset_t;
55  using lno_t = typename InputTraits<User>::lno_t;
56  using gno_t = typename InputTraits<User>::gno_t;
57  using part_t = typename InputTraits<User>::part_t;
58  using node_t = typename InputTraits<User>::node_t;
59  using user_t = User;
60  using userCoord_t = UserCoord;
61 
62  using Base = GraphAdapter<User, UserCoord>;
63 #endif
64 
74  TpetraRowGraphAdapter(const RCP<const User> &ingraph, int nVtxWeights = 0,
75  int nEdgeWeights = 0);
76 
89  void setWeights(const scalar_t *val, int stride, int idx);
90 
99  void setWeightsDevice(typename Base::ConstWeightsDeviceView1D val, int idx);
100 
109  void setWeightsHost(typename Base::ConstWeightsHostView1D val, int idx);
110 
126  void setVertexWeights(const scalar_t *val, int stride, int idx);
127 
139  void setVertexWeightsDevice(typename Base::ConstWeightsDeviceView1D val,
140  int idx);
141 
153  void setVertexWeightsHost(typename Base::ConstWeightsHostView1D val, int idx);
154 
160  void setWeightIsDegree(int idx);
161 
167  void setVertexWeightIsDegree(int idx);
168 
191  void setEdgeWeights(const scalar_t *val, int stride, int idx);
192 
198  void setEdgeWeightsDevice(typename Base::ConstWeightsDeviceView1D val,
199  int idx);
200 
206  void setEdgeWeightsHost(typename Base::ConstWeightsHostView1D val, int idx);
207 
209  // The GraphAdapter interface.
211 
212  // TODO: Assuming rows == objects;
213  // TODO: Need to add option for columns or nonzeros?
214  size_t getLocalNumVertices() const override;
215 
216  void getVertexIDsView(const gno_t *&ids) const override;
217 
218  void
219  getVertexIDsDeviceView(typename Base::ConstIdsDeviceView &ids) const override;
220 
221  void
222  getVertexIDsHostView(typename Base::ConstIdsHostView &ids) const override;
223 
224  size_t getLocalNumEdges() const override;
225 
226  void getEdgesView(const offset_t *&offsets,
227  const gno_t *&adjIds) const override;
228 
229  void
230  getEdgesDeviceView(typename Base::ConstOffsetsDeviceView &offsets,
231  typename Base::ConstIdsDeviceView &adjIds) const override;
232 
233  void getEdgesHostView(typename Base::ConstOffsetsHostView &offsets,
234  typename Base::ConstIdsHostView &adjIds) const override;
235 
236  int getNumWeightsPerVertex() const override;
237 
238  void getVertexWeightsView(const scalar_t *&weights, int &stride,
239  int idx) const override;
240 
241  void getVertexWeightsDeviceView(typename Base::WeightsDeviceView1D &weights,
242  int idx = 0) const override;
243 
245  typename Base::WeightsDeviceView &weights) const override;
246 
247  void getVertexWeightsHostView(typename Base::WeightsHostView1D &weights,
248  int idx = 0) const override;
249 
251  typename Base::WeightsHostView &weights) const override;
252 
253  bool useDegreeAsVertexWeight(int idx) const override;
254 
255  int getNumWeightsPerEdge() const override;
256 
257  void getEdgeWeightsView(const scalar_t *&weights, int &stride,
258  int idx) const override;
259 
260  void getEdgeWeightsDeviceView(typename Base::WeightsDeviceView1D &weights,
261  int idx = 0) const override;
262 
264  typename Base::WeightsDeviceView &weights) const override;
265 
266  void getEdgeWeightsHostView(typename Base::WeightsHostView1D &weights,
267  int idx = 0) const override;
268 
270  typename Base::WeightsHostView &weights) const override;
271 
272  template <typename Adapter>
274  const User &in, User *&out,
275  const PartitioningSolution<Adapter> &solution) const;
276 
277  template <typename Adapter>
279  const User &in, RCP<User> &out,
280  const PartitioningSolution<Adapter> &solution) const;
281 
282 protected:
283  // Useb by TpetraCrsGraphAdapter
284  TpetraRowGraphAdapter(int nVtxWgts, int nEdgeWgts,
285  const RCP<const User> &graph)
286  : graph_(graph), nWeightsPerVertex_(nVtxWgts),
287  nWeightsPerEdge_(nEdgeWgts) {}
288 
289  RCP<const User> graph_;
290 
291  typename Base::ConstOffsetsHostView offsHost_;
292  typename Base::ConstIdsHostView adjIdsHost_;
293 
294  typename Base::ConstIdsDeviceView adjIdsDevice_;
295  typename Base::ConstOffsetsDeviceView offsDevice_;
296 
298  ArrayRCP<StridedData<lno_t, scalar_t>> vertexWeights_;
299  typename Base::WeightsDeviceView vertexWeightsDevice_;
300  typename Base::VtxDegreeHostView vertexDegreeWeightsHost_;
301 
303  ArrayRCP<StridedData<lno_t, scalar_t>> edgeWeights_;
304  typename Base::WeightsDeviceView edgeWeightsDevice_;
305 
306  virtual RCP<User> doMigration(const User &from, size_t numLocalRows,
307  const gno_t *myNewRows) const;
308 };
309 
311 // Definitions
313 
314 template <typename User, typename UserCoord>
316  const RCP<const User> &ingraph, int nVtxWgts, int nEdgeWgts)
317  : graph_(ingraph), nWeightsPerVertex_(nVtxWgts),
318  nWeightsPerEdge_(nEdgeWgts), edgeWeights_() {
319  using strided_t = StridedData<lno_t, scalar_t>;
320  using localInds_t = typename User::nonconst_local_inds_host_view_type;
321 
322  const auto nvtx = graph_->getLocalNumRows();
323  const auto nedges = graph_->getLocalNumEntries();
324  // Diff from CrsMatrix
325  const auto maxNumEntries = graph_->getLocalMaxNumRowEntries();
326 
327  // Unfortunately we have to copy the offsets and edge Ids
328  // because edge Ids are not usually stored in vertex id order.
329 
330  adjIdsHost_ = typename Base::ConstIdsHostView("adjIdsHost_", nedges);
331  offsHost_ = typename Base::ConstOffsetsHostView("offsHost_", nvtx + 1);
332 
333  localInds_t nbors("nbors", maxNumEntries);
334 
335  for (size_t v = 0; v < nvtx; v++) {
336  size_t numColInds = 0;
337  graph_->getLocalRowCopy(v, nbors, numColInds); // Diff from CrsGraph
338 
339  offsHost_(v + 1) = offsHost_(v) + numColInds;
340  for (offset_t e = offsHost_(v), i = 0; e < offsHost_(v + 1); e++) {
341  adjIdsHost_(e) = graph_->getColMap()->getGlobalElement(nbors(i++));
342  }
343  }
344 
345  // Since there's no direct getter of offsets and edges in device view,
346  // we have to deep copy here
347  offsDevice_ =
348  Kokkos::create_mirror_view_and_copy(typename Base::device_t(), offsHost_);
349  adjIdsDevice_ = Kokkos::create_mirror_view_and_copy(typename Base::device_t(),
350  adjIdsHost_);
351 
352  if (nWeightsPerVertex_ > 0) {
354  arcp(new strided_t[nWeightsPerVertex_], 0, nWeightsPerVertex_, true);
355 
356  vertexWeightsDevice_ = typename Base::WeightsDeviceView(
357  "vertexWeightsDevice_", nvtx, nWeightsPerVertex_);
358 
359  vertexDegreeWeightsHost_ = typename Base::VtxDegreeHostView(
360  "vertexDegreeWeightsHost_", nWeightsPerVertex_);
361 
362  for (int i = 0; i < nWeightsPerVertex_; ++i) {
363  vertexDegreeWeightsHost_(i) = false;
364  }
365  }
366 
367  if (nWeightsPerEdge_ > 0) {
368  edgeWeights_ =
369  arcp(new strided_t[nWeightsPerEdge_], 0, nWeightsPerEdge_, true);
370 
371  edgeWeightsDevice_ = typename Base::WeightsDeviceView(
372  "nWeightsPerEdge_", graph_->getLocalNumRows(), nWeightsPerEdge_);
373  }
374 }
375 
377 template <typename User, typename UserCoord>
379  const scalar_t *weightVal, int stride, int idx) {
380  if (this->getPrimaryEntityType() == GRAPH_VERTEX)
381  setVertexWeights(weightVal, stride, idx);
382  else
383  setEdgeWeights(weightVal, stride, idx);
384 }
385 
387 template <typename User, typename UserCoord>
389  typename Base::ConstWeightsDeviceView1D val, int idx) {
390  if (this->getPrimaryEntityType() == GRAPH_VERTEX)
391  setVertexWeightsDevice(val, idx);
392  else
393  setEdgeWeightsDevice(val, idx);
394 }
395 
397 template <typename User, typename UserCoord>
399  typename Base::ConstWeightsHostView1D val, int idx) {
400  if (this->getPrimaryEntityType() == GRAPH_VERTEX)
401  setVertexWeightsHost(val, idx);
402  else
403  setEdgeWeightsHost(val, idx);
404 }
405 
407 template <typename User, typename UserCoord>
409  const scalar_t *weightVal, int stride, int idx) {
410  AssertCondition((idx >= 0) and (idx < nWeightsPerVertex_),
411  "Invalid vertex weight index: " + std::to_string(idx));
412 
413  size_t nvtx = getLocalNumVertices();
414  ArrayRCP<const scalar_t> weightV(weightVal, 0, nvtx * stride, false);
415  vertexWeights_[idx] = input_t(weightV, stride);
416 }
417 
419 template <typename User, typename UserCoord>
421  typename Base::ConstWeightsDeviceView1D weights, int idx) {
422 
423  AssertCondition((idx >= 0) and (idx < nWeightsPerVertex_),
424  "Invalid vertex weight index: " + std::to_string(idx));
425 
426  AssertCondition(vertexWeightsDevice_.extent(0) == weights.extent(0),
427  "Invalid sizes!");
428 
429  Kokkos::parallel_for(
430  vertexWeightsDevice_.extent(0), KOKKOS_CLASS_LAMBDA(const int vertexID) {
431  vertexWeightsDevice_(vertexID, idx) = weights(vertexID);
432  });
433 
434  Kokkos::fence();
435 }
436 
438 template <typename User, typename UserCoord>
440  typename Base::ConstWeightsHostView1D weightsHost, int idx) {
441  AssertCondition((idx >= 0) and (idx < nWeightsPerVertex_),
442  "Invalid vertex weight index: " + std::to_string(idx));
443 
444  auto weightsDevice = Kokkos::create_mirror_view_and_copy(
445  typename Base::device_t(), weightsHost);
446 
447  setVertexWeightsDevice(weightsDevice, idx);
448 }
449 
451 template <typename User, typename UserCoord>
453  AssertCondition(this->getPrimaryEntityType() == GRAPH_VERTEX,
454  "setWeightIsNumberOfNonZeros is supported only for vertices");
455 
456  setVertexWeightIsDegree(idx);
457 }
458 
460 template <typename User, typename UserCoord>
462  AssertCondition((idx >= 0) and (idx < nWeightsPerVertex_),
463  "Invalid vertex weight index.");
464 
465  vertexDegreeWeightsHost_(idx) = true;
466 }
467 
469 template <typename User, typename UserCoord>
471  const scalar_t *weightVal, int stride, int idx) {
472  typedef StridedData<lno_t, scalar_t> input_t;
473 
474  AssertCondition((idx >= 0) and (idx < nWeightsPerEdge_),
475  "Invalid edge weight index" + std::to_string(idx));
476 
477  size_t nedges = getLocalNumEdges();
478  ArrayRCP<const scalar_t> weightV(weightVal, 0, nedges * stride, false);
479  edgeWeights_[idx] = input_t(weightV, stride);
480 }
481 
483 template <typename User, typename UserCoord>
485  typename Base::ConstWeightsDeviceView1D weights, int idx) {
486  AssertCondition((idx >= 0) and (idx < nWeightsPerVertex_),
487  "Invalid edge weight index.");
488 
489  AssertCondition(edgeWeightsDevice_.extent(0) == weights.extent(0),
490  "Invalid sizes!");
491 
492  Kokkos::parallel_for(
493  edgeWeightsDevice_.extent(0), KOKKOS_CLASS_LAMBDA(const int vertexID) {
494  edgeWeightsDevice_(vertexID, idx) = weights(vertexID);
495  });
496 
497  Kokkos::fence();
498 }
499 
501 template <typename User, typename UserCoord>
503  typename Base::ConstWeightsHostView1D weightsHost, int idx) {
504  AssertCondition((idx >= 0) and (idx < nWeightsPerVertex_),
505  "Invalid edge weight index.");
506 
507  auto weightsDevice = Kokkos::create_mirror_view_and_copy(
508  typename Base::device_t(), weightsHost);
509 
510  setEdgeWeightsDevice(weightsDevice);
511 }
512 
514 template <typename User, typename UserCoord>
516  return graph_->getLocalNumRows();
517 }
518 
520 template <typename User, typename UserCoord>
522  const gno_t *&ids) const {
523  ids = NULL;
524  if (getLocalNumVertices())
525  ids = graph_->getRowMap()->getLocalElementList().getRawPtr();
526 }
527 
529 template <typename User, typename UserCoord>
531  typename Base::ConstIdsDeviceView &ids) const {
532 
533  // TODO: Making a ConstIdsDeviceView LayoutLeft would proably remove the
534  // need of creating tmpIds
535  auto idsDevice = graph_->getRowMap()->getMyGlobalIndices();
536  auto tmpIds = typename Base::IdsDeviceView("", idsDevice.extent(0));
537 
538  Kokkos::deep_copy(tmpIds, idsDevice);
539 
540  ids = tmpIds;
541 }
542 
544 template <typename User, typename UserCoord>
546  typename Base::ConstIdsHostView &ids) const {
547  // TODO: Making a ConstIdsDeviceView LayoutLeft would proably remove the
548  // need of creating tmpIds
549  auto idsDevice = graph_->getRowMap()->getMyGlobalIndices();
550  auto tmpIds = typename Base::IdsHostView("", idsDevice.extent(0));
551 
552  Kokkos::deep_copy(tmpIds, idsDevice);
553 
554  ids = tmpIds;
555 }
556 
558 template <typename User, typename UserCoord>
560  return graph_->getLocalNumEntries();
561 }
562 
564 template <typename User, typename UserCoord>
566  const offset_t *&offsets, const gno_t *&adjIds) const {
567  offsets = offsHost_.data();
568  adjIds = (getLocalNumEdges() ? adjIdsHost_.data() : NULL);
569 }
570 
572 template <typename User, typename UserCoord>
574  typename Base::ConstOffsetsDeviceView &offsets,
575  typename Base::ConstIdsDeviceView &adjIds) const {
576 
577  offsets = offsDevice_;
578  adjIds = adjIdsDevice_;
579 }
580 
582 template <typename User, typename UserCoord>
584  typename Base::ConstOffsetsHostView &offsets,
585  typename Base::ConstIdsHostView &adjIds) const {
586 
587  auto hostIDs = Kokkos::create_mirror_view(adjIdsDevice_);
588  Kokkos::deep_copy(hostIDs, adjIdsDevice_);
589  adjIds = hostIDs;
590 
591  auto hostOffsets = Kokkos::create_mirror_view(offsDevice_);
592  Kokkos::deep_copy(hostOffsets, offsDevice_);
593  offsets = hostOffsets;
594 }
595 
597 template <typename User, typename UserCoord>
599  return nWeightsPerVertex_;
600 }
601 
603 template <typename User, typename UserCoord>
605  const scalar_t *&weights, int &stride, int idx) const {
606 
607  AssertCondition((idx >= 0) and (idx < nWeightsPerVertex_),
608  "Invalid vertex weight index.");
609 
610  size_t length;
611  vertexWeights_[idx].getStridedList(length, weights, stride);
612 }
613 
615 template <typename User, typename UserCoord>
617  typename Base::WeightsDeviceView1D &weights, int idx) const {
618  AssertCondition((idx >= 0) and (idx < nWeightsPerVertex_),
619  "Invalid vertex weight index.");
620 
621  const auto size = vertexWeightsDevice_.extent(0);
622  weights = typename Base::WeightsDeviceView1D("weights", size);
623 
624  Kokkos::parallel_for(
625  size, KOKKOS_CLASS_LAMBDA(const int id) {
626  weights(id) = vertexWeightsDevice_(id, idx);
627  });
628 
629  Kokkos::fence();
630 }
631 
633 template <typename User, typename UserCoord>
635  typename Base::WeightsDeviceView &weights) const {
636 
637  weights = vertexWeightsDevice_;
638 }
639 
641 template <typename User, typename UserCoord>
643  typename Base::WeightsHostView1D &weights, int idx) const {
644  AssertCondition((idx >= 0) and (idx < nWeightsPerVertex_),
645  "Invalid vertex weight index.");
646 
647  auto weightsDevice = typename Base::WeightsDeviceView1D(
648  "weights", vertexWeightsDevice_.extent(0));
649  getVertexWeightsDeviceView(weightsDevice, idx);
650 
651  weights = Kokkos::create_mirror_view(weightsDevice);
652  Kokkos::deep_copy(weights, weightsDevice);
653 }
654 
656 template <typename User, typename UserCoord>
658  typename Base::WeightsHostView &weights) const {
659 
660  weights = Kokkos::create_mirror_view(vertexWeightsDevice_);
661  Kokkos::deep_copy(weights, vertexWeightsDevice_);
662 }
663 
665 template <typename User, typename UserCoord>
667  int idx) const {
668  return vertexDegreeWeightsHost_(idx);
669 }
670 
672 template <typename User, typename UserCoord>
674  return nWeightsPerEdge_;
675 }
676 
678 template <typename User, typename UserCoord>
680  const scalar_t *&weights, int &stride, int idx) const {
681  AssertCondition((idx >= 0) and (idx < nWeightsPerEdge_),
682  "Invalid edge weight index.");
683 
684  size_t length;
685  edgeWeights_[idx].getStridedList(length, weights, stride);
686 }
687 
689 template <typename User, typename UserCoord>
691  typename Base::WeightsDeviceView1D &weights, int idx) const {
692 
693  weights = Kokkos::subview(edgeWeightsDevice_, Kokkos::ALL, idx);
694 }
695 
697 template <typename User, typename UserCoord>
699  typename Base::WeightsDeviceView &weights) const {
700 
701  weights = edgeWeightsDevice_;
702 }
703 
705 template <typename User, typename UserCoord>
707  typename Base::WeightsHostView1D &weights, int idx) const {
708 
709  auto weightsDevice = Kokkos::subview(edgeWeightsDevice_, Kokkos::ALL, idx);
710  weights = Kokkos::create_mirror_view(weightsDevice);
711  Kokkos::deep_copy(weights, weightsDevice);
712 }
713 
715 template <typename User, typename UserCoord>
717  typename Base::WeightsHostView &weights) const {
718 
719  weights = Kokkos::create_mirror_view(edgeWeightsDevice_);
720  Kokkos::deep_copy(weights, edgeWeightsDevice_);
721 }
722 
724 template <typename User, typename UserCoord>
725 template <typename Adapter>
727  const User &in, User *&out,
728  const PartitioningSolution<Adapter> &solution) const {
729  // Get an import list (rows to be received)
730  size_t numNewVtx;
731  ArrayRCP<gno_t> importList;
732  try {
733  numNewVtx =
734  Zoltan2::getImportList<Adapter, TpetraRowGraphAdapter<User, UserCoord>>(
735  solution, this, importList);
736  }
738 
739  // Move the rows, creating a new graph.
740  RCP<User> outPtr = doMigration(in, numNewVtx, importList.getRawPtr());
741  out = outPtr.get();
742  outPtr.release();
743 }
744 
746 template <typename User, typename UserCoord>
747 template <typename Adapter>
749  const User &in, RCP<User> &out,
750  const PartitioningSolution<Adapter> &solution) const {
751  // Get an import list (rows to be received)
752  size_t numNewVtx;
753  ArrayRCP<gno_t> importList;
754  try {
755  numNewVtx =
756  Zoltan2::getImportList<Adapter, TpetraRowGraphAdapter<User, UserCoord>>(
757  solution, this, importList);
758  }
760 
761  // Move the rows, creating a new graph.
762  out = doMigration(in, numNewVtx, importList.getRawPtr());
763 }
764 
766 template <typename User, typename UserCoord>
768  const User &from, size_t numLocalRows, const gno_t *myNewRows) const {
769  typedef Tpetra::Map<lno_t, gno_t, node_t> map_t;
770  typedef Tpetra::CrsGraph<lno_t, gno_t, node_t> tcrsgraph_t;
771 
772  // We cannot create a Tpetra::RowGraph, unless the underlying type is
773  // something we know (like Tpetra::CrsGraph).
774  // If the underlying type is something different, the user probably doesn't
775  // want a Tpetra::CrsGraph back, so we throw an error.
776 
777  // Try to cast "from" graph to a TPetra::CrsGraph
778  // If that fails we throw an error.
779  // We could cast as a ref which will throw std::bad_cast but with ptr
780  // approach it might be clearer what's going on here
781  const tcrsgraph_t *pCrsGraphSrc = dynamic_cast<const tcrsgraph_t *>(&from);
782 
783  if (!pCrsGraphSrc) {
784  throw std::logic_error("TpetraRowGraphAdapter cannot migrate data for "
785  "your RowGraph; it can migrate data only for "
786  "Tpetra::CrsGraph. "
787  "You can inherit from TpetraRowGraphAdapter and "
788  "implement migration for your RowGraph.");
789  }
790 
791  // source map
792  const RCP<const map_t> &smap = from.getRowMap();
793  int oldNumElts = smap->getLocalNumElements();
794  gno_t numGlobalRows = smap->getGlobalNumElements();
795  gno_t base = smap->getMinAllGlobalIndex();
796 
797  // target map
798  ArrayView<const gno_t> rowList(myNewRows, numLocalRows);
799  const RCP<const Teuchos::Comm<int>> &comm = from.getComm();
800  RCP<const map_t> tmap = rcp(new map_t(numGlobalRows, rowList, base, comm));
801 
802  // importer
803  Tpetra::Import<lno_t, gno_t, node_t> importer(smap, tmap);
804 
805  // number of entries in my new rows
806  typedef Tpetra::Vector<gno_t, lno_t, gno_t, node_t> vector_t;
807  vector_t numOld(smap);
808  vector_t numNew(tmap);
809  for (int lid = 0; lid < oldNumElts; lid++) {
810  numOld.replaceGlobalValue(smap->getGlobalElement(lid),
811  from.getNumEntriesInLocalRow(lid));
812  }
813  numNew.doImport(numOld, importer, Tpetra::INSERT);
814 
815  size_t numElts = tmap->getLocalNumElements();
816  ArrayRCP<const gno_t> nnz;
817  if (numElts > 0)
818  nnz = numNew.getData(0); // hangs if vector len == 0
819 
820  ArrayRCP<const size_t> nnz_size_t;
821 
822  if (numElts && sizeof(gno_t) != sizeof(size_t)) {
823  size_t *vals = new size_t[numElts];
824  nnz_size_t = arcp(vals, 0, numElts, true);
825  for (size_t i = 0; i < numElts; i++) {
826  vals[i] = static_cast<size_t>(nnz[i]);
827  }
828  } else {
829  nnz_size_t = arcp_reinterpret_cast<const size_t>(nnz);
830  }
831 
832  // target graph
833  RCP<tcrsgraph_t> G = rcp(new tcrsgraph_t(tmap, nnz_size_t()));
834 
835  G->doImport(*pCrsGraphSrc, importer, Tpetra::INSERT);
836  G->fillComplete();
837  return Teuchos::rcp_dynamic_cast<User>(G);
838 }
839 
840 } // namespace Zoltan2
841 
842 #endif
TpetraRowGraphAdapter(int nVtxWgts, int nEdgeWgts, const RCP< const User > &graph)
ArrayRCP< StridedData< lno_t, scalar_t > > edgeWeights_
void getVertexIDsHostView(typename Base::ConstIdsHostView &ids) const override
Sets pointers to this process&#39; graph entries.
void setVertexWeightsHost(typename Base::ConstWeightsHostView1D val, int idx)
Provide a host view to vertex weights.
void getEdgeWeightsView(const scalar_t *&weights, int &stride, int idx) const override
Provide a pointer to the edge weights, if any.
Helper functions for Partitioning Problems.
void setWeightIsDegree(int idx)
Specify an index for which the weight should be the degree of the entity.
void getVertexIDsView(const gno_t *&ids) const override
Sets pointers to this process&#39; graph entries.
#define Z2_FORWARD_EXCEPTIONS
Forward an exception back through call stack.
typename InputTraits< User >::scalar_t scalar_t
static void AssertCondition(bool condition, const std::string &message, const char *file=__FILE__, int line=__LINE__)
void getEdgesView(const offset_t *&offsets, const gno_t *&adjIds) const override
Gets adjacency lists for all vertices in a compressed sparse row (CSR) format.
static ArrayRCP< ArrayRCP< zscalar_t > > weights
void getVertexWeightsDeviceView(typename Base::WeightsDeviceView1D &weights, int idx=0) const override
Provide a device view of the vertex weights, if any.
GraphAdapter defines the interface for graph-based user data.
int getNumWeightsPerVertex() const override
Returns the number (0 or greater) of weights per vertex.
typename node_t::device_type device_t
void setVertexWeights(const scalar_t *val, int stride, int idx)
Provide a pointer to vertex weights.
default_part_t part_t
The data type to represent part numbers.
default_offset_t offset_t
The data type to represent offsets.
size_t getLocalNumVertices() const override
Returns the number of vertices on this process.
ArrayRCP< StridedData< lno_t, scalar_t > > vertexWeights_
typename InputTraits< User >::part_t part_t
int getNumWeightsPerEdge() const override
Returns the number (0 or greater) of edge weights.
void getEdgesDeviceView(typename Base::ConstOffsetsDeviceView &offsets, typename Base::ConstIdsDeviceView &adjIds) const override
Gets adjacency lists for all vertices in a compressed sparse row (CSR) format.
void getEdgeWeightsDeviceView(typename Base::WeightsDeviceView1D &weights, int idx=0) const override
Provide a device view of the edge weights, if any.
void setWeightsHost(typename Base::ConstWeightsHostView1D val, int idx)
Provide a host view of weights for the primary entity type.
void getVertexWeightsView(const scalar_t *&weights, int &stride, int idx) const override
Provide a pointer to the vertex weights, if any.
bool useDegreeAsVertexWeight(int idx) const override
Indicate whether vertex weight with index idx should be the global degree of the vertex.
void applyPartitioningSolution(const User &in, User *&out, const PartitioningSolution< Adapter > &solution) const
typename InputTraits< User >::node_t node_t
A PartitioningSolution is a solution to a partitioning problem.
size_t getLocalNumEdges() const override
Returns the number of edges on this process.
void getEdgesHostView(typename Base::ConstOffsetsHostView &offsets, typename Base::ConstIdsHostView &adjIds) const override
Gets adjacency lists for all vertices in a compressed sparse row (CSR) format.
void getVertexWeightsHostView(typename Base::WeightsHostView1D &weights, int idx=0) const override
Provide a host view of the vertex weights, if any.
void getEdgeWeightsHostView(typename Base::WeightsHostView1D &weights, int idx=0) const override
Provide a host view of the edge weights, if any.
typename InputTraits< User >::gno_t gno_t
default_lno_t lno_t
The ordinal type (e.g., int, long, int64_t) that represents local counts and local indices...
Tpetra::Map map_t
Definition: mapRemotes.cpp:25
The StridedData class manages lists of weights or coordinates.
void setEdgeWeightsDevice(typename Base::ConstWeightsDeviceView1D val, int idx)
Provide a device view to edge weights.
void setWeightsDevice(typename Base::ConstWeightsDeviceView1D val, int idx)
Provide a device view of weights for the primary entity type.
map_t::local_ordinal_type lno_t
Definition: mapRemotes.cpp:26
default_gno_t gno_t
The ordinal type (e.g., int, long, int64_t) that can represent global counts and identifiers.
default_node_t node_t
The Kokkos node type. This is only meaningful for users of Tpetra objects.
void getVertexIDsDeviceView(typename Base::ConstIdsDeviceView &ids) const override
Sets pointers to this process&#39; graph entries.
typename InputTraits< User >::offset_t offset_t
void setVertexWeightsDevice(typename Base::ConstWeightsDeviceView1D val, int idx)
Provide a device view to vertex weights.
void setVertexWeightIsDegree(int idx)
Specify an index for which the vertex weight should be the degree of the vertex.
TpetraRowGraphAdapter(const RCP< const User > &ingraph, int nVtxWeights=0, int nEdgeWeights=0)
Constructor for graph with no weights or coordinates.
void setEdgeWeights(const scalar_t *val, int stride, int idx)
Provide a pointer to edge weights.
Defines the GraphAdapter interface.
void setWeights(const scalar_t *val, int stride, int idx)
Provide a pointer to weights for the primary entity type.
virtual RCP< User > doMigration(const User &from, size_t numLocalRows, const gno_t *myNewRows) const
default_scalar_t scalar_t
The data type for weights and coordinates.
void setEdgeWeightsHost(typename Base::ConstWeightsHostView1D val, int idx)
Provide a host view to edge weights.
Provides access for Zoltan2 to Tpetra::RowGraph data.
This file defines the StridedData class.