39 const Matrix& B,
bool transposeB,
41 bool call_FillComplete_on_result,
42 bool doOptimizeStorage,
43 const std::string& label,
53 bool haveMultiplyDoFillComplete = call_FillComplete_on_result && doOptimizeStorage;
57 if (helpers::isTpetraCrs(A) && helpers::isTpetraCrs(B) && helpers::isTpetraCrs(C)) {
66 }
else if (helpers::isTpetraBlockCrs(A) && helpers::isTpetraBlockCrs(B)) {
71 std::cout <<
"WARNING: Using inefficient BlockCrs Multiply Placeholder" << std::endl;
83 new_params->set(
"compute global constants",
true);
97 Ac_w->replaceCrsMatrix(Ac_p);
104 if (call_FillComplete_on_result && !haveMultiplyDoFillComplete) {
106 fillParams->set(
"Optimize Storage", doOptimizeStorage);
113 RCP<Matrix> rcpA = Teuchos::rcp_const_cast<Matrix>(Teuchos::rcpFromRef(A));
114 RCP<Matrix> rcpB = Teuchos::rcp_const_cast<Matrix>(Teuchos::rcpFromRef(B));
115 C.
CreateView(
"stridedMaps", rcpA, transposeA, rcpB, transposeB);
178 bool doOptimizeStorage) {
180 "TwoMatrixMultiply for BlockedCrsMatrix not implemented for transposeA==true or transposeB==true");
191 for (
size_t i = 0; i < A.
Rows(); ++i) {
192 for (
size_t j = 0; j < B.
Cols(); ++j) {
195 for (
size_t l = 0; l < B.
Rows(); ++l) {
204 auto unwrap1 = Teuchos::rcp_dynamic_cast<BlockedCrsMatrix>(crmat1);
205 auto unwrap2 = Teuchos::rcp_dynamic_cast<BlockedCrsMatrix>(crmat2);
207 if (unwrap1.is_null() != unwrap2.is_null()) {
208 if (unwrap1 != Teuchos::null && unwrap1->Rows() == 1 && unwrap1->Cols() == 1)
209 crmat1 = unwrap1->getCrsMatrix();
210 if (unwrap2 != Teuchos::null && unwrap2->Rows() == 1 && unwrap2->Cols() == 1)
211 crmat2 = unwrap2->getCrsMatrix();
218 "A and B must be either both (compatible) BlockedCrsMatrix objects or both CrsMatrixWrap objects.");
222 Teuchos::rcp_const_cast<CrsGraph>(crmat1->getCrsGraph())->computeGlobalConstants();
224 Teuchos::rcp_const_cast<CrsGraph>(crmat2->getCrsGraph())->computeGlobalConstants();
227 "crmat1 does not have global constants");
229 "crmat2 does not have global constants");
231 if (crmat1->getGlobalNumEntries() == 0 || crmat2->getGlobalNumEntries() == 0)
237 if (crop1 != Teuchos::null && crop2 != Teuchos::null)
238 temp = Multiply(*crop1,
false, *crop2,
false, fos);
248 temp = TwoMatrixMultiplyBlock(*bop1, transposeA, *bop2, transposeB, fos, doFillComplete, doOptimizeStorage);
271 if (Cij->isFillComplete())
274 C->setMatrix(i, j, Cij);
276 C->setMatrix(i, j, Teuchos::null);
302 const Matrix& B,
bool transposeB,
const SC& beta,
315 if (rcpBopA == Teuchos::null && rcpBopB == Teuchos::null) {
321 const tcrs_matrix_type& tpA = helpers::Op2TpetraCrs(A);
322 const tcrs_matrix_type& tpB = helpers::Op2TpetraCrs(B);
323 C = helpers::tpetraAdd(tpA, transposeA, alpha, tpB, transposeB, beta);
326 if (A.
IsView(
"stridedMaps")) C->CreateView(
"stridedMaps", rcpFromRef(A));
327 if (B.
IsView(
"stridedMaps")) C->CreateView(
"stridedMaps", rcpFromRef(B));
331 else if (rcpBopA == Teuchos::null && rcpBopB != Teuchos::null) {
339 for (
size_t j = 0; j < rcpBopB->Cols(); ++j) {
341 if (rcpA != Teuchos::null &&
342 rcpBopB->getMatrix(i, j) != Teuchos::null) {
344 TwoMatrixAdd(*rcpA, transposeA, alpha,
345 *(rcpBopB->getMatrix(i, j)), transposeB, beta,
346 Cij, fos, AHasFixedNnzPerRow);
347 }
else if (rcpA == Teuchos::null &&
348 rcpBopB->getMatrix(i, j) != Teuchos::null) {
349 Cij = rcpBopB->getMatrix(i, j);
350 }
else if (rcpA != Teuchos::null &&
351 rcpBopB->getMatrix(i, j) == Teuchos::null) {
352 Cij = Teuchos::rcp_const_cast<Matrix>(rcpA);
358 if (Cij->isFillComplete())
361 bC->setMatrix(i, j, Cij);
363 bC->setMatrix(i, j, Teuchos::null);
368 else if (rcpBopA != Teuchos::null && rcpBopB == Teuchos::null) {
375 for (
size_t i = 0; i < rcpBopA->Rows(); ++i) {
377 if (rcpBopA->getMatrix(i, j) != Teuchos::null &&
378 rcpB != Teuchos::null) {
380 TwoMatrixAdd(*(rcpBopA->getMatrix(i, j)), transposeA, alpha,
381 *rcpB, transposeB, beta,
382 Cij, fos, AHasFixedNnzPerRow);
383 }
else if (rcpBopA->getMatrix(i, j) == Teuchos::null &&
384 rcpB != Teuchos::null) {
385 Cij = Teuchos::rcp_const_cast<Matrix>(rcpB);
386 }
else if (rcpBopA->getMatrix(i, j) != Teuchos::null &&
387 rcpB == Teuchos::null) {
388 Cij = rcpBopA->getMatrix(i, j);
394 if (Cij->isFillComplete())
397 bC->setMatrix(i, j, Cij);
399 bC->setMatrix(i, j, Teuchos::null);
420 for (
size_t i = 0; i < rcpBopA->Rows(); ++i) {
421 for (
size_t j = 0; j < rcpBopB->Cols(); ++j) {
424 if (rcpBopA->getMatrix(i, j) != Teuchos::null &&
425 rcpBopB->getMatrix(i, j) != Teuchos::null) {
427 TwoMatrixAdd(*(rcpBopA->getMatrix(i, j)), transposeA, alpha,
428 *(rcpBopB->getMatrix(i, j)), transposeB, beta,
429 Cij, fos, AHasFixedNnzPerRow);
430 }
else if (rcpBopA->getMatrix(i, j) == Teuchos::null &&
431 rcpBopB->getMatrix(i, j) != Teuchos::null) {
432 Cij = rcpBopB->getMatrix(i, j);
433 }
else if (rcpBopA->getMatrix(i, j) != Teuchos::null &&
434 rcpBopB->getMatrix(i, j) == Teuchos::null) {
435 Cij = rcpBopA->getMatrix(i, j);
441 if (Cij->isFillComplete())
444 bC->setMatrix(i, j, Cij);
446 bC->setMatrix(i, j, Teuchos::null);
void Multiply(const CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, bool transposeA, const CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &B, bool transposeB, CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &C, bool call_FillComplete_on_result=true, const std::string &label=std::string(), const Teuchos::RCP< Teuchos::ParameterList > ¶ms=Teuchos::null)