10 #ifndef PACKAGES_XPETRA_SUP_UTILS_XPETRA_TRIPLEMATRIXMULTIPLY_DECL_HPP_
11 #define PACKAGES_XPETRA_SUP_UTILS_XPETRA_TRIPLEMATRIXMULTIPLY_DECL_HPP_
16 #include "Xpetra_CrsMatrixWrap.hpp"
17 #include "Xpetra_MapExtractor.hpp"
18 #include "Xpetra_Map.hpp"
19 #include "Xpetra_MatrixFactory.hpp"
20 #include "Xpetra_Matrix.hpp"
21 #include "Xpetra_StridedMapFactory.hpp"
22 #include "Xpetra_StridedMap.hpp"
23 #include "Xpetra_IO.hpp"
25 #ifdef HAVE_XPETRA_TPETRA
26 #include <TpetraExt_TripleMatrixMultiply.hpp>
27 #include <Xpetra_TpetraCrsMatrix.hpp>
28 #include <Tpetra_BlockCrsMatrix.hpp>
29 #include <Tpetra_BlockCrsMatrix_Helpers.hpp>
32 #endif // HAVE_XPETRA_TPETRA
36 template <
class Scalar,
41 #undef XPETRA_TRIPLEMATRIXMULTIPLY_SHORT
70 const Matrix& A,
bool transposeA,
71 const Matrix& P,
bool transposeP,
73 bool call_FillComplete_on_result =
true,
74 bool doOptimizeStorage =
true,
75 const std::string& label = std::string(),
76 const RCP<ParameterList>& params = null);
80 #ifdef HAVE_XPETRA_EPETRA
92 const Matrix& A,
bool transposeA,
93 const Matrix& P,
bool transposeP,
95 bool call_FillComplete_on_result =
true,
96 bool doOptimizeStorage =
true,
97 const std::string& label = std::string(),
98 const RCP<ParameterList>& params = null) {
99 TEUCHOS_TEST_FOR_EXCEPTION(transposeR ==
false && Ac.
getRowMap()->isSameAs(*R.
getRowMap()) ==
false,
100 Exceptions::RuntimeError,
"XpetraExt::TripleMatrixMultiply::MultiplyRAP: row map of Ac is not same as row map of R");
101 TEUCHOS_TEST_FOR_EXCEPTION(transposeR ==
true && Ac.
getRowMap()->isSameAs(*R.
getDomainMap()) ==
false,
102 Exceptions::RuntimeError,
"XpetraExt::TripleMatrixMultiply::MultiplyRAP: row map of Ac is not same as domain map of R");
108 bool haveMultiplyDoFillComplete = call_FillComplete_on_result && doOptimizeStorage;
113 #ifdef HAVE_XPETRA_TPETRA
114 #if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \
115 (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT))))
119 if (helpers::isTpetraCrs(R) && helpers::isTpetraCrs(A) && helpers::isTpetraCrs(P) && helpers::isTpetraCrs(Ac)) {
128 Tpetra::TripleMatrixMultiply::MultiplyRAP(tpR, transposeR, tpA, transposeA, tpP, transposeP, tpAc, haveMultiplyDoFillComplete, label, params);
129 }
else if (helpers::isTpetraBlockCrs(R) && helpers::isTpetraBlockCrs(A) && helpers::isTpetraBlockCrs(P)) {
133 if (!A.
getRowMap()->getComm()->getRank())
134 std::cout <<
"WARNING: Using inefficient BlockCrs Multiply Placeholder" << std::endl;
141 using CRS = Tpetra::CrsMatrix<SC, LO, GO, NO>;
142 RCP<const CRS> Rcrs = Tpetra::convertToCrsMatrix(tpR);
143 RCP<const CRS> Acrs = Tpetra::convertToCrsMatrix(tpA);
144 RCP<const CRS> Pcrs = Tpetra::convertToCrsMatrix(tpP);
148 RCP<CRS> Accrs = Teuchos::rcp(
new CRS(Rcrs->getRowMap(), 0));
149 const bool do_fill_complete =
true;
150 Tpetra::TripleMatrixMultiply::MultiplyRAP(*Rcrs, transposeR, *Acrs, transposeA, *Pcrs, transposeP, *Accrs, do_fill_complete, label, params);
153 RCP<Tpetra::BlockCrsMatrix<SC, LO, GO, NO> > Ac_t = Tpetra::convertToBlockCrsMatrix(*Accrs, A.
GetStorageBlockSize());
155 RCP<Xpetra::CrsMatrix<SC, LO, GO, NO> > Ac_p = Ac_x;
163 TEUCHOS_TEST_FOR_EXCEPTION(1,
Exceptions::RuntimeError,
"Mix-and-match Crs/BlockCrs Multiply not currently supported");
169 if (call_FillComplete_on_result && !haveMultiplyDoFillComplete) {
170 RCP<Teuchos::ParameterList> fillParams = rcp(
new Teuchos::ParameterList());
171 fillParams->set(
"Optimize Storage", doOptimizeStorage);
178 RCP<const Map> domainMap = Teuchos::null;
179 RCP<const Map> rangeMap = Teuchos::null;
181 const std::string stridedViewLabel(
"stridedMaps");
182 const size_t blkSize = 1;
183 std::vector<size_t> stridingInfo(1, blkSize);
186 if (R.
IsView(stridedViewLabel)) {
187 rangeMap = transposeR ? R.
getColMap(stridedViewLabel) : R.
getRowMap(stridedViewLabel);
193 if (P.
IsView(stridedViewLabel)) {
194 domainMap = transposeP ? P.
getRowMap(stridedViewLabel) : P.
getColMap(stridedViewLabel);
199 Ac.
CreateView(stridedViewLabel, rangeMap, domainMap);
217 const Matrix& A,
bool transposeA,
218 const Matrix& P,
bool transposeP,
220 bool call_FillComplete_on_result =
true,
221 bool doOptimizeStorage =
true,
222 const std::string& label = std::string(),
223 const RCP<ParameterList>& params = null) {
224 TEUCHOS_TEST_FOR_EXCEPTION(transposeR ==
false && Ac.
getRowMap()->isSameAs(*R.
getRowMap()) ==
false,
225 Exceptions::RuntimeError,
"XpetraExt::TripleMatrixMultiply::MultiplyRAP: row map of Ac is not same as row map of R");
226 TEUCHOS_TEST_FOR_EXCEPTION(transposeR ==
true && Ac.
getRowMap()->isSameAs(*R.
getDomainMap()) ==
false,
227 Exceptions::RuntimeError,
"XpetraExt::TripleMatrixMultiply::MultiplyRAP: row map of Ac is not same as domain map of R");
233 bool haveMultiplyDoFillComplete = call_FillComplete_on_result && doOptimizeStorage;
238 #ifdef HAVE_XPETRA_TPETRA
239 #if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_LONG_LONG))) || \
240 (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_LONG_LONG))))
244 if (helpers::isTpetraCrs(R) && helpers::isTpetraCrs(A) && helpers::isTpetraCrs(P)) {
253 Tpetra::TripleMatrixMultiply::MultiplyRAP(tpR, transposeR, tpA, transposeA, tpP, transposeP, tpAc, haveMultiplyDoFillComplete, label, params);
254 }
else if (helpers::isTpetraBlockCrs(R) && helpers::isTpetraBlockCrs(A) && helpers::isTpetraBlockCrs(P)) {
258 if (!A.
getRowMap()->getComm()->getRank())
259 std::cout <<
"WARNING: Using inefficient BlockCrs Multiply Placeholder" << std::endl;
266 using CRS = Tpetra::CrsMatrix<SC, LO, GO, NO>;
267 RCP<const CRS> Rcrs = Tpetra::convertToCrsMatrix(tpR);
268 RCP<const CRS> Acrs = Tpetra::convertToCrsMatrix(tpA);
269 RCP<const CRS> Pcrs = Tpetra::convertToCrsMatrix(tpP);
273 RCP<CRS> Accrs = Teuchos::rcp(
new CRS(Rcrs->getRowMap(), 0));
274 const bool do_fill_complete =
true;
275 Tpetra::TripleMatrixMultiply::MultiplyRAP(*Rcrs, transposeR, *Acrs, transposeA, *Pcrs, transposeP, *Accrs, do_fill_complete, label, params);
278 RCP<Tpetra::BlockCrsMatrix<SC, LO, GO, NO> > Ac_t = Tpetra::convertToBlockCrsMatrix(*Accrs, A.
GetStorageBlockSize());
280 RCP<Xpetra::CrsMatrix<SC, LO, GO, NO> > Ac_p = Ac_x;
287 TEUCHOS_TEST_FOR_EXCEPTION(1,
Exceptions::RuntimeError,
"Mix-and-match Crs/BlockCrs Multiply not currently supported");
294 if (call_FillComplete_on_result && !haveMultiplyDoFillComplete) {
295 RCP<Teuchos::ParameterList> fillParams = rcp(
new Teuchos::ParameterList());
296 fillParams->set(
"Optimize Storage", doOptimizeStorage);
303 RCP<const Map> domainMap = Teuchos::null;
304 RCP<const Map> rangeMap = Teuchos::null;
306 const std::string stridedViewLabel(
"stridedMaps");
307 const size_t blkSize = 1;
308 std::vector<size_t> stridingInfo(1, blkSize);
311 if (R.
IsView(stridedViewLabel)) {
312 rangeMap = transposeR ? R.
getColMap(stridedViewLabel) : R.
getRowMap(stridedViewLabel);
318 if (P.
IsView(stridedViewLabel)) {
319 domainMap = transposeP ? P.
getRowMap(stridedViewLabel) : P.
getColMap(stridedViewLabel);
324 Ac.
CreateView(stridedViewLabel, rangeMap, domainMap);
334 #define XPETRA_TRIPLEMATRIXMULTIPLY_SHORT
static void MultiplyRAP(const Matrix &R, bool transposeR, const Matrix &A, bool transposeA, const Matrix &P, bool transposeP, Matrix &Ac, bool call_FillComplete_on_result=true, bool doOptimizeStorage=true, const std::string &label=std::string(), const RCP< ParameterList > ¶ms=null)
virtual const RCP< const Map > & getColMap() const
Returns the Map that describes the column distribution in this matrix. This might be null until fillC...
static void MultiplyRAP(const Matrix &R, bool transposeR, const Matrix &A, bool transposeA, const Matrix &P, bool transposeP, Matrix &Ac, bool call_FillComplete_on_result=true, bool doOptimizeStorage=true, const std::string &label=std::string(), const RCP< ParameterList > ¶ms=null)
Xpetra utility class containing transformation routines between Xpetra::Matrix and Epetra/Tpetra obje...
virtual const RCP< const Map > & getRowMap() const
Returns the Map that describes the row distribution in this matrix.
virtual LocalOrdinal GetStorageBlockSize() const =0
Returns the block size of the storage mechanism, which is usually 1, except for Tpetra::BlockCrsMatri...
Exception throws to report errors in the internal logical of the program.
static RCP< const Tpetra::CrsMatrix< SC, LO, GO, NO > > Op2TpetraCrs(RCP< Matrix > Op)
virtual void fillComplete(const RCP< const Map > &domainMap, const RCP< const Map > &rangeMap, const RCP< ParameterList > ¶ms=null)=0
Signal that data entry is complete, specifying domain and range maps.
bool IsView(const viewLabel_t viewLabel) const
virtual bool isFillComplete() const =0
Returns true if fillComplete() has been called and the matrix is in compute mode. ...
void CreateView(viewLabel_t viewLabel, const RCP< const Map > &rowMap, const RCP< const Map > &colMap)
virtual const Teuchos::RCP< const map_type > getRangeMap() const =0
The Map associated with the range of this operator, which must be compatible with Y...
static RCP< Tpetra::CrsMatrix< SC, LO, GO, NO > > Op2NonConstTpetraCrs(RCP< Matrix > Op)
Tpetra::KokkosCompat::KokkosSerialWrapperNode EpetraNode
void replaceCrsMatrix(RCP< CrsMatrix > &M)
Expert only.
Concrete implementation of Xpetra::Matrix.
static void MultiplyRAP(const Matrix &R, bool transposeR, const Matrix &A, bool transposeA, const Matrix &P, bool transposeP, Matrix &Ac, bool call_FillComplete_on_result=true, bool doOptimizeStorage=true, const std::string &label=std::string(), const RCP< ParameterList > ¶ms=null)
virtual const Teuchos::RCP< const map_type > getDomainMap() const =0
The Map associated with the domain of this operator, which must be compatible with X...
static RCP< const Tpetra::BlockCrsMatrix< SC, LO, GO, NO > > Op2TpetraBlockCrs(RCP< Matrix > Op)
static RCP< Xpetra::StridedMap< LocalOrdinal, GlobalOrdinal, Node > > Build(UnderlyingLib lib, global_size_t numGlobalElements, GlobalOrdinal indexBase, std::vector< size_t > &stridingInfo, const Teuchos::RCP< const Teuchos::Comm< int >> &comm, LocalOrdinal stridedBlockId=-1, GlobalOrdinal offset=0, LocalGlobal lg=Xpetra::GloballyDistributed)
Map constructor with Xpetra-defined contiguous uniform distribution.
Xpetra-specific matrix class.