10 #ifndef MUELU_RAPFACTORY_DEF_HPP
11 #define MUELU_RAPFACTORY_DEF_HPP
25 #include "MueLu_PerfUtils.hpp"
29 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
31 : hasDeclaredInput_(false) {}
33 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
36 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
40 #define SET_VALID_ENTRY(name) validParamList->setEntry(name, MasterList::getEntry(name))
47 #undef SET_VALID_ENTRY
48 validParamList->
set<
RCP<const FactoryBase> >(
"A", null,
"Generating factory of the matrix A used during the prolongator smoothing process");
52 validParamList->
set<
bool>(
"CheckMainDiagonal",
false,
"Check main diagonal for zeros");
53 validParamList->
set<
bool>(
"RepairMainDiagonal",
false,
"Repair zeros on main diagonal");
58 validParamList->
set<
ParameterList>(
"matrixmatrix: kernel params", norecurse,
"MatrixMatrix kernel parameters");
60 return validParamList;
63 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
66 if (pL.
get<
bool>(
"transpose: use implicit") ==
false)
67 Input(coarseLevel,
"R");
69 Input(fineLevel,
"A");
70 Input(coarseLevel,
"P");
73 for (std::vector<
RCP<const FactoryBase> >::const_iterator it = transferFacts_.begin(); it != transferFacts_.end(); ++it)
74 (*it)->CallDeclareInput(coarseLevel);
76 hasDeclaredInput_ =
true;
79 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
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!");
96 RCP<Matrix> P = Get<RCP<Matrix> >(coarseLevel,
"P"), AP;
99 if (P == Teuchos::null) {
101 Set(coarseLevel,
"A", Ac);
107 #ifdef KOKKOS_ENABLE_CUDA
108 (
typeid(
Node).name() ==
typeid(Tpetra::KokkosCompat::KokkosCudaWrapperNode).name()) ||
110 #ifdef KOKKOS_ENABLE_HIP
111 (
typeid(
Node).name() ==
typeid(Tpetra::KokkosCompat::KokkosHIPWrapperNode).name()) ||
113 #ifdef KOKKOS_ENABLE_SYCL
114 (
typeid(
Node).name() ==
typeid(Tpetra::KokkosCompat::KokkosSYCLWrapperNode).name()) ||
118 if (pL.
get<
bool>(
"rap: triple product") ==
false || isEpetra || isGPU) {
119 if (pL.
get<
bool>(
"rap: triple product") && isEpetra)
120 GetOStream(
Warnings1) <<
"Switching from triple product to R x (A x P) since triple product has not been implemented for Epetra.\n";
121 #if defined(KOKKOS_ENABLE_CUDA) || defined(KOKKOS_ENABLE_HIP) || defined(KOKKOS_ENABLE_SYCL)
122 if (pL.
get<
bool>(
"rap: triple product") && isGPU)
123 GetOStream(
Warnings1) <<
"Switching from triple product to R x (A x P) since triple product has not been implemented for "
124 << Node::execution_space::name() << std::endl;
129 if (pL.
isSublist(
"matrixmatrix: kernel params"))
133 APparams->
set(
"compute global constants: temporaries", APparams->
get(
"compute global constants: temporaries",
false));
134 APparams->
set(
"compute global constants", APparams->
get(
"compute global constants",
false));
136 if (coarseLevel.IsAvailable(
"AP reuse data",
this)) {
137 GetOStream(static_cast<MsgType>(
Runtime0 |
Test)) <<
"Reusing previous AP data" << std::endl;
148 AP = MatrixMatrix::Multiply(*A, !doTranspose, *P, !doTranspose, AP, GetOStream(
Statistics2),
149 doFillComplete, doOptimizeStorage, labelstr + std::string(
"MueLu::A*P-") + levelstr.str(), APparams);
154 if (pL.
isSublist(
"matrixmatrix: kernel params"))
157 if (coarseLevel.IsAvailable(
"RAP reuse data",
this)) {
158 GetOStream(static_cast<MsgType>(
Runtime0 |
Test)) <<
"Reusing previous RAP data" << std::endl;
171 RAPparams->
set(
"compute global constants: temporaries", RAPparams->
get(
"compute global constants: temporaries",
false));
172 RAPparams->
set(
"compute global constants",
true);
178 if (pL.
get<
bool>(
"transpose: use implicit") ==
true) {
181 Ac = MatrixMatrix::Multiply(*P, doTranspose, *AP, !doTranspose, Ac, GetOStream(
Statistics2),
182 doFillComplete, doOptimizeStorage, labelstr + std::string(
"MueLu::R*(AP)-implicit-") + levelstr.str(), RAPparams);
185 RCP<Matrix> R = Get<RCP<Matrix> >(coarseLevel,
"R");
189 Ac = MatrixMatrix::Multiply(*R, !doTranspose, *AP, !doTranspose, Ac, GetOStream(
Statistics2),
190 doFillComplete, doOptimizeStorage, labelstr + std::string(
"MueLu::R*(AP)-explicit-") + levelstr.str(), RAPparams);
194 if (relativeFloor.
size() > 0) {
198 bool repairZeroDiagonals = pL.
get<
bool>(
"RepairMainDiagonal") || pL.
get<
bool>(
"rap: fix zero diagonals");
199 bool checkAc = pL.
get<
bool>(
"CheckMainDiagonal") || pL.
get<
bool>(
"rap: fix zero diagonals");
201 if (checkAc || repairZeroDiagonals) {
203 magnitudeType threshold;
204 if (pL.
isType<magnitudeType>(
"rap: fix zero diagonals threshold"))
205 threshold = pL.
get<magnitudeType>(
"rap: fix zero diagonals threshold");
207 threshold = Teuchos::as<magnitudeType>(pL.
get<
double>(
"rap: fix zero diagonals threshold"));
208 Scalar replacement = Teuchos::as<Scalar>(pL.
get<
double>(
"rap: fix zero diagonals replacement"));
215 params->
set(
"printLoadBalancingInfo",
true);
216 params->
set(
"printCommInfo",
true);
221 std::ostringstream oss;
222 oss <<
"A_" << coarseLevel.GetLevelID();
223 Ac->setObjectLabel(oss.str());
225 Set(coarseLevel,
"A", Ac);
228 APparams->
set(
"graph", AP);
229 Set(coarseLevel,
"AP reuse data", APparams);
232 RAPparams->
set(
"graph", Ac);
233 Set(coarseLevel,
"RAP reuse data", RAPparams);
237 if (pL.
isSublist(
"matrixmatrix: kernel params"))
238 RAPparams->
sublist(
"matrixmatrix: kernel params") = pL.
sublist(
"matrixmatrix: kernel params");
240 if (coarseLevel.IsAvailable(
"RAP reuse data",
this)) {
241 GetOStream(static_cast<MsgType>(
Runtime0 |
Test)) <<
"Reusing previous RAP data" << std::endl;
254 RAPparams->
set(
"compute global constants: temporaries", RAPparams->
get(
"compute global constants: temporaries",
false));
255 RAPparams->
set(
"compute global constants",
true);
257 if (pL.
get<
bool>(
"transpose: use implicit") ==
true) {
258 Ac = MatrixFactory::Build(P->getDomainMap(), Teuchos::as<LO>(0));
263 MultiplyRAP(*P, doTranspose, *A, !doTranspose, *P, !doTranspose, *Ac, doFillComplete,
264 doOptimizeStorage, labelstr + std::string(
"MueLu::R*A*P-implicit-") + levelstr.str(),
267 RCP<Matrix> R = Get<RCP<Matrix> >(coarseLevel,
"R");
268 Ac = MatrixFactory::Build(R->getRowMap(), Teuchos::as<LO>(0));
273 MultiplyRAP(*R, !doTranspose, *A, !doTranspose, *P, !doTranspose, *Ac, doFillComplete,
274 doOptimizeStorage, labelstr + std::string(
"MueLu::R*A*P-explicit-") + levelstr.str(),
279 if (relativeFloor.
size() > 0) {
283 bool repairZeroDiagonals = pL.
get<
bool>(
"RepairMainDiagonal") || pL.
get<
bool>(
"rap: fix zero diagonals");
284 bool checkAc = pL.
get<
bool>(
"CheckMainDiagonal") || pL.
get<
bool>(
"rap: fix zero diagonals");
286 if (checkAc || repairZeroDiagonals) {
288 magnitudeType threshold;
289 if (pL.
isType<magnitudeType>(
"rap: fix zero diagonals threshold"))
290 threshold = pL.
get<magnitudeType>(
"rap: fix zero diagonals threshold");
292 threshold = Teuchos::as<magnitudeType>(pL.
get<
double>(
"rap: fix zero diagonals threshold"));
293 Scalar replacement = Teuchos::as<Scalar>(pL.
get<
double>(
"rap: fix zero diagonals replacement"));
300 params->
set(
"printLoadBalancingInfo",
true);
301 params->
set(
"printCommInfo",
true);
306 std::ostringstream oss;
307 oss <<
"A_" << coarseLevel.GetLevelID();
308 Ac->setObjectLabel(oss.str());
310 Set(coarseLevel,
"A", Ac);
313 RAPparams->
set(
"graph", Ac);
314 Set(coarseLevel,
"RAP reuse data", RAPparams);
319 #ifdef HAVE_MUELU_DEBUG
320 MatrixUtils::checkLocalRowMapMatchesColMap(*Ac);
321 #endif // HAVE_MUELU_DEBUG
323 if (transferFacts_.begin() != transferFacts_.end()) {
327 for (std::vector<
RCP<const FactoryBase> >::const_iterator it = transferFacts_.begin(); it != transferFacts_.end(); ++it) {
329 GetOStream(
Runtime0) <<
"RAPFactory: call transfer factory: " << fac->
description() << std::endl;
364 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
368 "MueLu::RAPFactory::AddTransferFactory: Transfer factory is not derived from TwoLevelFactoryBase. "
369 "This is very strange. (Note: you can remove this exception if there's a good reason for)");
371 transferFacts_.push_back(factory);
376 #define MUELU_RAPFACTORY_SHORT
377 #endif // MUELU_RAPFACTORY_DEF_HPP
#define SET_VALID_ENTRY(name)
Exception indicating invalid cast attempted.
virtual std::string getObjectLabel() const
static void RelativeDiagonalBoost(RCP< Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &A, const Teuchos::ArrayView< const double > &relativeThreshold, Teuchos::FancyOStream &fos)
virtual void CallBuild(Level &requestedLevel) const =0
ParameterList & disableRecursiveValidation()
void Release(const FactoryBase &factory)
Decrement the storage counter for all the inputs of a factory.
T & get(const std::string &name, T def_value)
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)
Timer to be used in factories. Similar to Monitor but with additional timers.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
RCP< const ParameterList > GetValidParameterList() const
Return a const parameter list of valid parameters that setParameterList() will accept.
One-liner description of what is happening.
void AddTransferFactory(const RCP< const FactoryBase > &factory)
Add transfer factory in the end of list of transfer factories in RepartitionAcFactory.
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
static void CheckRepairMainDiagonal(RCP< Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node >> &Ac, bool const &repairZeroDiagonals, Teuchos::FancyOStream &fos, const typename Teuchos::ScalarTraits< Scalar >::magnitudeType threshold=Teuchos::ScalarTraits< typename Teuchos::ScalarTraits< Scalar >::magnitudeType >::zero())
Print even more statistics.
bool isParameter(const std::string &name) const
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
MueLu::DefaultScalar Scalar
Class that holds all level-specific information.
bool isSublist(const std::string &name) const
Timer to be used in factories. Similar to SubMonitor but adds a timer level by level.
static std::string PrintMatrixInfo(const Matrix &A, const std::string &msgTag, RCP< const Teuchos::ParameterList > params=Teuchos::null)
bool isType(const std::string &name) const
ParameterList & sublist(const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
int GetLevelID() const
Return level number.
Exception throws to report errors in the internal logical of the program.
virtual std::string description() const
Return a simple one-line description of this object.
void Build(Level &fineLevel, Level &coarseLevel) const
Build an object with this factory.
void DeclareInput(Level &fineLevel, Level &coarseLevel) const
Input.