81 const bool doTranspose =
true;
82 const bool doFillComplete =
true;
83 const bool doOptimizeStorage =
true;
87 std::ostringstream levelstr;
92 "MueLu::RAPFactory::Build(): CallDeclareInput has not been called before Build!");
94 const Teuchos::ParameterList& pL = GetParameterList();
95 RCP<Matrix> A = Get<RCP<Matrix> >(fineLevel,
"A");
96 RCP<Matrix> P = Get<RCP<Matrix> >(coarseLevel,
"P"), AP;
99 if (P == Teuchos::null) {
101 Set(coarseLevel,
"A", Ac);
105 bool isGPU = Node::is_gpu;
107 if (pL.get<
bool>(
"rap: triple product") ==
false || isGPU) {
108 if (pL.get<
bool>(
"rap: triple product") && isGPU)
109 GetOStream(
Warnings1) <<
"Switching from triple product to R x (A x P) since triple product has not been implemented for "
110 << Node::execution_space::name() << std::endl;
113 RCP<ParameterList> APparams = rcp(
new ParameterList);
114 if (pL.isSublist(
"matrixmatrix: kernel params"))
115 APparams = rcp(
new ParameterList(pL.sublist(
"matrixmatrix: kernel params")));
118 APparams->set(
"compute global constants: temporaries", APparams->get(
"compute global constants: temporaries",
false));
119 APparams->set(
"compute global constants", APparams->get(
"compute global constants",
false));
121 if (coarseLevel.IsAvailable(
"AP reuse data",
this)) {
122 GetOStream(
static_cast<MsgType>(
Runtime0 |
Test)) <<
"Reusing previous AP data" << std::endl;
124 APparams = coarseLevel.Get<RCP<ParameterList> >(
"AP reuse data",
this);
126 if (APparams->isParameter(
"graph"))
127 AP = APparams->get<RCP<Matrix> >(
"graph");
133 AP = MatrixMatrix::Multiply(*A, !doTranspose, *P, !doTranspose, AP, GetOStream(
Statistics2),
134 doFillComplete, doOptimizeStorage, labelstr + std::string(
"MueLu::A*P-") + levelstr.str(), APparams);
138 RCP<ParameterList> RAPparams = rcp(
new ParameterList);
139 if (pL.isSublist(
"matrixmatrix: kernel params"))
140 RAPparams = rcp(
new ParameterList(pL.sublist(
"matrixmatrix: kernel params")));
142 if (coarseLevel.IsAvailable(
"RAP reuse data",
this)) {
143 GetOStream(
static_cast<MsgType>(
Runtime0 |
Test)) <<
"Reusing previous RAP data" << std::endl;
145 RAPparams = coarseLevel.Get<RCP<ParameterList> >(
"RAP reuse data",
this);
147 if (RAPparams->isParameter(
"graph"))
148 Ac = RAPparams->get<RCP<Matrix> >(
"graph");
152 Ac->SetMaxEigenvalueEstimate(-Teuchos::ScalarTraits<SC>::one());
156 RAPparams->set(
"compute global constants: temporaries", RAPparams->get(
"compute global constants: temporaries",
false));
157 RAPparams->set(
"compute global constants",
true);
163 if (pL.get<
bool>(
"transpose: use implicit") ==
true) {
166 Ac = MatrixMatrix::Multiply(*P, doTranspose, *AP, !doTranspose, Ac, GetOStream(
Statistics2),
167 doFillComplete, doOptimizeStorage, labelstr + std::string(
"MueLu::R*(AP)-implicit-") + levelstr.str(), RAPparams);
170 RCP<Matrix> R = Get<RCP<Matrix> >(coarseLevel,
"R");
174 Ac = MatrixMatrix::Multiply(*R, !doTranspose, *AP, !doTranspose, Ac, GetOStream(
Statistics2),
175 doFillComplete, doOptimizeStorage, labelstr + std::string(
"MueLu::R*(AP)-explicit-") + levelstr.str(), RAPparams);
178 Teuchos::ArrayView<const double> relativeFloor = pL.get<Teuchos::Array<double> >(
"rap: relative diagonal floor")();
179 if (relativeFloor.size() > 0) {
180 Xpetra::MatrixUtils<SC, LO, GO, NO>::RelativeDiagonalBoost(Ac, relativeFloor, GetOStream(
Statistics2));
183 bool repairZeroDiagonals = pL.get<
bool>(
"RepairMainDiagonal") || pL.get<
bool>(
"rap: fix zero diagonals");
184 bool checkAc = pL.get<
bool>(
"CheckMainDiagonal") || pL.get<
bool>(
"rap: fix zero diagonals");
186 if (checkAc || repairZeroDiagonals) {
187 using magnitudeType =
typename Teuchos::ScalarTraits<Scalar>::magnitudeType;
188 magnitudeType threshold;
189 if (pL.isType<magnitudeType>(
"rap: fix zero diagonals threshold"))
190 threshold = pL.get<magnitudeType>(
"rap: fix zero diagonals threshold");
192 threshold = Teuchos::as<magnitudeType>(pL.get<
double>(
"rap: fix zero diagonals threshold"));
193 Scalar replacement = Teuchos::as<Scalar>(pL.get<
double>(
"rap: fix zero diagonals replacement"));
194 Xpetra::MatrixUtils<SC, LO, GO, NO>::CheckRepairMainDiagonal(Ac, repairZeroDiagonals, GetOStream(
Warnings1), threshold, replacement);
198 RCP<ParameterList> params = rcp(
new ParameterList());
200 params->set(
"printLoadBalancingInfo",
true);
201 params->set(
"printCommInfo",
true);
206 std::ostringstream oss;
207 oss <<
"A_" << coarseLevel.GetLevelID();
208 Ac->setObjectLabel(oss.str());
210 Set(coarseLevel,
"A", Ac);
213 APparams->set(
"graph", AP);
214 Set(coarseLevel,
"AP reuse data", APparams);
217 RAPparams->set(
"graph", Ac);
218 Set(coarseLevel,
"RAP reuse data", RAPparams);
221 RCP<ParameterList> RAPparams = rcp(
new ParameterList);
222 if (pL.isSublist(
"matrixmatrix: kernel params"))
223 RAPparams->sublist(
"matrixmatrix: kernel params") = pL.sublist(
"matrixmatrix: kernel params");
225 if (coarseLevel.IsAvailable(
"RAP reuse data",
this)) {
226 GetOStream(
static_cast<MsgType>(
Runtime0 |
Test)) <<
"Reusing previous RAP data" << std::endl;
228 RAPparams = coarseLevel.Get<RCP<ParameterList> >(
"RAP reuse data",
this);
230 if (RAPparams->isParameter(
"graph"))
231 Ac = RAPparams->get<RCP<Matrix> >(
"graph");
235 Ac->SetMaxEigenvalueEstimate(-Teuchos::ScalarTraits<SC>::one());
239 RAPparams->set(
"compute global constants: temporaries", RAPparams->get(
"compute global constants: temporaries",
false));
240 RAPparams->set(
"compute global constants",
true);
242 if (pL.get<
bool>(
"transpose: use implicit") ==
true) {
243 Ac = MatrixFactory::Build(P->getDomainMap(), Teuchos::as<LO>(0));
247 Xpetra::TripleMatrixMultiply<SC, LO, GO, NO>::
248 MultiplyRAP(*P, doTranspose, *A, !doTranspose, *P, !doTranspose, *Ac, doFillComplete,
249 doOptimizeStorage, labelstr + std::string(
"MueLu::R*A*P-implicit-") + levelstr.str(),
252 RCP<Matrix> R = Get<RCP<Matrix> >(coarseLevel,
"R");
253 Ac = MatrixFactory::Build(R->getRowMap(), Teuchos::as<LO>(0));
257 Xpetra::TripleMatrixMultiply<SC, LO, GO, NO>::
258 MultiplyRAP(*R, !doTranspose, *A, !doTranspose, *P, !doTranspose, *Ac, doFillComplete,
259 doOptimizeStorage, labelstr + std::string(
"MueLu::R*A*P-explicit-") + levelstr.str(),
263 Teuchos::ArrayView<const double> relativeFloor = pL.get<Teuchos::Array<double> >(
"rap: relative diagonal floor")();
264 if (relativeFloor.size() > 0) {
265 Xpetra::MatrixUtils<SC, LO, GO, NO>::RelativeDiagonalBoost(Ac, relativeFloor, GetOStream(
Statistics2));
268 bool repairZeroDiagonals = pL.get<
bool>(
"RepairMainDiagonal") || pL.get<
bool>(
"rap: fix zero diagonals");
269 bool checkAc = pL.get<
bool>(
"CheckMainDiagonal") || pL.get<
bool>(
"rap: fix zero diagonals");
271 if (checkAc || repairZeroDiagonals) {
272 using magnitudeType =
typename Teuchos::ScalarTraits<Scalar>::magnitudeType;
273 magnitudeType threshold;
274 if (pL.isType<magnitudeType>(
"rap: fix zero diagonals threshold"))
275 threshold = pL.get<magnitudeType>(
"rap: fix zero diagonals threshold");
277 threshold = Teuchos::as<magnitudeType>(pL.get<
double>(
"rap: fix zero diagonals threshold"));
278 Scalar replacement = Teuchos::as<Scalar>(pL.get<
double>(
"rap: fix zero diagonals replacement"));
279 Xpetra::MatrixUtils<SC, LO, GO, NO>::CheckRepairMainDiagonal(Ac, repairZeroDiagonals, GetOStream(
Warnings1), threshold, replacement);
283 RCP<ParameterList> params = rcp(
new ParameterList());
285 params->set(
"printLoadBalancingInfo",
true);
286 params->set(
"printCommInfo",
true);
291 std::ostringstream oss;
292 oss <<
"A_" << coarseLevel.GetLevelID();
293 Ac->setObjectLabel(oss.str());
295 Set(coarseLevel,
"A", Ac);
298 RAPparams->set(
"graph", Ac);
299 Set(coarseLevel,
"RAP reuse data", RAPparams);
304#ifdef HAVE_MUELU_DEBUG
305 MatrixUtils::checkLocalRowMapMatchesColMap(*Ac);
308 if (transferFacts_.begin() != transferFacts_.end()) {
312 for (std::vector<RCP<const FactoryBase> >::const_iterator it = transferFacts_.begin(); it != transferFacts_.end(); ++it) {
313 RCP<const FactoryBase> fac = *it;
314 GetOStream(
Runtime0) <<
"RAPFactory: call transfer factory: " << fac->description() << std::endl;
315 fac->CallBuild(coarseLevel);