46 #ifndef MUELU_RAPFACTORY_DEF_HPP
47 #define MUELU_RAPFACTORY_DEF_HPP
64 #include "MueLu_PerfUtils.hpp"
69 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
71 : hasDeclaredInput_(false) {}
73 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
77 #define SET_VALID_ENTRY(name) validParamList->setEntry(name, MasterList::getEntry(name))
84 #undef SET_VALID_ENTRY
85 validParamList->
set<
RCP<const FactoryBase> >(
"A", null,
"Generating factory of the matrix A used during the prolongator smoothing process");
89 validParamList->
set<
bool>(
"CheckMainDiagonal",
false,
"Check main diagonal for zeros");
90 validParamList->
set<
bool>(
"RepairMainDiagonal",
false,
"Repair zeros on main diagonal");
95 validParamList->
set<
ParameterList>(
"matrixmatrix: kernel params", norecurse,
"MatrixMatrix kernel parameters");
97 return validParamList;
100 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
103 if (pL.
get<
bool>(
"transpose: use implicit") ==
false)
104 Input(coarseLevel,
"R");
106 Input(fineLevel,
"A");
107 Input(coarseLevel,
"P");
110 for (std::vector<
RCP<const FactoryBase> >::const_iterator it = transferFacts_.begin(); it != transferFacts_.end(); ++it)
111 (*it)->CallDeclareInput(coarseLevel);
113 hasDeclaredInput_ =
true;
116 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
118 const bool doTranspose =
true;
119 const bool doFillComplete =
true;
120 const bool doOptimizeStorage =
true;
124 std::ostringstream levelstr;
129 "MueLu::RAPFactory::Build(): CallDeclareInput has not been called before Build!");
133 RCP<Matrix> P = Get<RCP<Matrix> >(coarseLevel,
"P"), AP;
136 if (P == Teuchos::null) {
138 Set(coarseLevel,
"A", Ac);
144 #ifdef KOKKOS_ENABLE_CUDA
145 (
typeid(
Node).name() ==
typeid(Tpetra::KokkosCompat::KokkosCudaWrapperNode).name()) ||
147 #ifdef KOKKOS_ENABLE_HIP
148 (
typeid(
Node).name() ==
typeid(Tpetra::KokkosCompat::KokkosHIPWrapperNode).name()) ||
150 #ifdef KOKKOS_ENABLE_SYCL
151 (
typeid(
Node).name() ==
typeid(Tpetra::KokkosCompat::KokkosSYCLWrapperNode).name()) ||
155 if (pL.
get<
bool>(
"rap: triple product") ==
false || isEpetra || isGPU) {
156 if (pL.
get<
bool>(
"rap: triple product") && isEpetra)
157 GetOStream(
Warnings1) <<
"Switching from triple product to R x (A x P) since triple product has not been implemented for Epetra.\n";
158 #if defined(KOKKOS_ENABLE_CUDA) || defined(KOKKOS_ENABLE_HIP) || defined(KOKKOS_ENABLE_SYCL)
159 if (pL.
get<
bool>(
"rap: triple product") && isGPU)
160 GetOStream(
Warnings1) <<
"Switching from triple product to R x (A x P) since triple product has not been implemented for "
161 << Node::execution_space::name() << std::endl;
166 if (pL.
isSublist(
"matrixmatrix: kernel params"))
170 APparams->
set(
"compute global constants: temporaries", APparams->
get(
"compute global constants: temporaries",
false));
171 APparams->
set(
"compute global constants", APparams->
get(
"compute global constants",
false));
173 if (coarseLevel.IsAvailable(
"AP reuse data",
this)) {
174 GetOStream(static_cast<MsgType>(
Runtime0 |
Test)) <<
"Reusing previous AP data" << std::endl;
185 AP = MatrixMatrix::Multiply(*A, !doTranspose, *P, !doTranspose, AP, GetOStream(
Statistics2),
186 doFillComplete, doOptimizeStorage, labelstr + std::string(
"MueLu::A*P-") + levelstr.str(), APparams);
191 if (pL.
isSublist(
"matrixmatrix: kernel params"))
194 if (coarseLevel.IsAvailable(
"RAP reuse data",
this)) {
195 GetOStream(static_cast<MsgType>(
Runtime0 |
Test)) <<
"Reusing previous RAP data" << std::endl;
208 RAPparams->
set(
"compute global constants: temporaries", RAPparams->
get(
"compute global constants: temporaries",
false));
209 RAPparams->
set(
"compute global constants",
true);
215 if (pL.
get<
bool>(
"transpose: use implicit") ==
true) {
218 Ac = MatrixMatrix::Multiply(*P, doTranspose, *AP, !doTranspose, Ac, GetOStream(
Statistics2),
219 doFillComplete, doOptimizeStorage, labelstr + std::string(
"MueLu::R*(AP)-implicit-") + levelstr.str(), RAPparams);
222 RCP<Matrix> R = Get<RCP<Matrix> >(coarseLevel,
"R");
226 Ac = MatrixMatrix::Multiply(*R, !doTranspose, *AP, !doTranspose, Ac, GetOStream(
Statistics2),
227 doFillComplete, doOptimizeStorage, labelstr + std::string(
"MueLu::R*(AP)-explicit-") + levelstr.str(), RAPparams);
231 if (relativeFloor.
size() > 0) {
235 bool repairZeroDiagonals = pL.
get<
bool>(
"RepairMainDiagonal") || pL.
get<
bool>(
"rap: fix zero diagonals");
236 bool checkAc = pL.
get<
bool>(
"CheckMainDiagonal") || pL.
get<
bool>(
"rap: fix zero diagonals");
238 if (checkAc || repairZeroDiagonals) {
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"));
252 params->
set(
"printLoadBalancingInfo",
true);
253 params->
set(
"printCommInfo",
true);
258 std::ostringstream oss;
259 oss <<
"A_" << coarseLevel.GetLevelID();
260 Ac->setObjectLabel(oss.str());
262 Set(coarseLevel,
"A", Ac);
265 APparams->
set(
"graph", AP);
266 Set(coarseLevel,
"AP reuse data", APparams);
269 RAPparams->
set(
"graph", Ac);
270 Set(coarseLevel,
"RAP reuse data", RAPparams);
274 if (pL.
isSublist(
"matrixmatrix: kernel params"))
275 RAPparams->
sublist(
"matrixmatrix: kernel params") = pL.
sublist(
"matrixmatrix: kernel params");
277 if (coarseLevel.IsAvailable(
"RAP reuse data",
this)) {
278 GetOStream(static_cast<MsgType>(
Runtime0 |
Test)) <<
"Reusing previous RAP data" << std::endl;
291 RAPparams->
set(
"compute global constants: temporaries", RAPparams->
get(
"compute global constants: temporaries",
false));
292 RAPparams->
set(
"compute global constants",
true);
294 if (pL.
get<
bool>(
"transpose: use implicit") ==
true) {
295 Ac = MatrixFactory::Build(P->getDomainMap(), Teuchos::as<LO>(0));
300 MultiplyRAP(*P, doTranspose, *A, !doTranspose, *P, !doTranspose, *Ac, doFillComplete,
301 doOptimizeStorage, labelstr + std::string(
"MueLu::R*A*P-implicit-") + levelstr.str(),
304 RCP<Matrix> R = Get<RCP<Matrix> >(coarseLevel,
"R");
305 Ac = MatrixFactory::Build(R->getRowMap(), Teuchos::as<LO>(0));
310 MultiplyRAP(*R, !doTranspose, *A, !doTranspose, *P, !doTranspose, *Ac, doFillComplete,
311 doOptimizeStorage, labelstr + std::string(
"MueLu::R*A*P-explicit-") + levelstr.str(),
316 if (relativeFloor.
size() > 0) {
320 bool repairZeroDiagonals = pL.
get<
bool>(
"RepairMainDiagonal") || pL.
get<
bool>(
"rap: fix zero diagonals");
321 bool checkAc = pL.
get<
bool>(
"CheckMainDiagonal") || pL.
get<
bool>(
"rap: fix zero diagonals");
323 if (checkAc || repairZeroDiagonals) {
325 magnitudeType threshold;
326 if (pL.
isType<magnitudeType>(
"rap: fix zero diagonals threshold"))
327 threshold = pL.
get<magnitudeType>(
"rap: fix zero diagonals threshold");
329 threshold = Teuchos::as<magnitudeType>(pL.
get<
double>(
"rap: fix zero diagonals threshold"));
330 Scalar replacement = Teuchos::as<Scalar>(pL.
get<
double>(
"rap: fix zero diagonals replacement"));
337 params->
set(
"printLoadBalancingInfo",
true);
338 params->
set(
"printCommInfo",
true);
343 std::ostringstream oss;
344 oss <<
"A_" << coarseLevel.GetLevelID();
345 Ac->setObjectLabel(oss.str());
347 Set(coarseLevel,
"A", Ac);
350 RAPparams->
set(
"graph", Ac);
351 Set(coarseLevel,
"RAP reuse data", RAPparams);
356 #ifdef HAVE_MUELU_DEBUG
357 MatrixUtils::checkLocalRowMapMatchesColMap(*Ac);
358 #endif // HAVE_MUELU_DEBUG
360 if (transferFacts_.begin() != transferFacts_.end()) {
364 for (std::vector<
RCP<const FactoryBase> >::const_iterator it = transferFacts_.begin(); it != transferFacts_.end(); ++it) {
366 GetOStream(
Runtime0) <<
"RAPFactory: call transfer factory: " << fac->
description() << std::endl;
401 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
405 "MueLu::RAPFactory::AddTransferFactory: Transfer factory is not derived from TwoLevelFactoryBase. "
406 "This is very strange. (Note: you can remove this exception if there's a good reason for)");
408 transferFacts_.push_back(factory);
413 #define MUELU_RAPFACTORY_SHORT
414 #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)
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
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.
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.