Zoltan2
Loading...
Searching...
No Matches
Zoltan2_TpetraCrsMatrixAdapter.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_TPETRACRSMATRIXADAPTER_HPP_
15#define _ZOLTAN2_TPETRACRSMATRIXADAPTER_HPP_
16
22
23#include <Tpetra_CrsMatrix.hpp>
24
25#include <vector>
26
27namespace Zoltan2 {
28
30
49template <typename User, typename UserCoord = User>
50 class TpetraCrsMatrixAdapter : public TpetraRowMatrixAdapter<User,UserCoord> {
51
52public:
53#ifndef DOXYGEN_SHOULD_SKIP_THIS
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;
60 using tmatrix_t = Tpetra::CrsMatrix<scalar_t, lno_t, gno_t, node_t>;
61 using device_t = typename node_t::device_type;
62 using host_t = typename Kokkos::HostSpace::memory_space;
63 using user_t = User;
64 using userCoord_t = UserCoord;
65
68 #endif
69
75 TpetraCrsMatrixAdapter(const RCP<const User> &inmatrix,
76 int nWeightsPerRow=0);
77
80 RCP<const User> getUserMatrix() const { return this->matrix_; }
81
82 template <typename Adapter>
83 void applyPartitioningSolution(const User &in, User *&out,
84 const PartitioningSolution<Adapter> &solution) const;
85
86 template <typename Adapter>
87 void applyPartitioningSolution(const User &in, RCP<User> &out,
88 const PartitioningSolution<Adapter> &solution) const;
89};
90
92// Definitions
94
95 template <typename User, typename UserCoord>
97 const RCP<const User> &inmatrix, int nWeightsPerRow):
98 RowMatrix(nWeightsPerRow, inmatrix) {
99
100 auto colIdsHost = inmatrix->getLocalIndicesHost();
101
102 auto colIdsGlobalHost =
103 typename Base::IdsHostView("colIdsGlobalHost", colIdsHost.extent(0));
104 auto colMap = inmatrix->getColMap();
105
106 // Convert to global IDs using Tpetra::Map
107 Kokkos::parallel_for("colIdsGlobalHost",
108 Kokkos::RangePolicy<Kokkos::HostSpace::execution_space>(
109 0, colIdsGlobalHost.extent(0)),
110 [=](const int i) {
111 colIdsGlobalHost(i) =
112 colMap->getGlobalElement(colIdsHost(i));
113 });
114
115 auto colIdsDevice = Kokkos::create_mirror_view_and_copy(
116 typename Base::device_t(), colIdsGlobalHost);
117
118 this->colIdsDevice_ = colIdsDevice;
119 this->offsDevice_ = inmatrix->getLocalRowPtrsDevice();
120
121 if (this->nWeightsPerRow_ > 0) {
122
123 this->rowWeightsDevice_ = typename Base::WeightsDeviceView(
124 "rowWeightsDevice_", inmatrix->getLocalNumRows(),
125 this->nWeightsPerRow_);
126
127 this->numNzWeight_ = Kokkos::View<bool *, host_t>(
128 "numNzWeight_", this->nWeightsPerRow_);
129
130 for (int i = 0; i < this->nWeightsPerRow_; ++i) {
131 this->numNzWeight_(i) = false;
132 }
133 }
134}
135
137template <typename User, typename UserCoord>
138 template <typename Adapter>
140 const User &in, User *&out,
141 const PartitioningSolution<Adapter> &solution) const
142{
143 // Get an import list (rows to be received)
144 size_t numNewRows;
145 ArrayRCP<gno_t> importList;
146 try{
147 numNewRows = Zoltan2::getImportList<Adapter,
149 (solution, this, importList);
150 }
152
153 // Move the rows, creating a new matrix.
154 RCP<User> outPtr = this->doMigration(in, numNewRows,importList.getRawPtr());
155 out = const_cast<User *>(outPtr.get());
156 outPtr.release();
157}
158
160template <typename User, typename UserCoord>
161 template <typename Adapter>
163 const User &in, RCP<User> &out,
164 const PartitioningSolution<Adapter> &solution) const
165{
166 // Get an import list (rows to be received)
167 size_t numNewRows;
168 ArrayRCP<gno_t> importList;
169 try{
170 numNewRows = Zoltan2::getImportList<Adapter,
172 (solution, this, importList);
173 }
175
176 // Move the rows, creating a new matrix.
177 out = this->doMigration(in, numNewRows, importList.getRawPtr());
178}
179
180} //namespace Zoltan2
181
182#endif
Tpetra::CrsMatrix< zscalar_t, zlno_t, zgno_t, znode_t > tmatrix_t
#define Z2_FORWARD_EXCEPTIONS
Forward an exception back through call stack.
Traits for application input objects.
Defines the MatrixAdapter interface.
Helper functions for Partitioning Problems.
This file defines the StridedData class.
Defines the TpetraRowMatrixAdapter class.
typename InputTraits< User >::node_t node_t
typename InputTraits< User >::lno_t lno_t
typename InputTraits< User >::scalar_t scalar_t
typename InputTraits< User >::gno_t gno_t
typename Kokkos::HostSpace::memory_space host_t
typename InputTraits< User >::offset_t offset_t
typename InputTraits< User >::part_t part_t
typename node_t::device_type device_t
MatrixAdapter defines the adapter interface for matrices.
A PartitioningSolution is a solution to a partitioning problem.
Provides access for Zoltan2 to Tpetra::CrsMatrix data.
void applyPartitioningSolution(const User &in, User *&out, const PartitioningSolution< Adapter > &solution) const
RCP< const User > getUserMatrix() const
Access to user's matrix.
TpetraCrsMatrixAdapter(const RCP< const User > &inmatrix, int nWeightsPerRow=0)
Constructor.
Provides access for Zoltan2 to Tpetra::RowMatrix data.
Created by mbenlioglu on Aug 31, 2020.
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...
default_offset_t offset_t
The data type to represent offsets.
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.
default_lno_t lno_t
The ordinal type (e.g., int, long, int64_t) that represents local counts and local indices.
default_part_t part_t
The data type to represent part numbers.
default_scalar_t scalar_t
The data type for weights and coordinates.