| 1 |
// @HEADER |
| 2 |
// ***************************************************************************** |
| 3 |
// MueLu: A package for multigrid based preconditioning |
| 4 |
// |
| 5 |
// Copyright 2012 NTESS and the MueLu contributors. |
| 6 |
// SPDX-License-Identifier: BSD-3-Clause |
| 7 |
// ***************************************************************************** |
| 8 |
// @HEADER |
| 9 |
|
| 10 |
#include "MueLu_SingleLevelFactoryBase.hpp" |
| 11 |
#include "MueLu_TimeMonitor.hpp" |
| 12 |
#include "MueLu_Level.hpp" |
| 13 |
|
| 14 |
namespace MueLu { |
| 15 |
|
| 16 |
SingleLevelFactoryBase::SingleLevelFactoryBase() = default; |
| 17 |
|
| 18 |
SingleLevelFactoryBase::~SingleLevelFactoryBase() = default; |
| 19 |
|
| 20 |
void SingleLevelFactoryBase::CallBuild(Level& requestedLevel) const { |
| 21 |
#ifdef HAVE_MUELU_DEBUG |
| 22 |
// We cannot call Build method twice for the same level, but we can call it multiple times for different levels |
| 23 |
int levelID = requestedLevel.GetLevelID(); |
| 24 |
TEUCHOS_TEST_FOR_EXCEPTION((multipleCallCheck_ == ENABLED) && (multipleCallCheckGlobal_ == ENABLED) && (lastLevelID_ == levelID), |
| 25 |
Exceptions::RuntimeError, |
| 26 |
this->ShortClassName() << "::Build() called twice for the same level (levelID=" << levelID |
| 27 |
<< "). This is likely due to a configuration error, or calling hierarchy setup multiple times " |
| 28 |
<< "without resetting debug info through FactoryManager::ResetDebugData()."); |
| 29 |
if (multipleCallCheck_ == FIRSTCALL) |
| 30 |
multipleCallCheck_ = ENABLED; |
| 31 |
|
| 32 |
lastLevelID_ = levelID; |
| 33 |
#endif |
| 34 |
|
| 35 |
RCP<const Teuchos::Comm<int> > comm = requestedLevel.GetComm(); |
| 36 |
if (comm.is_null()) { |
| 37 |
// Some factories are called before we constructed Ac, and therefore, |
| 38 |
// before we set the level communicator. For such factories we can get |
| 39 |
// the comm from the previous level, as all processes go there |
| 40 |
RCP<Level>& prevLevel = requestedLevel.GetPreviousLevel(); |
| 41 |
if (!prevLevel.is_null()) |
| 42 |
comm = prevLevel->GetComm(); |
| 43 |
} |
| 44 |
|
| 45 |
int oldRank = -1; |
| 46 |
if (!comm.is_null()) |
| 47 |
oldRank = SetProcRankVerbose(comm->getRank()); |
| 48 |
|
| 49 |
// Synchronization timer |
| 50 |
std::string syncTimer = this->ShortClassName() + ": Build sync (level=" + toString(requestedLevel.GetLevelID()) + ")"; |
| 51 |
if (this->timerSync_ && !comm.is_null()) { |
| 52 |
TimeMonitor timer(*this, syncTimer); |
| 53 |
comm->barrier(); |
| 54 |
} |
| 55 |
|
| 56 |
Build(requestedLevel); |
| 57 |
|
| 58 |
if (this->timerSync_ && !comm.is_null()) { |
| 59 |
TimeMonitor timer(*this, syncTimer); |
| 60 |
comm->barrier(); |
| 61 |
} |
| 62 |
|
| 63 |
if (IsPrint(Test1)) |
| 64 |
GetOStream(Test1) << *RemoveFactoriesFromList(GetParameterList()) << std::endl; |
| 65 |
else |
| 66 |
RemoveFactoriesFromList(GetParameterList())->print(GetOStream(Test0), Teuchos::ParameterList::PrintOptions().indent(0).showFlags(true).showDefault(false)); |
| 67 |
|
| 68 |
if (oldRank != -1) |
| 69 |
SetProcRankVerbose(oldRank); |
| 70 |
} |
| 71 |
|
| 72 |
void SingleLevelFactoryBase::CallDeclareInput(Level& requestedLevel) const { |
| 73 |
DeclareInput(requestedLevel); |
| 74 |
} |
| 75 |
|
| 76 |
} // namespace MueLu |
| 77 |
|
| 78 |
// TODO: code factorization between SingleLevelFactoryBase and TwoLevelFactoryBase |