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"
19#include "Teuchos_ParameterList.hpp"
20#include "Teuchos_TimeMonitor.hpp"
21#include "KokkosSparse_Utils.hpp"
25template <
class Scalar,
31 const std::string& label)
32 : origMatrix_(origMatrix) {}
34template <
class Scalar,
38Teuchos::RCP<CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
51 RCP<const export_type> exporter =
52 transMatrixWithSharedRows->getGraph()->getExporter();
53 if (exporter.is_null()) {
54 return transMatrixWithSharedRows;
56 Teuchos::ParameterList labelList;
57 if (!params.is_null()) {
58 const char paramName[] =
"compute global constants";
59 labelList.set(paramName, params->get(paramName,
true));
65 Teuchos::null, Teuchos::rcpFromRef(labelList));
73template <
class Scalar,
77Teuchos::RCP<CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
81 using Teuchos::ArrayRCP;
82 using Teuchos::ArrayView;
85 using Teuchos::rcp_dynamic_cast;
86 using LO = LocalOrdinal;
87 using GO = GlobalOrdinal;
93 const bool sort = [&]() {
94 constexpr bool sortDefault =
true;
95 const char sortParamName[] =
"sort";
96 return params.get() ==
nullptr ? sortDefault : params->get(sortParamName, sortDefault);
99 const LO lclNumRows(origMatrix_->getLocalNumRows());
101 RCP<const crs_matrix_type> crsMatrix =
102 rcp_dynamic_cast<const crs_matrix_type>(origMatrix_);
103 if (crsMatrix.is_null()) {
104 auto rowMap = origMatrix_->getRowMap();
105 if (rowMap->isOneToOne()) {
106 Teuchos::Array<size_t> numEntPerRow(lclNumRows);
107 for (LO lclRow = 0; lclRow < lclNumRows; ++lclRow) {
108 numEntPerRow[lclRow] = origMatrix_->getNumEntriesInLocalRow(lclRow);
110 auto colMap = origMatrix_->getColMap();
112 RCP<crs_matrix_type> crsMatrix_nc =
113 rcp(
new crs_matrix_type(rowMap, colMap, numEntPerRow()));
118 crsMatrix_nc->fillComplete(origMatrix_->getDomainMap(),
119 origMatrix_->getRangeMap());
120 crsMatrix = crsMatrix_nc;
122 TEUCHOS_ASSERT(
false);
128#if KOKKOSKERNELS_VERSION >= 50199
129 bool conjugate_values = Teuchos::ScalarTraits<Scalar>::isComplex;
131 bool conjugate_values =
false;
133 const char conjugateValuesParamName[] =
"conjugate values";
134 if (!params.is_null() && params->isParameter(conjugateValuesParamName)) {
135 conjugate_values = params->get(conjugateValuesParamName, conjugate_values);
139#if KOKKOSKERNELS_VERSION >= 50199
142 TEUCHOS_TEST_FOR_EXCEPTION(conjugate_values, std::runtime_error,
"Kokkos-Kernels does not yet support conjugating the values.");
146 Import_Util::sortCrsMatrix(lclTransposeMatrix);
150 const auto origExport = origMatrix_->getGraph()->getExporter();
151 RCP<const import_type> myImport = origExport.is_null() ? Teuchos::null : rcp(
new import_type(*origExport));
152 const auto origImport = origMatrix_->getGraph()->getImporter();
153 RCP<const export_type> myExport = origImport.is_null() ? Teuchos::null : rcp(
new export_type(*origImport));
155 RCP<Teuchos::ParameterList> graphParams = Teuchos::null;
157 graphParams = rcp(
new Teuchos::ParameterList);
158 graphParams->set(
"sorted",
false);
160 const char computeGlobalConstantsParamName[] =
"compute global constants";
161 if (!params.is_null() && params->isParameter(computeGlobalConstantsParamName)) {
162 if (graphParams.is_null())
163 graphParams = rcp(
new Teuchos::ParameterList);
164 graphParams->set(computeGlobalConstantsParamName, params->get<
bool>(computeGlobalConstantsParamName));
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) {}
186template <
class Scalar,
190Teuchos::RCP<BlockCrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
203 RCP<const export_type> exporter =
204 transMatrixWithSharedRows->getGraph()->getExporter();
205 if (exporter.is_null()) {
206 return transMatrixWithSharedRows;
208 Teuchos::ParameterList labelList;
209 if (!params.is_null()) {
210 const char paramName[] =
"compute global constants";
211 labelList.set(paramName, params->get(paramName,
true));
216 return exportAndFillCompleteBlockCrsMatrix<bcrs_matrix_type>(transMatrixWithSharedRows, *exporter);
224template <
class Scalar,
228Teuchos::RCP<BlockCrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
231 using Teuchos::Array;
232 using Teuchos::ArrayRCP;
233 using Teuchos::ArrayView;
236 using Teuchos::rcp_dynamic_cast;
237 using LO = LocalOrdinal;
238 using GO = GlobalOrdinal;
245 RCP<const bcrs_matrix_type> crsMatrix =
246 rcp_dynamic_cast<const bcrs_matrix_type>(origMatrix_);
248 if (crsMatrix.is_null())
249 TEUCHOS_ASSERT(
false);
253 typename local_matrix_device_type::values_type values;
254 RCP<const crs_graph_type> graph;
261 Import_Util::sortCrsMatrix(lclTransposeMatrix);
262 values = lclTransposeMatrix.values;
266 const auto origExport = origMatrix_->
getGraph()->getExporter();
267 RCP<const import_type> myImport = origExport.is_null() ? Teuchos::null : rcp(
new import_type(*origExport));
268 const auto origImport = origMatrix_->getGraph()->getImporter();
269 RCP<const export_type> myExport = origImport.is_null() ? Teuchos::null : rcp(
new export_type(*origImport));
271 RCP<Teuchos::ParameterList> graphParams = Teuchos::null;
276 origMatrix_->getRowMap(),
277 origMatrix_->getGraph()->getRangeMap(),
278 origMatrix_->getGraph()->getDomainMap(),
284 return rcp(
new bcrs_matrix_type(*graph,
286 origMatrix_->getBlockSize()));
296#define TPETRA_ROWMATRIXTRANSPOSER_INSTANT(SCALAR, LO, GO, NODE) \
297 template class RowMatrixTransposer<SCALAR, LO, GO, NODE>; \
298 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.
Utility functions for packing and unpacking sparse matrix entries.
::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.