Tpetra parallel linear algebra Version of the Day
Loading...
Searching...
No Matches
Tpetra_Reindex_CrsMatrix_def.hpp
Go to the documentation of this file.
1// @HEADER
2// *****************************************************************************
3// Tpetra: Templated Linear Algebra Services Package
4//
5// Copyright 2008 NTESS and the Tpetra contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
10#ifndef TPETRA_REINDEX_CRSMATRIX_DEF_HPP
11#define TPETRA_REINDEX_CRSMATRIX_DEF_HPP
12
15#include <Tpetra_Import_decl.hpp>
16
17#include <vector>
18
28
29namespace Tpetra {
30
31template <class Scalar,
32 class LocalOrdinal,
33 class GlobalOrdinal,
34 class Node>
37 : ViewTransform<CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >()
38 , newRowMap_(newRowMap)
39 , newColMap_(Teuchos::null) {
40 // Nothing to do
41}
42
43template <class Scalar,
44 class LocalOrdinal,
45 class GlobalOrdinal,
46 class Node>
50
51template <class Scalar,
52 class LocalOrdinal,
53 class GlobalOrdinal,
54 class Node>
55typename Reindex_CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>::NewType
58
59 this->origObj_ = origMatrix;
60
61 assert(origMatrix->getRowMap()->getLocalNumElements() == newRowMap_->getLocalNumElements());
62
63 if ((origMatrix->getDomainMap()->getGlobalNumElements() == 0) &&
64 (origMatrix->getRowMap()->getGlobalNumElements() == 0)) {
65 // Construct a zero matrix as a placeholder, don't do reindexing analysis.
66 this->newObj_ = Teuchos::rcp<cm_t>(new cm_t(origMatrix->getRowMap(), origMatrix->getColMap(), 0));
67 } else {
70
71 // Construct new column map
72 v_t cols(origMatrix->getDomainMap());
73 {
74 size_t origDomainMap_localSize = origMatrix->getDomainMap()->getLocalNumElements();
75 map_t tmpColMap(origMatrix->getDomainMap()->getGlobalNumElements(), origDomainMap_localSize, 0, origMatrix->getDomainMap()->getComm());
76 Kokkos::deep_copy(Kokkos::subview(cols.getLocalViewDevice(Tpetra::Access::OverwriteAll), Kokkos::ALL(), 0),
77 tmpColMap.getMyGlobalIndicesDevice());
78 }
79
80 v_t newCols(origMatrix->getColMap());
81 {
83 Teuchos::RCP<const imp_t> importer = origMatrix->getCrsGraph()->getImporter();
84 if (importer.is_null()) {
85 newCols = cols;
86 } else {
87 newCols.doImport(cols, *importer, INSERT, false);
88 }
89 }
90
91 using kv_t = Kokkos::View<GlobalOrdinal*, typename Node::device_type>;
93 {
94 auto newColsView = newCols.getLocalViewDevice(Tpetra::Access::ReadOnly);
95 newColIndices = kv_t("newColIndices", newColsView.extent(0));
96 Kokkos::deep_copy(newColIndices, Kokkos::subview(newColsView, Kokkos::ALL(), 0));
97 }
98
99 this->newColMap_ = Teuchos::RCP<map_t>(new map_t(origMatrix->getColMap()->getGlobalNumElements(),
101 origMatrix->getColMap()->getIndexBase(),
102 origMatrix->getColMap()->getComm()));
103
104 // Create the new matrix
105 typename cm_t::local_matrix_device_type tmpLocalMatrix("", origMatrix->getLocalMatrixDevice());
106 Teuchos::RCP<cm_t> newMatrix = Teuchos::rcp<cm_t>(new cm_t(tmpLocalMatrix, this->newRowMap_, this->newColMap_));
107
108 this->newObj_ = newMatrix;
109 }
110
111 return this->newObj_;
112}
113
114//
115// Explicit instantiation macro
116//
117// Must be expanded from within the Tpetra namespace!
118//
119
120#define TPETRA_REINDEXCRSMATRIX_INSTANT(SCALAR, LO, GO, NODE) \
121 template class Reindex_CrsMatrix<SCALAR, LO, GO, NODE>;
122
123} // namespace Tpetra
124
125#endif // TPETRA_REINDEX_CRSMATRIX_DEF_HPP
Declaration of the Tpetra::Reindex_CrsMatrix class.
Declaration of the Tpetra::Vector class.
Struct that holds views of the contents of a CrsMatrix.
Teuchos::RCP< const CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > origMatrix
The original matrix.
Sparse matrix that presents a row-oriented interface that lets users read or modify entries.
NewType operator()(OriginalType const &origMatrix)
Reindex_CrsMatrix(Teuchos::RCP< Map< LocalOrdinal, GlobalOrdinal, Node > const > newRowMap)
Namespace Tpetra contains the class and methods constituting the Tpetra library.
@ INSERT
Insert new values that don't currently exist.