42 #ifndef TPETRA_ROWMATRIXTRANSPOSER_DEF_HPP
43 #define TPETRA_ROWMATRIXTRANSPOSER_DEF_HPP
45 #include "Tpetra_CrsMatrix.hpp"
46 #include "Tpetra_BlockCrsMatrix.hpp"
47 #include "Tpetra_Export.hpp"
50 #include "Teuchos_ParameterList.hpp"
51 #include "Teuchos_TimeMonitor.hpp"
52 #include "KokkosSparse_Utils.hpp"
53 #include "KokkosSparse_SortCrs.hpp"
57 template<
class Scalar,
63 const std::string& label)
64 : origMatrix_ (origMatrix), label_ (label)
67 template<
class Scalar,
71 Teuchos::RCP<CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
77 RCP<crs_matrix_type> transMatrixWithSharedRows = createTransposeLocal (params);
79 #ifdef HAVE_TPETRA_MMM_TIMINGS
80 const std::string prefix = std::string (
"Tpetra ") + label_ +
": ";
81 using Teuchos::TimeMonitor;
82 TimeMonitor MM (*TimeMonitor::getNewTimer (prefix +
"Transpose TAFC"));
89 RCP<const export_type> exporter =
90 transMatrixWithSharedRows->getGraph ()->getExporter ();
91 if (exporter.is_null ()) {
92 return transMatrixWithSharedRows;
95 Teuchos::ParameterList labelList;
96 #ifdef HAVE_TPETRA_MMM_TIMINGS
97 labelList.set(
"Timer Label", label_);
99 if(! params.is_null ()) {
100 const char paramName[] =
"compute global constants";
101 labelList.set (paramName, params->get (paramName,
true));
106 return exportAndFillCompleteCrsMatrix<crs_matrix_type>
107 (transMatrixWithSharedRows, *exporter, Teuchos::null,
108 Teuchos::null, Teuchos::rcpFromRef (labelList));
117 template<
class Scalar,
121 Teuchos::RCP<CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
125 using Teuchos::Array;
126 using Teuchos::ArrayRCP;
127 using Teuchos::ArrayView;
130 using Teuchos::rcp_dynamic_cast;
131 using LO = LocalOrdinal;
132 using GO = GlobalOrdinal;
136 #ifdef HAVE_TPETRA_MMM_TIMINGS
137 std::string prefix = std::string(
"Tpetra ") + label_ +
": ";
138 using Teuchos::TimeMonitor;
139 TimeMonitor MM (*TimeMonitor::getNewTimer (prefix +
"Transpose Local"));
142 const bool sort = [&] () {
143 constexpr
bool sortDefault =
true;
144 const char sortParamName[] =
"sort";
145 return params.get () ==
nullptr ? sortDefault :
146 params->get (sortParamName, sortDefault);
149 const LO lclNumRows (origMatrix_->getLocalNumRows ());
151 RCP<const crs_matrix_type> crsMatrix =
153 if (crsMatrix.is_null ()) {
155 if (rowMap->isOneToOne ()) {
156 Teuchos::Array<size_t> numEntPerRow (lclNumRows);
157 for (LO lclRow = 0; lclRow < lclNumRows; ++lclRow) {
158 numEntPerRow[lclRow] = origMatrix_->getNumEntriesInLocalRow (lclRow);
160 auto colMap = origMatrix_->getColMap ();
162 RCP<crs_matrix_type> crsMatrix_nc =
166 import_type imp (rowMap, rowMap);
168 crsMatrix_nc->fillComplete (origMatrix_->getDomainMap (),
169 origMatrix_->getRangeMap ());
170 crsMatrix = crsMatrix_nc;
173 TEUCHOS_ASSERT(
false );
179 local_matrix_device_type lclMatrix = crsMatrix->getLocalMatrixDevice ();
180 local_matrix_device_type lclTransposeMatrix = KokkosSparse::Impl::transpose_matrix(lclMatrix);
182 KokkosSparse::sort_crs_matrix(lclTransposeMatrix);
186 const auto origExport = origMatrix_->getGraph ()->getExporter ();
187 RCP<const import_type> myImport = origExport.is_null () ?
188 Teuchos::null : rcp (
new import_type (*origExport));
189 const auto origImport = origMatrix_->getGraph ()->getImporter ();
190 RCP<const export_type> myExport = origImport.is_null () ?
191 Teuchos::null : rcp (
new export_type (*origImport));
193 RCP<Teuchos::ParameterList> graphParams = Teuchos::null;
195 graphParams = rcp(
new Teuchos::ParameterList);
196 graphParams->set(
"sorted",
false);
200 origMatrix_->getColMap (),
201 origMatrix_->getRowMap (),
202 origMatrix_->getRangeMap (),
203 origMatrix_->getDomainMap (),
204 myImport, myExport, graphParams));
209 template<
class Scalar,
215 const std::string& label)
216 : origMatrix_ (origMatrix), label_ (label)
219 template<
class Scalar,
223 Teuchos::RCP<BlockCrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
229 RCP<bcrs_matrix_type> transMatrixWithSharedRows = createTransposeLocal (params);
231 #ifdef HAVE_TPETRA_MMM_TIMINGS
232 const std::string prefix = std::string (
"Tpetra ") + label_ +
": ";
233 using Teuchos::TimeMonitor;
234 TimeMonitor MM (*TimeMonitor::getNewTimer (prefix +
"Transpose TAFC"));
241 RCP<const export_type> exporter =
242 transMatrixWithSharedRows->getGraph ()->getExporter ();
243 if (exporter.is_null ()) {
244 return transMatrixWithSharedRows;
247 Teuchos::ParameterList labelList;
248 #ifdef HAVE_TPETRA_MMM_TIMINGS
249 labelList.set(
"Timer Label", label_);
251 if(! params.is_null ()) {
252 const char paramName[] =
"compute global constants";
253 labelList.set (paramName, params->get (paramName,
true));
258 return exportAndFillCompleteBlockCrsMatrix<bcrs_matrix_type>
259 (transMatrixWithSharedRows, *exporter);
268 template<
class Scalar,
272 Teuchos::RCP<BlockCrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
276 using Teuchos::Array;
277 using Teuchos::ArrayRCP;
278 using Teuchos::ArrayView;
281 using Teuchos::rcp_dynamic_cast;
282 using LO = LocalOrdinal;
283 using GO = GlobalOrdinal;
288 #ifdef HAVE_TPETRA_MMM_TIMINGS
289 std::string prefix = std::string(
"Tpetra ") + label_ +
": ";
290 using Teuchos::TimeMonitor;
291 TimeMonitor MM (*TimeMonitor::getNewTimer (prefix +
"Transpose Local"));
294 RCP<const bcrs_matrix_type> crsMatrix =
297 if(crsMatrix.is_null())
298 TEUCHOS_ASSERT(
false );
300 using local_matrix_device_type =
typename bcrs_matrix_type::local_matrix_device_type;
302 typename local_matrix_device_type::values_type values ;
303 RCP<const crs_graph_type> graph;
307 local_matrix_device_type lclTransposeMatrix = KokkosSparse::Impl::transpose_bsr_matrix(lclMatrix);
310 KokkosSparse::sort_crs_matrix(lclTransposeMatrix);
311 values = lclTransposeMatrix.values;
315 const auto origExport = origMatrix_->getGraph ()->getExporter ();
316 RCP<const import_type> myImport = origExport.is_null () ?
317 Teuchos::null : rcp (
new import_type (*origExport));
318 const auto origImport = origMatrix_->getGraph ()->getImporter ();
319 RCP<const export_type> myExport = origImport.is_null () ?
320 Teuchos::null : rcp (
new export_type (*origImport));
322 RCP<Teuchos::ParameterList> graphParams = Teuchos::null;
325 graph = rcp(
new crs_graph_type(lclTransposeMatrix.graph,
326 origMatrix_->getColMap (),
327 origMatrix_->getRowMap (),
328 origMatrix_->getGraph()->getRangeMap (),
329 origMatrix_->getGraph()->getDomainMap (),
337 origMatrix_->getBlockSize()));
348 #define TPETRA_ROWMATRIXTRANSPOSER_INSTANT(SCALAR,LO,GO,NODE) \
349 template class RowMatrixTransposer< SCALAR, LO , GO , NODE >;\
350 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.