119 const bool doTranspose =
true;
120 const bool doFillComplete =
true;
121 const bool doOptimizeStorage =
true;
125 std::ostringstream levelstr;
130 "MueLu::RAPFactory::Build(): CallDeclareInput has not been called before Build!");
137 if (P == Teuchos::null) {
139 Set(coarseLevel,
"A", Ac);
143 bool isEpetra = A->getRowMap()->lib() == Xpetra::UseEpetra;
145#ifdef KOKKOS_ENABLE_CUDA
146 (
typeid(
Node).name() ==
typeid(Tpetra::KokkosCompat::KokkosCudaWrapperNode).name()) ||
148#ifdef KOKKOS_ENABLE_HIP
149 (
typeid(
Node).name() ==
typeid(Tpetra::KokkosCompat::KokkosHIPWrapperNode).name()) ||
151#ifdef KOKKOS_ENABLE_SYCL
152 (
typeid(
Node).name() ==
typeid(Tpetra::KokkosCompat::KokkosSYCLWrapperNode).name()) ||
156 if (pL.get<
bool>(
"rap: triple product") ==
false || isEpetra || isGPU) {
157 if (pL.get<
bool>(
"rap: triple product") && isEpetra)
158 GetOStream(
Warnings1) <<
"Switching from triple product to R x (A x P) since triple product has not been implemented for Epetra.\n";
159#if defined(KOKKOS_ENABLE_CUDA) || defined(KOKKOS_ENABLE_HIP) || defined(KOKKOS_ENABLE_SYCL)
160 if (pL.get<
bool>(
"rap: triple product") && isGPU)
161 GetOStream(
Warnings1) <<
"Switching from triple product to R x (A x P) since triple product has not been implemented for "
162 << Node::execution_space::name() << std::endl;
166 RCP<ParameterList> APparams = rcp(
new ParameterList);
167 if(pL.isSublist(
"matrixmatrix: kernel params"))
168 APparams->sublist(
"matrixmatrix: kernel params") = pL.sublist(
"matrixmatrix: kernel params");
171 APparams->set(
"compute global constants: temporaries",APparams->get(
"compute global constants: temporaries",
false));
172 APparams->set(
"compute global constants",APparams->get(
"compute global constants",
false));
174 if (coarseLevel.IsAvailable(
"AP reuse data",
this)) {
177 APparams = coarseLevel.Get< RCP<ParameterList> >(
"AP reuse data",
this);
179 if (APparams->isParameter(
"graph"))
180 AP = APparams->get< RCP<Matrix> >(
"graph");
187 doFillComplete, doOptimizeStorage, labelstr+std::string(
"MueLu::A*P-")+levelstr.str(), APparams);
191 RCP<ParameterList> RAPparams = rcp(
new ParameterList);
192 if(pL.isSublist(
"matrixmatrix: kernel params"))
193 RAPparams->sublist(
"matrixmatrix: kernel params") = pL.sublist(
"matrixmatrix: kernel params");
195 if (coarseLevel.IsAvailable(
"RAP reuse data",
this)) {
198 RAPparams = coarseLevel.Get< RCP<ParameterList> >(
"RAP reuse data",
this);
200 if (RAPparams->isParameter(
"graph"))
201 Ac = RAPparams->get< RCP<Matrix> >(
"graph");
205 Ac->SetMaxEigenvalueEstimate(-Teuchos::ScalarTraits<SC>::one());
209 RAPparams->set(
"compute global constants: temporaries",RAPparams->get(
"compute global constants: temporaries",
false));
210 RAPparams->set(
"compute global constants",
true);
216 if (pL.get<
bool>(
"transpose: use implicit") ==
true) {
220 doFillComplete, doOptimizeStorage, labelstr+std::string(
"MueLu::R*(AP)-implicit-")+levelstr.str(), RAPparams);
228 doFillComplete, doOptimizeStorage, labelstr+std::string(
"MueLu::R*(AP)-explicit-")+levelstr.str(), RAPparams);
231 Teuchos::ArrayView<const double> relativeFloor = pL.get<Teuchos::Array<double> >(
"rap: relative diagonal floor")();
232 if(relativeFloor.size() > 0) {
236 bool repairZeroDiagonals = pL.get<
bool>(
"RepairMainDiagonal") || pL.get<
bool>(
"rap: fix zero diagonals");
237 bool checkAc = pL.get<
bool>(
"CheckMainDiagonal")|| pL.get<
bool>(
"rap: fix zero diagonals"); ;
238 if (checkAc || repairZeroDiagonals) {
239 using magnitudeType =
typename Teuchos::ScalarTraits<Scalar>::magnitudeType;
240 magnitudeType threshold;
241 if (pL.isType<magnitudeType>(
"rap: fix zero diagonals threshold"))
242 threshold = pL.get<magnitudeType>(
"rap: fix zero diagonals threshold");
244 threshold = Teuchos::as<magnitudeType>(pL.get<
double>(
"rap: fix zero diagonals threshold"));
245 Scalar replacement = Teuchos::as<Scalar>(pL.get<
double>(
"rap: fix zero diagonals replacement"));
246 Xpetra::MatrixUtils<SC,LO,GO,NO>::CheckRepairMainDiagonal(Ac, repairZeroDiagonals,
GetOStream(
Warnings1), threshold, replacement);
250 RCP<ParameterList> params = rcp(
new ParameterList());;
251 params->set(
"printLoadBalancingInfo",
true);
252 params->set(
"printCommInfo",
true);
256 if(!Ac.is_null()) {std::ostringstream oss; oss <<
"A_" << coarseLevel.GetLevelID(); Ac->setObjectLabel(oss.str());}
257 Set(coarseLevel,
"A", Ac);
260 APparams->set(
"graph", AP);
261 Set(coarseLevel,
"AP reuse data", APparams);
264 RAPparams->set(
"graph", Ac);
265 Set(coarseLevel,
"RAP reuse data", RAPparams);
268 RCP<ParameterList> RAPparams = rcp(
new ParameterList);
269 if(pL.isSublist(
"matrixmatrix: kernel params"))
270 RAPparams->sublist(
"matrixmatrix: kernel params") = pL.sublist(
"matrixmatrix: kernel params");
272 if (coarseLevel.IsAvailable(
"RAP reuse data",
this)) {
275 RAPparams = coarseLevel.Get< RCP<ParameterList> >(
"RAP reuse data",
this);
277 if (RAPparams->isParameter(
"graph"))
278 Ac = RAPparams->get< RCP<Matrix> >(
"graph");
282 Ac->SetMaxEigenvalueEstimate(-Teuchos::ScalarTraits<SC>::one());
286 RAPparams->set(
"compute global constants: temporaries",RAPparams->get(
"compute global constants: temporaries",
false));
287 RAPparams->set(
"compute global constants",
true);
289 if (pL.get<
bool>(
"transpose: use implicit") ==
true) {
291 Ac = MatrixFactory::Build(P->getDomainMap(), Teuchos::as<LO>(0));
295 Xpetra::TripleMatrixMultiply<SC,LO,GO,NO>::
296 MultiplyRAP(*P, doTranspose, *A, !doTranspose, *P, !doTranspose, *Ac, doFillComplete,
297 doOptimizeStorage, labelstr+std::string(
"MueLu::R*A*P-implicit-")+levelstr.str(),
301 Ac = MatrixFactory::Build(R->getRowMap(), Teuchos::as<LO>(0));
305 Xpetra::TripleMatrixMultiply<SC,LO,GO,NO>::
306 MultiplyRAP(*R, !doTranspose, *A, !doTranspose, *P, !doTranspose, *Ac, doFillComplete,
307 doOptimizeStorage, labelstr+std::string(
"MueLu::R*A*P-explicit-")+levelstr.str(),
311 Teuchos::ArrayView<const double> relativeFloor = pL.get<Teuchos::Array<double> >(
"rap: relative diagonal floor")();
312 if(relativeFloor.size() > 0) {
316 bool repairZeroDiagonals = pL.get<
bool>(
"RepairMainDiagonal") || pL.get<
bool>(
"rap: fix zero diagonals");
317 bool checkAc = pL.get<
bool>(
"CheckMainDiagonal")|| pL.get<
bool>(
"rap: fix zero diagonals"); ;
318 if (checkAc || repairZeroDiagonals) {
319 using magnitudeType =
typename Teuchos::ScalarTraits<Scalar>::magnitudeType;
320 magnitudeType threshold;
321 if (pL.isType<magnitudeType>(
"rap: fix zero diagonals threshold"))
322 threshold = pL.get<magnitudeType>(
"rap: fix zero diagonals threshold");
324 threshold = Teuchos::as<magnitudeType>(pL.get<
double>(
"rap: fix zero diagonals threshold"));
325 Scalar replacement = Teuchos::as<Scalar>(pL.get<
double>(
"rap: fix zero diagonals replacement"));
326 Xpetra::MatrixUtils<SC,LO,GO,NO>::CheckRepairMainDiagonal(Ac, repairZeroDiagonals,
GetOStream(
Warnings1), threshold, replacement);
331 RCP<ParameterList> params = rcp(
new ParameterList());;
332 params->set(
"printLoadBalancingInfo",
true);
333 params->set(
"printCommInfo",
true);
337 if(!Ac.is_null()) {std::ostringstream oss; oss <<
"A_" << coarseLevel.GetLevelID(); Ac->setObjectLabel(oss.str());}
338 Set(coarseLevel,
"A", Ac);
341 RAPparams->set(
"graph", Ac);
342 Set(coarseLevel,
"RAP reuse data", RAPparams);
349#ifdef HAVE_MUELU_DEBUG
350 MatrixUtils::checkLocalRowMapMatchesColMap(*Ac);
358 RCP<const FactoryBase> fac = *it;
359 GetOStream(
Runtime0) <<
"RAPFactory: call transfer factory: " << fac->description() << std::endl;
360 fac->CallBuild(coarseLevel);