From a4fd7ca5bb1b014349687c9fc0003709cdab1bfe Mon Sep 17 00:00:00 2001 From: Matthias Mayr Date: Wed, 6 Oct 2021 22:48:33 +0200 Subject: [PATCH 01/10] MueLu: move decision of residual printout to func --- .../muelu/src/MueCentral/MueLu_Hierarchy_decl.hpp | 3 +++ .../muelu/src/MueCentral/MueLu_Hierarchy_def.hpp | 13 +++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/muelu/src/MueCentral/MueLu_Hierarchy_decl.hpp b/packages/muelu/src/MueCentral/MueLu_Hierarchy_decl.hpp index 44e86eede79d..2d52ab965fb1 100644 --- a/packages/muelu/src/MueCentral/MueLu_Hierarchy_decl.hpp +++ b/packages/muelu/src/MueCentral/MueLu_Hierarchy_decl.hpp @@ -355,6 +355,9 @@ namespace MueLu { //! Copy constructor is not implemented. Hierarchy(const Hierarchy &h); + //! Decide if the residual needs to be computed and printed to screen + bool IsResidualHistoryNecessary(const LO startLevel, const ConvData& conv) const; + //! Container for Level objects Array > Levels_; diff --git a/packages/muelu/src/MueCentral/MueLu_Hierarchy_def.hpp b/packages/muelu/src/MueCentral/MueLu_Hierarchy_def.hpp index 95d43e03dd03..0521b318d684 100644 --- a/packages/muelu/src/MueCentral/MueLu_Hierarchy_def.hpp +++ b/packages/muelu/src/MueCentral/MueLu_Hierarchy_def.hpp @@ -920,8 +920,7 @@ namespace MueLu { typedef Teuchos::ScalarTraits STM; MagnitudeType prevNorm = STM::one(), curNorm = STM::one(); rate_ = 1.0; - if (startLevel == 0 && !isPreconditioner_ && - (IsPrint(Statistics1) || tol > 0)) { + if (IsResidualHistoryNecessary(startLevel, conv)) { // We calculate the residual only if we want to print it out, or if we // want to stop once we achive the tolerance Teuchos::Array rn; @@ -1136,8 +1135,7 @@ namespace MueLu { } zeroGuess = false; - if (startLevel == 0 && !isPreconditioner_ && - (IsPrint(Statistics1) || tol > 0)) { + if (IsResidualHistoryNecessary(startLevel, conv)) { // We calculate the residual only if we want to print it out, or if we // want to stop once we achive the tolerance Teuchos::Array rn; @@ -1609,6 +1607,13 @@ void Hierarchy::DeleteLevelMultiVecto } +template +bool Hierarchy::IsResidualHistoryNecessary( + const LO startLevel, const ConvData& conv) const +{ + return (startLevel == 0 && !isPreconditioner_ && (IsPrint(Statistics1) || conv.tol_ > 0)); +} + } //namespace MueLu #endif // MUELU_HIERARCHY_DEF_HPP From 974f38b83000fce02cf96e25abc1dc8723e15c05 Mon Sep 17 00:00:00 2001 From: Matthias Mayr Date: Thu, 7 Oct 2021 08:59:01 +0200 Subject: [PATCH 02/10] MueLu: refactor printout of residual history Extract decision about residual calculation and the printing of the residual into functions to be reused inside Hierarchy::Iterate(). --- .../src/MueCentral/MueLu_Hierarchy_decl.hpp | 18 +++- .../src/MueCentral/MueLu_Hierarchy_def.hpp | 100 ++++++++++-------- 2 files changed, 72 insertions(+), 46 deletions(-) diff --git a/packages/muelu/src/MueCentral/MueLu_Hierarchy_decl.hpp b/packages/muelu/src/MueCentral/MueLu_Hierarchy_decl.hpp index 2d52ab965fb1..8aa9d376debf 100644 --- a/packages/muelu/src/MueCentral/MueLu_Hierarchy_decl.hpp +++ b/packages/muelu/src/MueCentral/MueLu_Hierarchy_decl.hpp @@ -355,8 +355,22 @@ namespace MueLu { //! Copy constructor is not implemented. Hierarchy(const Hierarchy &h); - //! Decide if the residual needs to be computed and printed to screen - bool IsResidualHistoryNecessary(const LO startLevel, const ConvData& conv) const; + //! Decide if the residual needs to be computed + bool IsCalculationOfResidualRequired(const LO startLevel, const ConvData& conv) const; + + /*! + \brief Decide if the mulitgrid iteration is converged + + We judge convergence by comparing the current \c residualNorm + to the user given \c convergenceTolerance and then return the + appropriate \c ReturnType + */ + ReturnType IsConverged(const Teuchos::Array& residualNorm, + const Scalar convergenceTolerance) const; + + //! Print \c residualNorm for this \c iteration to the screen + void PrintResidualHistory(const LO iteration, + const Teuchos::Array& residualNorm) const; //! Container for Level objects Array > Levels_; diff --git a/packages/muelu/src/MueCentral/MueLu_Hierarchy_def.hpp b/packages/muelu/src/MueCentral/MueLu_Hierarchy_def.hpp index 0521b318d684..4fba0697ee63 100644 --- a/packages/muelu/src/MueCentral/MueLu_Hierarchy_def.hpp +++ b/packages/muelu/src/MueCentral/MueLu_Hierarchy_def.hpp @@ -920,29 +920,16 @@ namespace MueLu { typedef Teuchos::ScalarTraits STM; MagnitudeType prevNorm = STM::one(), curNorm = STM::one(); rate_ = 1.0; - if (IsResidualHistoryNecessary(startLevel, conv)) { - // We calculate the residual only if we want to print it out, or if we - // want to stop once we achive the tolerance - Teuchos::Array rn; - rn = Utilities::ResidualNorm(*A, X, B,*residual_[startLevel]); - - if (tol > 0) { - bool passed = true; - for (LO k = 0; k < rn.size(); k++) - if (rn[k] >= tol) - passed = false; - - if (passed) - return Converged; - } + if (IsCalculationOfResidualRequired(startLevel, conv)) + { + Teuchos::Array residualNorm; + residualNorm = Utilities::ResidualNorm(*A, X, B,*residual_[startLevel]); if (IsPrint(Statistics1)) - GetOStream(Statistics1) << "iter: " - << std::setiosflags(std::ios::left) - << std::setprecision(3) << 0 // iter 0 - << " residual = " - << std::setprecision(10) << rn - << std::endl; + PrintResidualHistory(0, residualNorm); // Pass 0, since this is before first iteration + + ReturnType convergenceStatus = IsConverged(residualNorm, conv.tol_); + if (convergenceStatus == Converged) return convergenceStatus; } SC one = STS::one(), zero = STS::zero(); @@ -1135,33 +1122,21 @@ namespace MueLu { } zeroGuess = false; - if (IsResidualHistoryNecessary(startLevel, conv)) { - // We calculate the residual only if we want to print it out, or if we - // want to stop once we achive the tolerance - Teuchos::Array rn; - rn = Utilities::ResidualNorm(*A, X, B,*residual_[startLevel]); + + if (IsCalculationOfResidualRequired(startLevel, conv)) + { + Teuchos::Array residualNorm; + residualNorm = Utilities::ResidualNorm(*A, X, B,*residual_[startLevel]); prevNorm = curNorm; - curNorm = rn[0]; + curNorm = residualNorm[0]; rate_ = as(curNorm / prevNorm); if (IsPrint(Statistics1)) - GetOStream(Statistics1) << "iter: " - << std::setiosflags(std::ios::left) - << std::setprecision(3) << i - << " residual = " - << std::setprecision(10) << rn - << std::endl; - - if (tol > 0) { - bool passed = true; - for (LO k = 0; k < rn.size(); k++) - if (rn[k] >= tol) - passed = false; - - if (passed) - return Converged; - } + PrintResidualHistory(i, residualNorm); + + ReturnType convergenceStatus = IsConverged(residualNorm, conv.tol_); + if (convergenceStatus == Converged) return convergenceStatus; } } return (tol > 0 ? Unconverged : Undefined); @@ -1608,12 +1583,49 @@ void Hierarchy::DeleteLevelMultiVecto template -bool Hierarchy::IsResidualHistoryNecessary( +bool Hierarchy::IsCalculationOfResidualRequired( const LO startLevel, const ConvData& conv) const { return (startLevel == 0 && !isPreconditioner_ && (IsPrint(Statistics1) || conv.tol_ > 0)); } + +template +ReturnType Hierarchy::IsConverged( + const Teuchos::Array& residualNorm, const Scalar convergenceTolerance) const +{ + ReturnType convergenceStatus = Undefined; + + if (convergenceTolerance > 0) + { + bool passed = true; + for (LO k = 0; k < residualNorm.size(); k++) + if (residualNorm[k] >= convergenceTolerance) + passed = false; + + if (passed) + convergenceStatus = Converged; + else + convergenceStatus = Unconverged; + } + + return convergenceStatus; +} + + +template +void Hierarchy::PrintResidualHistory( + const LO iteration, const Teuchos::Array& residualNorm) const +{ + GetOStream(Statistics1) << "iter: " + << std::setiosflags(std::ios::left) + << std::setprecision(3) << iteration + << " residual = " + << std::setprecision(10) << residualNorm + << std::endl; +} + + } //namespace MueLu #endif // MUELU_HIERARCHY_DEF_HPP From d958dd75f960dfea661798dedbb6fc52599547ca Mon Sep 17 00:00:00 2001 From: Matthias Mayr Date: Fri, 8 Oct 2021 02:36:41 +0200 Subject: [PATCH 03/10] MueLu: update list of possible solver options --- packages/muelu/test/scaling/Driver.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/muelu/test/scaling/Driver.cpp b/packages/muelu/test/scaling/Driver.cpp index e84784bd11fb..678c414148c6 100644 --- a/packages/muelu/test/scaling/Driver.cpp +++ b/packages/muelu/test/scaling/Driver.cpp @@ -219,7 +219,7 @@ int main_(Teuchos::CommandLineProcessor &clp, Xpetra::UnderlyingLib& lib, int ar bool printTimings = true; clp.setOption("timings", "notimings", &printTimings, "print timings to screen"); std::string timingsFormat = "table-fixed"; clp.setOption("time-format", &timingsFormat, "timings format (table-fixed | table-scientific | yaml)"); int writeMatricesOPT = -2; clp.setOption("write", &writeMatricesOPT, "write matrices to file (-1 means all; i>=0 means level i)"); - std::string dsolveType = "belos", solveType; clp.setOption("solver", &dsolveType, "solve type: (none | cg | gmres | standalone | matvec)"); + std::string dsolveType = "belos", solveType; clp.setOption("solver", &dsolveType, "solve type: (none | belos | standalone | matvec)"); std::string belosType = "cg"; clp.setOption("belosType", &belosType, "belos solver type: (Pseudoblock CG | Block CG | Pseudoblock GMRES | Block GMRES | ...) see BelosSolverFactory.hpp for exhaustive list of solvers"); double dtol = 1e-12, tol; clp.setOption("tol", &dtol, "solver convergence tolerance"); bool binaryFormat = false; clp.setOption("binary", "ascii", &binaryFormat, "print timings to screen"); @@ -239,7 +239,7 @@ int main_(Teuchos::CommandLineProcessor &clp, Xpetra::UnderlyingLib& lib, int ar int maxIts = 200; clp.setOption("its", &maxIts, "maximum number of solver iterations"); int numVectors = 1; clp.setOption("multivector", &numVectors, "number of rhs to solve simultaneously"); bool scaleResidualHist = true; clp.setOption("scale", "noscale", &scaleResidualHist, "scaled Krylov residual history"); - bool solvePreconditioned = true; clp.setOption("solve-preconditioned","no-solve-preconditioned", &solvePreconditioned, "use MueLu preconditioner in solve"); + bool solvePreconditioned = true; clp.setOption("solve-preconditioned","no-solve-preconditioned", &solvePreconditioned, "use MueLu preconditioner in solve"); bool useStackedTimer = false; clp.setOption("stacked-timer","no-stacked-timer", &useStackedTimer, "use stacked timer"); #ifdef HAVE_MUELU_TPETRA From db68f1c1586a8b9ac7470d1db843e1173e8f8638 Mon Sep 17 00:00:00 2001 From: Matthias Mayr Date: Fri, 8 Oct 2021 02:41:47 +0200 Subject: [PATCH 04/10] MueLu: horizontal alignment of residual history --- packages/muelu/src/MueCentral/MueLu_Hierarchy_def.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/muelu/src/MueCentral/MueLu_Hierarchy_def.hpp b/packages/muelu/src/MueCentral/MueLu_Hierarchy_def.hpp index 4fba0697ee63..10519d90fd23 100644 --- a/packages/muelu/src/MueCentral/MueLu_Hierarchy_def.hpp +++ b/packages/muelu/src/MueCentral/MueLu_Hierarchy_def.hpp @@ -1619,7 +1619,7 @@ void Hierarchy::PrintResidualHistory( { GetOStream(Statistics1) << "iter: " << std::setiosflags(std::ios::left) - << std::setprecision(3) << iteration + << std::setprecision(3) << std::setw(4) << iteration << " residual = " << std::setprecision(10) << residualNorm << std::endl; From a0e50ceef4f6eae37c3131f5e239522ca454a86a Mon Sep 17 00:00:00 2001 From: Matthias Mayr Date: Fri, 8 Oct 2021 02:54:51 +0200 Subject: [PATCH 05/10] MueLu: refactor residual calc/print into functions Within Hierarchy::Iterate(), there are two places, where we might want to compute thre residual norm and print it to screen. Move the respective code into private functions and reuse it at both occurrences in order to reduce code duplication. --- .../src/MueCentral/MueLu_Hierarchy_decl.hpp | 5 +++ .../src/MueCentral/MueLu_Hierarchy_def.hpp | 44 +++++++++---------- 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/packages/muelu/src/MueCentral/MueLu_Hierarchy_decl.hpp b/packages/muelu/src/MueCentral/MueLu_Hierarchy_decl.hpp index 8aa9d376debf..742306f59f27 100644 --- a/packages/muelu/src/MueCentral/MueLu_Hierarchy_decl.hpp +++ b/packages/muelu/src/MueCentral/MueLu_Hierarchy_decl.hpp @@ -372,6 +372,11 @@ namespace MueLu { void PrintResidualHistory(const LO iteration, const Teuchos::Array& residualNorm) const; + //! Compute the residual norm and print it depending on the verbosity level + ReturnType ComputeResidualAndPrintHistory(const Operator& A, const MultiVector& X, + const MultiVector& B, const LO iteration, + const LO startLevel, const ConvData& conv, MagnitudeType& previousResidualNorm); + //! Container for Level objects Array > Levels_; diff --git a/packages/muelu/src/MueCentral/MueLu_Hierarchy_def.hpp b/packages/muelu/src/MueCentral/MueLu_Hierarchy_def.hpp index 10519d90fd23..4667924ad71a 100644 --- a/packages/muelu/src/MueCentral/MueLu_Hierarchy_def.hpp +++ b/packages/muelu/src/MueCentral/MueLu_Hierarchy_def.hpp @@ -921,16 +921,7 @@ namespace MueLu { MagnitudeType prevNorm = STM::one(), curNorm = STM::one(); rate_ = 1.0; if (IsCalculationOfResidualRequired(startLevel, conv)) - { - Teuchos::Array residualNorm; - residualNorm = Utilities::ResidualNorm(*A, X, B,*residual_[startLevel]); - - if (IsPrint(Statistics1)) - PrintResidualHistory(0, residualNorm); // Pass 0, since this is before first iteration - - ReturnType convergenceStatus = IsConverged(residualNorm, conv.tol_); - if (convergenceStatus == Converged) return convergenceStatus; - } + ComputeResidualAndPrintHistory(*A, X, B, Teuchos::ScalarTraits::zero(), startLevel, conv, prevNorm); SC one = STS::one(), zero = STS::zero(); for (LO i = 1; i <= nIts; i++) { @@ -1124,20 +1115,7 @@ namespace MueLu { if (IsCalculationOfResidualRequired(startLevel, conv)) - { - Teuchos::Array residualNorm; - residualNorm = Utilities::ResidualNorm(*A, X, B,*residual_[startLevel]); - - prevNorm = curNorm; - curNorm = residualNorm[0]; - rate_ = as(curNorm / prevNorm); - - if (IsPrint(Statistics1)) - PrintResidualHistory(i, residualNorm); - - ReturnType convergenceStatus = IsConverged(residualNorm, conv.tol_); - if (convergenceStatus == Converged) return convergenceStatus; - } + ComputeResidualAndPrintHistory(*A, X, B, i, startLevel, conv, prevNorm); } return (tol > 0 ? Unconverged : Undefined); } @@ -1625,6 +1603,24 @@ void Hierarchy::PrintResidualHistory( << std::endl; } +template +ReturnType Hierarchy::ComputeResidualAndPrintHistory( + const Operator& A, const MultiVector& X, const MultiVector& B, const LO iteration, + const LO startLevel, const ConvData& conv, MagnitudeType& previousResidualNorm) +{ + Teuchos::Array residualNorm; + residualNorm = Utilities::ResidualNorm(A, X, B, *residual_[startLevel]); + + const MagnitudeType currentResidualNorm = residualNorm[0]; + rate_ = currentResidualNorm / previousResidualNorm; + previousResidualNorm = currentResidualNorm; + + if (IsPrint(Statistics1)) + PrintResidualHistory(iteration, residualNorm); + + return IsConverged(residualNorm, conv.tol_); +} + } //namespace MueLu From 5b529f33e930472461291f270271e9fd2e5484c3 Mon Sep 17 00:00:00 2001 From: Matthias Mayr Date: Fri, 8 Oct 2021 03:00:46 +0200 Subject: [PATCH 06/10] MueLu: use descriptive variable name --- packages/muelu/src/MueCentral/MueLu_Hierarchy_def.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/muelu/src/MueCentral/MueLu_Hierarchy_def.hpp b/packages/muelu/src/MueCentral/MueLu_Hierarchy_def.hpp index 4667924ad71a..8e227f08ae8e 100644 --- a/packages/muelu/src/MueCentral/MueLu_Hierarchy_def.hpp +++ b/packages/muelu/src/MueCentral/MueLu_Hierarchy_def.hpp @@ -924,7 +924,7 @@ namespace MueLu { ComputeResidualAndPrintHistory(*A, X, B, Teuchos::ScalarTraits::zero(), startLevel, conv, prevNorm); SC one = STS::one(), zero = STS::zero(); - for (LO i = 1; i <= nIts; i++) { + for (LO iteration = 1; iteration <= nIts; iteration++) { #ifdef HAVE_MUELU_DEBUG #if 0 // TODO fix me if (A->getDomainMap()->isCompatible(*(X.getMap())) == false) { @@ -1115,7 +1115,7 @@ namespace MueLu { if (IsCalculationOfResidualRequired(startLevel, conv)) - ComputeResidualAndPrintHistory(*A, X, B, i, startLevel, conv, prevNorm); + ComputeResidualAndPrintHistory(*A, X, B, iteration, startLevel, conv, prevNorm); } return (tol > 0 ? Unconverged : Undefined); } From 54ff93627ef19f14918b2a96d115945afe0de359 Mon Sep 17 00:00:00 2001 From: Matthias Mayr Date: Fri, 8 Oct 2021 03:01:11 +0200 Subject: [PATCH 07/10] MueLu: remove trailing white spaces --- .../muelu/src/MueCentral/MueLu_Hierarchy_def.hpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/muelu/src/MueCentral/MueLu_Hierarchy_def.hpp b/packages/muelu/src/MueCentral/MueLu_Hierarchy_def.hpp index 8e227f08ae8e..ba44cc1be2f9 100644 --- a/packages/muelu/src/MueCentral/MueLu_Hierarchy_def.hpp +++ b/packages/muelu/src/MueCentral/MueLu_Hierarchy_def.hpp @@ -1350,29 +1350,29 @@ namespace MueLu { if (GetProcRankVerbose() != 0) return; #if defined(HAVE_MUELU_BOOST) && defined(HAVE_MUELU_BOOST_FOR_REAL) && defined(BOOST_VERSION) && (BOOST_VERSION >= 104400) - + BoostGraph graph; - + BoostProperties dp; dp.property("label", boost::get(boost::vertex_name, graph)); dp.property("id", boost::get(boost::vertex_index, graph)); dp.property("label", boost::get(boost::edge_name, graph)); dp.property("color", boost::get(boost::edge_color, graph)); - + // create local maps std::map vindices; typedef std::map, std::string> emap; emap edges; - + static int call_id=0; - + RCP A = Levels_[0]->template Get >("A"); int rank = A->getDomainMap()->getComm()->getRank(); - + // printf("[%d] CMS: ----------------------\n",rank); for (int i = currLevel; i <= currLevel+1 && i < GetNumLevels(); i++) { edges.clear(); Levels_[i]->UpdateGraph(vindices, edges, dp, graph); - + for (emap::const_iterator eit = edges.begin(); eit != edges.end(); eit++) { std::pair boost_edge = boost::add_edge(eit->first.first, eit->first.second, graph); // printf("[%d] CMS: Hierarchy, adding edge (%d->%d) %d\n",rank,(int)eit->first.first,(int)eit->first.second,(int)boost_edge.second); @@ -1385,7 +1385,7 @@ namespace MueLu { boost::put("color", dp, boost_edge.first, std::string("blue")); } } - + std::ofstream out(dumpFile_.c_str()+std::string("_")+std::to_string(currLevel)+std::string("_")+std::to_string(call_id)+std::string("_")+ std::to_string(rank) + std::string(".dot")); boost::write_graphviz_dp(out, graph, dp, std::string("id")); out.close(); From 2552c1ec6ce4b9ee0040a55c83894299a2ade703 Mon Sep 17 00:00:00 2001 From: Matthias Mayr Date: Fri, 8 Oct 2021 21:02:50 +0200 Subject: [PATCH 08/10] MueLu: fix typo --- packages/muelu/src/MueCentral/MueLu_Hierarchy_decl.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/muelu/src/MueCentral/MueLu_Hierarchy_decl.hpp b/packages/muelu/src/MueCentral/MueLu_Hierarchy_decl.hpp index 742306f59f27..4638a8471572 100644 --- a/packages/muelu/src/MueCentral/MueLu_Hierarchy_decl.hpp +++ b/packages/muelu/src/MueCentral/MueLu_Hierarchy_decl.hpp @@ -359,7 +359,7 @@ namespace MueLu { bool IsCalculationOfResidualRequired(const LO startLevel, const ConvData& conv) const; /*! - \brief Decide if the mulitgrid iteration is converged + \brief Decide if the multigrid iteration is converged We judge convergence by comparing the current \c residualNorm to the user given \c convergenceTolerance and then return the From ffaeb3f5d29f49cc04caf143577c741835e9d185 Mon Sep 17 00:00:00 2001 From: Matthias Mayr Date: Fri, 8 Oct 2021 21:03:54 +0200 Subject: [PATCH 09/10] MueLu: class enum to inndicate convergence status The hierharchy indicates the convergence of its Iterate() routine via a enum. This enum is now changed to be a scoped enum and it has been given a more descriptive name (ReturnType --> ConvergenceStatus). --- .../src/MueCentral/MueLu_Hierarchy_decl.hpp | 10 +++++----- .../src/MueCentral/MueLu_Hierarchy_def.hpp | 20 +++++++++---------- .../muelu/test/convergence/Convergence.cpp | 10 +++++----- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/packages/muelu/src/MueCentral/MueLu_Hierarchy_decl.hpp b/packages/muelu/src/MueCentral/MueLu_Hierarchy_decl.hpp index 4638a8471572..e36a13f6d63c 100644 --- a/packages/muelu/src/MueCentral/MueLu_Hierarchy_decl.hpp +++ b/packages/muelu/src/MueCentral/MueLu_Hierarchy_decl.hpp @@ -80,7 +80,7 @@ namespace MueLu { - enum ReturnType { + enum class ConvergenceStatus { Converged, Unconverged, Undefined @@ -271,7 +271,7 @@ namespace MueLu { @param InitialGuessIsZero Indicates whether the initial guess is zero @param startLevel index of starting level to build multigrid hierarchy (default = 0) */ - ReturnType Iterate(const MultiVector& B, MultiVector& X, ConvData conv = ConvData(), + ConvergenceStatus Iterate(const MultiVector& B, MultiVector& X, ConvData conv = ConvData(), bool InitialGuessIsZero = false, LO startLevel = 0); /*! @@ -363,9 +363,9 @@ namespace MueLu { We judge convergence by comparing the current \c residualNorm to the user given \c convergenceTolerance and then return the - appropriate \c ReturnType + appropriate \c ConvergenceStatus */ - ReturnType IsConverged(const Teuchos::Array& residualNorm, + ConvergenceStatus IsConverged(const Teuchos::Array& residualNorm, const Scalar convergenceTolerance) const; //! Print \c residualNorm for this \c iteration to the screen @@ -373,7 +373,7 @@ namespace MueLu { const Teuchos::Array& residualNorm) const; //! Compute the residual norm and print it depending on the verbosity level - ReturnType ComputeResidualAndPrintHistory(const Operator& A, const MultiVector& X, + ConvergenceStatus ComputeResidualAndPrintHistory(const Operator& A, const MultiVector& X, const MultiVector& B, const LO iteration, const LO startLevel, const ConvData& conv, MagnitudeType& previousResidualNorm); diff --git a/packages/muelu/src/MueCentral/MueLu_Hierarchy_def.hpp b/packages/muelu/src/MueCentral/MueLu_Hierarchy_def.hpp index ba44cc1be2f9..d235e944a808 100644 --- a/packages/muelu/src/MueCentral/MueLu_Hierarchy_def.hpp +++ b/packages/muelu/src/MueCentral/MueLu_Hierarchy_def.hpp @@ -652,7 +652,7 @@ namespace MueLu { #if defined(HAVE_MUELU_EXPERIMENTAL) && defined(HAVE_MUELU_ADDITIVE_VARIANT) template - ReturnType Hierarchy::Iterate(const MultiVector& B, MultiVector& X, ConvData conv, + ConvergenceStatus Hierarchy::Iterate(const MultiVector& B, MultiVector& X, ConvData conv, bool InitialGuessIsZero, LO startLevel) { LO nIts = conv.maxIts_; MagnitudeType tol = conv.tol_; @@ -851,12 +851,12 @@ namespace MueLu { //communicator->barrier(); - return (tol > 0 ? Unconverged : Undefined); + return (tol > 0 ? ConvergenceStatus::Unconverged : ConvergenceStatus::Undefined); } #else // ---------------------------------------- Iterate ------------------------------------------------------- template - ReturnType Hierarchy::Iterate(const MultiVector& B, MultiVector& X, ConvData conv, + ConvergenceStatus Hierarchy::Iterate(const MultiVector& B, MultiVector& X, ConvData conv, bool InitialGuessIsZero, LO startLevel) { LO nIts = conv.maxIts_; MagnitudeType tol = conv.tol_; @@ -902,7 +902,7 @@ namespace MueLu { // This processor does not have any data for this process on coarser // levels. This can only happen when there are multiple processors and // we use repartitioning. - return Undefined; + return ConvergenceStatus::Undefined; } // If we switched the number of vectors, we'd need to reallocate here. @@ -1117,7 +1117,7 @@ namespace MueLu { if (IsCalculationOfResidualRequired(startLevel, conv)) ComputeResidualAndPrintHistory(*A, X, B, iteration, startLevel, conv, prevNorm); } - return (tol > 0 ? Unconverged : Undefined); + return (tol > 0 ? ConvergenceStatus::Unconverged : ConvergenceStatus::Undefined); } #endif @@ -1569,10 +1569,10 @@ bool Hierarchy::IsCalculationOfResidu template -ReturnType Hierarchy::IsConverged( +ConvergenceStatus Hierarchy::IsConverged( const Teuchos::Array& residualNorm, const Scalar convergenceTolerance) const { - ReturnType convergenceStatus = Undefined; + ConvergenceStatus convergenceStatus = ConvergenceStatus::Undefined; if (convergenceTolerance > 0) { @@ -1582,9 +1582,9 @@ ReturnType Hierarchy::IsConverged( passed = false; if (passed) - convergenceStatus = Converged; + convergenceStatus = ConvergenceStatus::Converged; else - convergenceStatus = Unconverged; + convergenceStatus = ConvergenceStatus::Unconverged; } return convergenceStatus; @@ -1604,7 +1604,7 @@ void Hierarchy::PrintResidualHistory( } template -ReturnType Hierarchy::ComputeResidualAndPrintHistory( +ConvergenceStatus Hierarchy::ComputeResidualAndPrintHistory( const Operator& A, const MultiVector& X, const MultiVector& B, const LO iteration, const LO startLevel, const ConvData& conv, MagnitudeType& previousResidualNorm) { diff --git a/packages/muelu/test/convergence/Convergence.cpp b/packages/muelu/test/convergence/Convergence.cpp index d38a83656e26..954035d908a4 100644 --- a/packages/muelu/test/convergence/Convergence.cpp +++ b/packages/muelu/test/convergence/Convergence.cpp @@ -341,21 +341,21 @@ int main_(Teuchos::CommandLineProcessor &clp, Xpetra::UnderlyingLib lib, int arg H->IsPreconditioner(isPrec); if (isPrec == false) { - MueLu::ReturnType ret = H->Iterate(*B, *X, std::pair(maxIts, tol)); + MueLu::ConvergenceStatus ret = H->Iterate(*B, *X, std::pair(maxIts, tol)); double rate = H->GetRate(); if (std::abs(rate-goldRate) < 0.02) { out << xmlFile << ": passed (" << - (ret == MueLu::Converged ? "converged, " : "unconverged, ") << + (ret == MueLu::ConvergenceStatus::Converged ? "converged, " : "unconverged, ") << "expected rate = " << goldRate << ", real rate = " << rate << - (ret == MueLu::Converged ? "" : " (after " + Teuchos::toString(maxIts) + " iterations)") + (ret == MueLu::ConvergenceStatus::Converged ? "" : " (after " + Teuchos::toString(maxIts) + " iterations)") << ")" << std::endl; } else { out << xmlFile << ": failed (" << - (ret == MueLu::Converged ? "converged, " : "unconverged, ") << + (ret == MueLu::ConvergenceStatus::Converged ? "converged, " : "unconverged, ") << "expected rate = " << goldRate << ", real rate = " << rate << - (ret == MueLu::Converged ? "" : " (after " + Teuchos::toString(maxIts) + " iterations)") + (ret == MueLu::ConvergenceStatus::Converged ? "" : " (after " + Teuchos::toString(maxIts) + " iterations)") << ")" << std::endl; // ap: we need to understand what's going on with the convergence rate // At the moment, disable failure state, so that the test passes as long From 222aeb7642b5c1d8ca2d9259f9773a5870cba6a2 Mon Sep 17 00:00:00 2001 From: Matthias Mayr Date: Tue, 12 Oct 2021 09:20:48 +0200 Subject: [PATCH 10/10] MueLu: fix compiler warnings --- packages/muelu/src/MueCentral/MueLu_Hierarchy_decl.hpp | 2 +- packages/muelu/src/MueCentral/MueLu_Hierarchy_def.hpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/muelu/src/MueCentral/MueLu_Hierarchy_decl.hpp b/packages/muelu/src/MueCentral/MueLu_Hierarchy_decl.hpp index e36a13f6d63c..04831cf38d8e 100644 --- a/packages/muelu/src/MueCentral/MueLu_Hierarchy_decl.hpp +++ b/packages/muelu/src/MueCentral/MueLu_Hierarchy_decl.hpp @@ -366,7 +366,7 @@ namespace MueLu { appropriate \c ConvergenceStatus */ ConvergenceStatus IsConverged(const Teuchos::Array& residualNorm, - const Scalar convergenceTolerance) const; + const MagnitudeType convergenceTolerance) const; //! Print \c residualNorm for this \c iteration to the screen void PrintResidualHistory(const LO iteration, diff --git a/packages/muelu/src/MueCentral/MueLu_Hierarchy_def.hpp b/packages/muelu/src/MueCentral/MueLu_Hierarchy_def.hpp index d235e944a808..16061e10b7d2 100644 --- a/packages/muelu/src/MueCentral/MueLu_Hierarchy_def.hpp +++ b/packages/muelu/src/MueCentral/MueLu_Hierarchy_def.hpp @@ -918,7 +918,7 @@ namespace MueLu { // Print residual information before iterating typedef Teuchos::ScalarTraits STM; - MagnitudeType prevNorm = STM::one(), curNorm = STM::one(); + MagnitudeType prevNorm = STM::one(); rate_ = 1.0; if (IsCalculationOfResidualRequired(startLevel, conv)) ComputeResidualAndPrintHistory(*A, X, B, Teuchos::ScalarTraits::zero(), startLevel, conv, prevNorm); @@ -1570,11 +1570,11 @@ bool Hierarchy::IsCalculationOfResidu template ConvergenceStatus Hierarchy::IsConverged( - const Teuchos::Array& residualNorm, const Scalar convergenceTolerance) const + const Teuchos::Array& residualNorm, const MagnitudeType convergenceTolerance) const { ConvergenceStatus convergenceStatus = ConvergenceStatus::Undefined; - if (convergenceTolerance > 0) + if (convergenceTolerance > Teuchos::ScalarTraits::zero()) { bool passed = true; for (LO k = 0; k < residualNorm.size(); k++)