10 #ifndef TPETRA_ROWMATRIXTRANSPOSER_DEF_HPP
11 #define TPETRA_ROWMATRIXTRANSPOSER_DEF_HPP
13 #include "Tpetra_CrsMatrix.hpp"
14 #include "Tpetra_BlockCrsMatrix.hpp"
15 #include "Tpetra_Export.hpp"
18 #include "Teuchos_ParameterList.hpp"
19 #include "Teuchos_TimeMonitor.hpp"
20 #include "KokkosSparse_Utils.hpp"
21 #include "KokkosSparse_SortCrs.hpp"
25 template <
class Scalar,
31 const std::string& label)
32 : origMatrix_(origMatrix)
35 template <
class Scalar,
39 Teuchos::RCP<CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
44 RCP<crs_matrix_type> transMatrixWithSharedRows = createTransposeLocal(params);
46 #ifdef HAVE_TPETRA_MMM_TIMINGS
47 const std::string prefix = std::string(
"Tpetra ") + label_ +
": ";
48 using Teuchos::TimeMonitor;
49 TimeMonitor MM(*TimeMonitor::getNewTimer(prefix +
"Transpose TAFC"));
56 RCP<const export_type> exporter =
57 transMatrixWithSharedRows->getGraph()->getExporter();
58 if (exporter.is_null()) {
59 return transMatrixWithSharedRows;
61 Teuchos::ParameterList labelList;
62 #ifdef HAVE_TPETRA_MMM_TIMINGS
63 labelList.set(
"Timer Label", label_);
65 if (!params.is_null()) {
66 const char paramName[] =
"compute global constants";
67 labelList.set(paramName, params->get(paramName,
true));
72 return exportAndFillCompleteCrsMatrix<crs_matrix_type>(transMatrixWithSharedRows, *exporter, Teuchos::null,
73 Teuchos::null, Teuchos::rcpFromRef(labelList));
81 template <
class Scalar,
85 Teuchos::RCP<CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
89 using Teuchos::ArrayRCP;
90 using Teuchos::ArrayView;
93 using Teuchos::rcp_dynamic_cast;
94 using LO = LocalOrdinal;
95 using GO = GlobalOrdinal;
99 #ifdef HAVE_TPETRA_MMM_TIMINGS
100 std::string prefix = std::string(
"Tpetra ") + label_ +
": ";
101 using Teuchos::TimeMonitor;
102 TimeMonitor MM(*TimeMonitor::getNewTimer(prefix +
"Transpose Local"));
105 const bool sort = [&]() {
106 constexpr
bool sortDefault =
true;
107 const char sortParamName[] =
"sort";
108 return params.get() ==
nullptr ? sortDefault : params->get(sortParamName, sortDefault);
111 const LO lclNumRows(origMatrix_->getLocalNumRows());
113 RCP<const crs_matrix_type> crsMatrix =
115 if (crsMatrix.is_null()) {
117 if (rowMap->isOneToOne()) {
118 Teuchos::Array<size_t> numEntPerRow(lclNumRows);
119 for (LO lclRow = 0; lclRow < lclNumRows; ++lclRow) {
120 numEntPerRow[lclRow] = origMatrix_->getNumEntriesInLocalRow(lclRow);
122 auto colMap = origMatrix_->getColMap();
124 RCP<crs_matrix_type> crsMatrix_nc =
128 import_type imp(rowMap, rowMap);
130 crsMatrix_nc->fillComplete(origMatrix_->getDomainMap(),
131 origMatrix_->getRangeMap());
132 crsMatrix = crsMatrix_nc;
134 TEUCHOS_ASSERT(
false);
140 local_matrix_device_type lclMatrix = crsMatrix->getLocalMatrixDevice();
141 local_matrix_device_type lclTransposeMatrix = KokkosSparse::Impl::transpose_matrix(lclMatrix);
143 KokkosSparse::sort_crs_matrix(lclTransposeMatrix);
147 const auto origExport = origMatrix_->getGraph()->getExporter();
148 RCP<const import_type> myImport = origExport.is_null() ? Teuchos::null : rcp(
new import_type(*origExport));
149 const auto origImport = origMatrix_->getGraph()->getImporter();
150 RCP<const export_type> myExport = origImport.is_null() ? Teuchos::null : rcp(
new export_type(*origImport));
152 RCP<Teuchos::ParameterList> graphParams = Teuchos::null;
154 graphParams = rcp(
new Teuchos::ParameterList);
155 graphParams->set(
"sorted",
false);
159 origMatrix_->getColMap(),
160 origMatrix_->getRowMap(),
161 origMatrix_->getRangeMap(),
162 origMatrix_->getDomainMap(),
163 myImport, myExport, graphParams));
168 template <
class Scalar,
174 const std::string& label)
175 : origMatrix_(origMatrix)
178 template <
class Scalar,
182 Teuchos::RCP<BlockCrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
187 RCP<bcrs_matrix_type> transMatrixWithSharedRows = createTransposeLocal(params);
189 #ifdef HAVE_TPETRA_MMM_TIMINGS
190 const std::string prefix = std::string(
"Tpetra ") + label_ +
": ";
191 using Teuchos::TimeMonitor;
192 TimeMonitor MM(*TimeMonitor::getNewTimer(prefix +
"Transpose TAFC"));
199 RCP<const export_type> exporter =
200 transMatrixWithSharedRows->getGraph()->getExporter();
201 if (exporter.is_null()) {
202 return transMatrixWithSharedRows;
204 Teuchos::ParameterList labelList;
205 #ifdef HAVE_TPETRA_MMM_TIMINGS
206 labelList.set(
"Timer Label", label_);
208 if (!params.is_null()) {
209 const char paramName[] =
"compute global constants";
210 labelList.set(paramName, params->get(paramName,
true));
215 return exportAndFillCompleteBlockCrsMatrix<bcrs_matrix_type>(transMatrixWithSharedRows, *exporter);
223 template <
class Scalar,
227 Teuchos::RCP<BlockCrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
230 using Teuchos::Array;
231 using Teuchos::ArrayRCP;
232 using Teuchos::ArrayView;
235 using Teuchos::rcp_dynamic_cast;
236 using LO = LocalOrdinal;
237 using GO = GlobalOrdinal;
242 #ifdef HAVE_TPETRA_MMM_TIMINGS
243 std::string prefix = std::string(
"Tpetra ") + label_ +
": ";
244 using Teuchos::TimeMonitor;
245 TimeMonitor MM(*TimeMonitor::getNewTimer(prefix +
"Transpose Local"));
248 RCP<const bcrs_matrix_type> crsMatrix =
251 if (crsMatrix.is_null())
252 TEUCHOS_ASSERT(
false);
254 using local_matrix_device_type =
typename bcrs_matrix_type::local_matrix_device_type;
256 typename local_matrix_device_type::values_type values;
257 RCP<const crs_graph_type> graph;
261 local_matrix_device_type lclTransposeMatrix = KokkosSparse::Impl::transpose_bsr_matrix(lclMatrix);
264 KokkosSparse::sort_crs_matrix(lclTransposeMatrix);
265 values = lclTransposeMatrix.values;
269 const auto origExport = origMatrix_->getGraph()->getExporter();
270 RCP<const import_type> myImport = origExport.is_null() ? Teuchos::null : rcp(
new import_type(*origExport));
271 const auto origImport = origMatrix_->getGraph()->getImporter();
272 RCP<const export_type> myExport = origImport.is_null() ? Teuchos::null : rcp(
new export_type(*origImport));
274 RCP<Teuchos::ParameterList> graphParams = Teuchos::null;
277 graph = rcp(
new crs_graph_type(lclTransposeMatrix.graph,
278 origMatrix_->getColMap(),
279 origMatrix_->getRowMap(),
280 origMatrix_->getGraph()->getRangeMap(),
281 origMatrix_->getGraph()->getDomainMap(),
289 origMatrix_->getBlockSize()));
299 #define TPETRA_ROWMATRIXTRANSPOSER_INSTANT(SCALAR, LO, GO, NODE) \
300 template class RowMatrixTransposer<SCALAR, LO, GO, NODE>; \
301 template class BlockCrsMatrixTransposer<SCALAR, LO, GO, NODE>;
RowMatrixTransposer(const Teuchos::RCP< const crs_matrix_type > &origMatrix, const std::string &label=std::string())
Constructor that takes the matrix to transpose.
Communication plan for data redistribution from a uniquely-owned to a (possibly) multiply-owned distr...
Sparse matrix that presents a row-oriented interface that lets users read or modify entries...
Sparse matrix whose entries are small dense square blocks, all of the same dimensions.
Declaration and definition of functions for sorting "short" arrays of keys and corresponding values...
KokkosSparse::CrsMatrix< impl_scalar_type, local_ordinal_type, device_type, void, typename local_graph_device_type::size_type > local_matrix_device_type
The specialization of Kokkos::CrsMatrix that represents the part of the sparse matrix on each MPI pro...
void sort(View &view, const size_t &size)
Convenience wrapper for std::sort for host-accessible views.
Teuchos::RCP< bcrs_matrix_type > createTransposeLocal(const Teuchos::RCP< Teuchos::ParameterList > ¶ms=Teuchos::null)
Compute and return the transpose of the matrix given to the constructor.
BlockCrsMatrixTransposer(const Teuchos::RCP< const bcrs_matrix_type > &origMatrix, const std::string &label=std::string())
Constructor that takes the matrix to transpose.
Declare and define the functions Tpetra::Details::computeOffsetsFromCounts and Tpetra::computeOffsets...
Communication plan for data redistribution from a (possibly) multiply-owned to a uniquely-owned distr...
Teuchos::RCP< crs_matrix_type > createTransposeLocal(const Teuchos::RCP< Teuchos::ParameterList > ¶ms=Teuchos::null)
Compute and return the transpose of the matrix given to the constructor.
Replace existing values with new values.
Teuchos::RCP< bcrs_matrix_type > createTranspose(const Teuchos::RCP< Teuchos::ParameterList > ¶ms=Teuchos::null)
Compute and return the transpose of the matrix given to the constructor.
Teuchos::RCP< crs_matrix_type > createTranspose(const Teuchos::RCP< Teuchos::ParameterList > ¶ms=Teuchos::null)
Compute and return the transpose of the matrix given to the constructor.
local_matrix_device_type getLocalMatrixDevice() const
Teuchos::RCP< const map_type > getRowMap() const override
The Map that describes the row distribution in this matrix.