42#ifndef TPETRA_ROWMATRIXTRANSPOSER_DEF_HPP
43#define TPETRA_ROWMATRIXTRANSPOSER_DEF_HPP
45#include "Tpetra_CrsMatrix.hpp"
46#include "Tpetra_Export.hpp"
49#include "Teuchos_ParameterList.hpp"
50#include "Teuchos_TimeMonitor.hpp"
51#include "KokkosKernels_SparseUtils.hpp"
61 const std::string& label)
62 : origMatrix_ (origMatrix), label_ (label)
69Teuchos::RCP<CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
75 RCP<crs_matrix_type> transMatrixWithSharedRows = createTransposeLocal (params);
77#ifdef HAVE_TPETRA_MMM_TIMINGS
78 const std::string prefix = std::string (
"Tpetra ") + label_ +
": ";
79 using Teuchos::TimeMonitor;
80 TimeMonitor MM (*TimeMonitor::getNewTimer (prefix +
"Transpose TAFC"));
87 RCP<const export_type> exporter =
88 transMatrixWithSharedRows->getGraph ()->getExporter ();
89 if (exporter.is_null ()) {
90 return transMatrixWithSharedRows;
93 Teuchos::ParameterList labelList;
94#ifdef HAVE_TPETRA_MMM_TIMINGS
95 labelList.set(
"Timer Label", label_);
97 if(! params.is_null ()) {
98 const char paramName[] =
"compute global constants";
99 labelList.set (paramName, params->get (paramName,
true));
104 return exportAndFillCompleteCrsMatrix<crs_matrix_type>
105 (transMatrixWithSharedRows, *exporter, Teuchos::null,
106 Teuchos::null, Teuchos::rcpFromRef (labelList));
115template<
class Scalar,
119Teuchos::RCP<CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
123 using Teuchos::Array;
124 using Teuchos::ArrayRCP;
125 using Teuchos::ArrayView;
128 using Teuchos::rcp_dynamic_cast;
129 using LO = LocalOrdinal;
130 using GO = GlobalOrdinal;
134#ifdef HAVE_TPETRA_MMM_TIMINGS
135 std::string prefix = std::string(
"Tpetra ") + label_ +
": ";
136 using Teuchos::TimeMonitor;
137 TimeMonitor MM (*TimeMonitor::getNewTimer (prefix +
"Transpose Local"));
140 const bool sort = [&] () {
141 constexpr bool sortDefault =
true;
142 const char sortParamName[] =
"sort";
143 return params.get () ==
nullptr ? sortDefault :
144 params->get (sortParamName, sortDefault);
147 const LO lclNumRows (origMatrix_->getNodeNumRows ());
149 RCP<const crs_matrix_type> crsMatrix =
150 rcp_dynamic_cast<const crs_matrix_type> (origMatrix_);
151 if (crsMatrix.is_null ()) {
152 auto rowMap = origMatrix_->getRowMap ();
153 if (rowMap->isOneToOne ()) {
154 Teuchos::Array<size_t> numEntPerRow (lclNumRows);
155 for (LO lclRow = 0; lclRow < lclNumRows; ++lclRow) {
156 numEntPerRow[lclRow] = origMatrix_->getNumEntriesInLocalRow (lclRow);
158 auto colMap = origMatrix_->getColMap ();
160 RCP<crs_matrix_type> crsMatrix_nc =
164 import_type imp (rowMap, rowMap);
166 crsMatrix_nc->fillComplete (origMatrix_->getDomainMap (),
167 origMatrix_->getRangeMap ());
168 crsMatrix = crsMatrix_nc;
171 TEUCHOS_ASSERT(
false );
177 local_matrix_device_type lclMatrix = crsMatrix->getLocalMatrixDevice ();
178 local_matrix_device_type lclTransposeMatrix = KokkosKernels::Impl::transpose_matrix(lclMatrix);
180 KokkosKernels::Impl::sort_crs_matrix(lclTransposeMatrix);
184 const auto origExport = origMatrix_->getGraph ()->getExporter ();
185 RCP<const import_type> myImport = origExport.is_null () ?
186 Teuchos::null : rcp (
new import_type (*origExport));
187 const auto origImport = origMatrix_->getGraph ()->getImporter ();
188 RCP<const export_type> myExport = origImport.is_null () ?
189 Teuchos::null : rcp (
new export_type (*origImport));
191 RCP<Teuchos::ParameterList> graphParams = Teuchos::null;
193 graphParams = rcp(
new Teuchos::ParameterList);
194 graphParams->set(
"sorted",
false);
198 origMatrix_->getColMap (),
199 origMatrix_->getRowMap (),
200 origMatrix_->getRangeMap (),
201 origMatrix_->getDomainMap (),
202 myImport, myExport, graphParams));
210#define TPETRA_ROWMATRIXTRANSPOSER_INSTANT(SCALAR,LO,GO,NODE) \
211 template class RowMatrixTransposer< 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.
Sparse matrix that presents a row-oriented interface that lets users read or modify entries.
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.
@ REPLACE
Replace existing values with new values.