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), label_ (label)
35 template<
class Scalar,
39 Teuchos::RCP<CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
45 RCP<crs_matrix_type> transMatrixWithSharedRows = createTransposeLocal (params);
47 #ifdef HAVE_TPETRA_MMM_TIMINGS
48 const std::string prefix = std::string (
"Tpetra ") + label_ +
": ";
49 using Teuchos::TimeMonitor;
50 TimeMonitor MM (*TimeMonitor::getNewTimer (prefix +
"Transpose TAFC"));
57 RCP<const export_type> exporter =
58 transMatrixWithSharedRows->getGraph ()->getExporter ();
59 if (exporter.is_null ()) {
60 return transMatrixWithSharedRows;
63 Teuchos::ParameterList labelList;
64 #ifdef HAVE_TPETRA_MMM_TIMINGS
65 labelList.set(
"Timer Label", label_);
67 if(! params.is_null ()) {
68 const char paramName[] =
"compute global constants";
69 labelList.set (paramName, params->get (paramName,
true));
74 return exportAndFillCompleteCrsMatrix<crs_matrix_type>
75 (transMatrixWithSharedRows, *exporter, Teuchos::null,
76 Teuchos::null, Teuchos::rcpFromRef (labelList));
85 template<
class Scalar,
89 Teuchos::RCP<CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
94 using Teuchos::ArrayRCP;
95 using Teuchos::ArrayView;
98 using Teuchos::rcp_dynamic_cast;
99 using LO = LocalOrdinal;
100 using GO = GlobalOrdinal;
104 #ifdef HAVE_TPETRA_MMM_TIMINGS
105 std::string prefix = std::string(
"Tpetra ") + label_ +
": ";
106 using Teuchos::TimeMonitor;
107 TimeMonitor MM (*TimeMonitor::getNewTimer (prefix +
"Transpose Local"));
110 const bool sort = [&] () {
111 constexpr
bool sortDefault =
true;
112 const char sortParamName[] =
"sort";
113 return params.get () ==
nullptr ? sortDefault :
114 params->get (sortParamName, sortDefault);
117 const LO lclNumRows (origMatrix_->getLocalNumRows ());
119 RCP<const crs_matrix_type> crsMatrix =
121 if (crsMatrix.is_null ()) {
123 if (rowMap->isOneToOne ()) {
124 Teuchos::Array<size_t> numEntPerRow (lclNumRows);
125 for (LO lclRow = 0; lclRow < lclNumRows; ++lclRow) {
126 numEntPerRow[lclRow] = origMatrix_->getNumEntriesInLocalRow (lclRow);
128 auto colMap = origMatrix_->getColMap ();
130 RCP<crs_matrix_type> crsMatrix_nc =
134 import_type imp (rowMap, rowMap);
136 crsMatrix_nc->fillComplete (origMatrix_->getDomainMap (),
137 origMatrix_->getRangeMap ());
138 crsMatrix = crsMatrix_nc;
141 TEUCHOS_ASSERT(
false );
147 local_matrix_device_type lclMatrix = crsMatrix->getLocalMatrixDevice ();
148 local_matrix_device_type lclTransposeMatrix = KokkosSparse::Impl::transpose_matrix(lclMatrix);
150 KokkosSparse::sort_crs_matrix(lclTransposeMatrix);
154 const auto origExport = origMatrix_->getGraph ()->getExporter ();
155 RCP<const import_type> myImport = origExport.is_null () ?
156 Teuchos::null : rcp (
new import_type (*origExport));
157 const auto origImport = origMatrix_->getGraph ()->getImporter ();
158 RCP<const export_type> myExport = origImport.is_null () ?
159 Teuchos::null : rcp (
new export_type (*origImport));
161 RCP<Teuchos::ParameterList> graphParams = Teuchos::null;
163 graphParams = rcp(
new Teuchos::ParameterList);
164 graphParams->set(
"sorted",
false);
168 origMatrix_->getColMap (),
169 origMatrix_->getRowMap (),
170 origMatrix_->getRangeMap (),
171 origMatrix_->getDomainMap (),
172 myImport, myExport, graphParams));
177 template<
class Scalar,
183 const std::string& label)
184 : origMatrix_ (origMatrix), label_ (label)
187 template<
class Scalar,
191 Teuchos::RCP<BlockCrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
197 RCP<bcrs_matrix_type> transMatrixWithSharedRows = createTransposeLocal (params);
199 #ifdef HAVE_TPETRA_MMM_TIMINGS
200 const std::string prefix = std::string (
"Tpetra ") + label_ +
": ";
201 using Teuchos::TimeMonitor;
202 TimeMonitor MM (*TimeMonitor::getNewTimer (prefix +
"Transpose TAFC"));
209 RCP<const export_type> exporter =
210 transMatrixWithSharedRows->getGraph ()->getExporter ();
211 if (exporter.is_null ()) {
212 return transMatrixWithSharedRows;
215 Teuchos::ParameterList labelList;
216 #ifdef HAVE_TPETRA_MMM_TIMINGS
217 labelList.set(
"Timer Label", label_);
219 if(! params.is_null ()) {
220 const char paramName[] =
"compute global constants";
221 labelList.set (paramName, params->get (paramName,
true));
226 return exportAndFillCompleteBlockCrsMatrix<bcrs_matrix_type>
227 (transMatrixWithSharedRows, *exporter);
236 template<
class Scalar,
240 Teuchos::RCP<BlockCrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
244 using Teuchos::Array;
245 using Teuchos::ArrayRCP;
246 using Teuchos::ArrayView;
249 using Teuchos::rcp_dynamic_cast;
250 using LO = LocalOrdinal;
251 using GO = GlobalOrdinal;
256 #ifdef HAVE_TPETRA_MMM_TIMINGS
257 std::string prefix = std::string(
"Tpetra ") + label_ +
": ";
258 using Teuchos::TimeMonitor;
259 TimeMonitor MM (*TimeMonitor::getNewTimer (prefix +
"Transpose Local"));
262 RCP<const bcrs_matrix_type> crsMatrix =
265 if(crsMatrix.is_null())
266 TEUCHOS_ASSERT(
false );
268 using local_matrix_device_type =
typename bcrs_matrix_type::local_matrix_device_type;
270 typename local_matrix_device_type::values_type values ;
271 RCP<const crs_graph_type> graph;
275 local_matrix_device_type lclTransposeMatrix = KokkosSparse::Impl::transpose_bsr_matrix(lclMatrix);
278 KokkosSparse::sort_crs_matrix(lclTransposeMatrix);
279 values = lclTransposeMatrix.values;
283 const auto origExport = origMatrix_->getGraph ()->getExporter ();
284 RCP<const import_type> myImport = origExport.is_null () ?
285 Teuchos::null : rcp (
new import_type (*origExport));
286 const auto origImport = origMatrix_->getGraph ()->getImporter ();
287 RCP<const export_type> myExport = origImport.is_null () ?
288 Teuchos::null : rcp (
new export_type (*origImport));
290 RCP<Teuchos::ParameterList> graphParams = Teuchos::null;
293 graph = rcp(
new crs_graph_type(lclTransposeMatrix.graph,
294 origMatrix_->getColMap (),
295 origMatrix_->getRowMap (),
296 origMatrix_->getGraph()->getRangeMap (),
297 origMatrix_->getGraph()->getDomainMap (),
305 origMatrix_->getBlockSize()));
316 #define TPETRA_ROWMATRIXTRANSPOSER_INSTANT(SCALAR,LO,GO,NODE) \
317 template class RowMatrixTransposer< SCALAR, LO , GO , NODE >;\
318 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.