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"
31 const std::string& label)
32 : origMatrix_ (origMatrix), label_ (label)
39Teuchos::RCP<CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
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));
75 (transMatrixWithSharedRows, *exporter, Teuchos::null,
76 Teuchos::null, Teuchos::rcpFromRef (labelList));
89Teuchos::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 =
120 rcp_dynamic_cast<const crs_matrix_type> (origMatrix_);
121 if (crsMatrix.is_null ()) {
122 auto rowMap = origMatrix_->getRowMap ();
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 =
131 rcp (
new crs_matrix_type (rowMap, colMap, numEntPerRow ()));
136 crsMatrix_nc->fillComplete (origMatrix_->getDomainMap (),
137 origMatrix_->getRangeMap ());
138 crsMatrix = crsMatrix_nc;
141 TEUCHOS_ASSERT(
false );
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);
167 return rcp (
new crs_matrix_type (lclTransposeMatrix,
169 origMatrix_->getRowMap (),
170 origMatrix_->getRangeMap (),
171 origMatrix_->getDomainMap (),
172 myImport, myExport, graphParams));
177template<
class Scalar,
183 const std::string& label)
184 : origMatrix_ (origMatrix), label_ (label)
187template<
class Scalar,
191Teuchos::RCP<BlockCrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
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);
236template<
class Scalar,
240Teuchos::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 =
263 rcp_dynamic_cast<const bcrs_matrix_type> (origMatrix_);
265 if(crsMatrix.is_null())
266 TEUCHOS_ASSERT(
false );
270 typename local_matrix_device_type::values_type values ;
271 RCP<const crs_graph_type> graph;
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;
295 origMatrix_->getRowMap (),
296 origMatrix_->getGraph()->getRangeMap (),
297 origMatrix_->getGraph()->getDomainMap (),
303 return rcp (
new bcrs_matrix_type (*graph,
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 >;
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.
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::CrsGraph< LocalOrdinal, GlobalOrdinal, node_type > crs_graph_type
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.