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"
25template <
class Scalar,
31 const std::string& label)
32 : origMatrix_(origMatrix)
35template <
class Scalar,
39Teuchos::RCP<CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
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));
73 Teuchos::null, Teuchos::rcpFromRef(labelList));
81template <
class Scalar,
85Teuchos::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 =
114 rcp_dynamic_cast<const crs_matrix_type>(origMatrix_);
115 if (crsMatrix.is_null()) {
116 auto rowMap = origMatrix_->getRowMap();
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 =
125 rcp(
new crs_matrix_type(rowMap, colMap, numEntPerRow()));
130 crsMatrix_nc->fillComplete(origMatrix_->getDomainMap(),
131 origMatrix_->getRangeMap());
132 crsMatrix = crsMatrix_nc;
134 TEUCHOS_ASSERT(
false);
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);
158 return rcp(
new crs_matrix_type(lclTransposeMatrix,
160 origMatrix_->getRowMap(),
161 origMatrix_->getRangeMap(),
162 origMatrix_->getDomainMap(),
163 myImport, myExport, graphParams));
168template <
class Scalar,
174 const std::string& label)
175 : origMatrix_(origMatrix)
178template <
class Scalar,
182Teuchos::RCP<BlockCrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
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);
223template <
class Scalar,
227Teuchos::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 =
249 rcp_dynamic_cast<const bcrs_matrix_type>(origMatrix_);
251 if (crsMatrix.is_null())
252 TEUCHOS_ASSERT(
false);
256 typename local_matrix_device_type::values_type values;
257 RCP<const crs_graph_type> graph;
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;
279 origMatrix_->getRowMap(),
280 origMatrix_->getGraph()->getRangeMap(),
281 origMatrix_->getGraph()->getDomainMap(),
287 return rcp(
new bcrs_matrix_type(*graph,
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>;
Declare and define the functions Tpetra::Details::computeOffsetsFromCounts and Tpetra::computeOffsets...
Declaration and definition of functions for sorting "short" arrays of keys and corresponding values.
::Tpetra::CrsGraph< LocalOrdinal, GlobalOrdinal, node_type > crs_graph_type
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.
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.
TPETRA_DETAILS_ALWAYS_INLINE local_matrix_device_type getLocalMatrixDevice() const
The local sparse matrix.
Teuchos::RCP< const map_type > getColMap() const override
The Map that describes the column distribution in this matrix.
Teuchos::RCP< const RowGraph< LocalOrdinal, GlobalOrdinal, Node > > getGraph() const override
This matrix's graph, as a RowGraph.
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...
Communication plan for data redistribution from a (possibly) multiply-owned to a uniquely-owned distr...
Communication plan for data redistribution from a uniquely-owned to a (possibly) multiply-owned distr...
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.
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.
RowMatrixTransposer(const Teuchos::RCP< const crs_matrix_type > &origMatrix, const std::string &label=std::string())
Constructor that takes the matrix to transpose.
Namespace Tpetra contains the class and methods constituting the Tpetra library.
void sort(View &view, const size_t &size)
Convenience wrapper for std::sort for host-accessible views.
Teuchos::RCP< CrsMatrixType > exportAndFillCompleteCrsMatrix(const Teuchos::RCP< const CrsMatrixType > &sourceMatrix, const Export< typename CrsMatrixType::local_ordinal_type, typename CrsMatrixType::global_ordinal_type, typename CrsMatrixType::node_type > &exporter, const Teuchos::RCP< const Map< typename CrsMatrixType::local_ordinal_type, typename CrsMatrixType::global_ordinal_type, typename CrsMatrixType::node_type > > &domainMap=Teuchos::null, const Teuchos::RCP< const Map< typename CrsMatrixType::local_ordinal_type, typename CrsMatrixType::global_ordinal_type, typename CrsMatrixType::node_type > > &rangeMap=Teuchos::null, const Teuchos::RCP< Teuchos::ParameterList > ¶ms=Teuchos::null)
Nonmember CrsMatrix constructor that fuses Export and fillComplete().
@ REPLACE
Replace existing values with new values.