Zoltan2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Zoltan2_TpetraCrsGraphAdapter.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_TPETRACRSGRAPHADAPTER_HPP_
15 #define _ZOLTAN2_TPETRACRSGRAPHADAPTER_HPP_
16 
18 #include <Zoltan2_StridedData.hpp>
20 #include <Zoltan2_XpetraTraits.hpp>
21 #include <string>
22 
23 namespace Zoltan2 {
24 
32 template <typename User, typename UserCoord = User>
33 class TpetraCrsGraphAdapter : public TpetraRowGraphAdapter<User, UserCoord> {
34 
35 public:
36 #ifndef DOXYGEN_SHOULD_SKIP_THIS
37  using scalar_t = typename InputTraits<User>::scalar_t;
38  using offset_t = typename InputTraits<User>::offset_t;
39  using lno_t = typename InputTraits<User>::lno_t;
40  using gno_t = typename InputTraits<User>::gno_t;
41  using part_t = typename InputTraits<User>::part_t;
42  using node_t = typename InputTraits<User>::node_t;
43  using user_t = User;
44  using userCoord_t = UserCoord;
45 
46  using Base = GraphAdapter<User, UserCoord>;
48 #endif
49 
59  TpetraCrsGraphAdapter(const RCP<const User> &graph, int nVtxWeights = 0,
60  int nEdgeWeights = 0);
61 
64  RCP<const User> getUserGraph() const { return this->graph_; }
65 
66  template <typename Adapter>
68  const User &in, User *&out,
69  const PartitioningSolution<Adapter> &solution) const;
70 
71  template <typename Adapter>
73  const User &in, RCP<User> &out,
74  const PartitioningSolution<Adapter> &solution) const;
75 };
76 
78 // Definitions
80 
81 template <typename User, typename UserCoord>
83  const RCP<const User> &graph, int nVtxWgts, int nEdgeWgts)
84  : TpetraRowGraphAdapter<User>(nVtxWgts, nEdgeWgts, graph) {
85  auto adjIdsHost = graph->getLocalIndicesHost();
86 
87  auto adjIdsGlobalHost =
88  typename Base::IdsHostView("adjIdsGlobalHost", adjIdsHost.extent(0));
89  auto colMap = graph->getColMap();
90 
91  // Convert to global IDs using Tpetra::Map
92  Kokkos::parallel_for("adjIdsGlobalHost",
93  Kokkos::RangePolicy<Kokkos::HostSpace::execution_space>(
94  0, adjIdsGlobalHost.extent(0)),
95  [=](const int i) {
96  adjIdsGlobalHost(i) =
97  colMap->getGlobalElement(adjIdsHost(i));
98  });
99 
100  auto adjIdsDevice = Kokkos::create_mirror_view_and_copy(
101  typename Base::device_t(), adjIdsGlobalHost);
102 
103  this->adjIdsDevice_ = adjIdsDevice;
104  this->offsDevice_ = graph->getLocalRowPtrsDevice();
105 
106  if (this->nWeightsPerVertex_ > 0) {
107 
108  this->vertexWeightsDevice_ = typename Base::WeightsDeviceView(
109  "vertexWeightsDevice_", graph->getLocalNumRows(),
110  this->nWeightsPerVertex_);
111 
112  this->vertexDegreeWeightsHost_ = typename Base::VtxDegreeHostView(
113  "vertexDegreeWeightsHost_", this->nWeightsPerVertex_);
114 
115  for (int i = 0; i < this->nWeightsPerVertex_; ++i) {
116  this->vertexDegreeWeightsHost_(i) = false;
117  }
118  }
119 
120  if (this->nWeightsPerEdge_) {
121  this->edgeWeightsDevice_ = typename Base::WeightsDeviceView(
122  "nWeightsPerEdge_", graph->getLocalNumRows(), this->nWeightsPerEdge_);
123  }
124 }
125 
127 template <typename User, typename UserCoord>
128 template <typename Adapter>
130  const User &in, User *&out,
131  const PartitioningSolution<Adapter> &solution) const {
133  solution);
134 }
135 
137 template <typename User, typename UserCoord>
138 template <typename Adapter>
140  const User &in, RCP<User> &out,
141  const PartitioningSolution<Adapter> &solution) const {
143  solution);
144 }
145 
146 } // namespace Zoltan2
147 
148 #endif
Helper functions for Partitioning Problems.
typename InputTraits< User >::scalar_t scalar_t
GraphAdapter defines the interface for graph-based user data.
Defines TpetraRowGraphAdapter class.
typename node_t::device_type device_t
default_part_t part_t
The data type to represent part numbers.
default_offset_t offset_t
The data type to represent offsets.
Provides access for Zoltan2 to Tpetra::CrsGraph data.
Traits of Xpetra classes, including migration method.
typename InputTraits< User >::part_t part_t
void applyPartitioningSolution(const User &in, User *&out, const PartitioningSolution< Adapter > &solution) const
typename InputTraits< User >::node_t node_t
TpetraCrsGraphAdapter(const RCP< const User > &graph, int nVtxWeights=0, int nEdgeWeights=0)
Constructor for graph with no weights or coordinates.
A PartitioningSolution is a solution to a partitioning problem.
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...
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.
typename InputTraits< User >::offset_t offset_t
void applyPartitioningSolution(const User &in, User *&out, const PartitioningSolution< Adapter > &solution) const
RCP< const User > getUserGraph() const
Access to user&#39;s graph.
typename InputTraits< User >::lno_t lno_t
default_scalar_t scalar_t
The data type for weights and coordinates.
Provides access for Zoltan2 to Tpetra::RowGraph data.
This file defines the StridedData class.