10 #ifndef MUELU_REBALANCEACFACTORY_DEF_HPP
11 #define MUELU_REBALANCEACFACTORY_DEF_HPP
15 #include <Xpetra_CrsMatrixWrap.hpp>
22 #include "MueLu_PerfUtils.hpp"
23 #include "MueLu_RAPFactory.hpp"
27 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
30 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
33 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
37 #define SET_VALID_ENTRY(name) validParamList->setEntry(name, MasterList::getEntry(name))
40 #undef SET_VALID_ENTRY
46 return validParamList;
49 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
51 Input(coarseLevel,
"A");
53 if (pL.
isParameter(
"repartition: use subcommunicators in place") && pL.
get<
bool>(
"repartition: use subcommunicators in place") ==
true) {
54 Input(coarseLevel,
"InPlaceMap");
56 Input(coarseLevel,
"Importer");
59 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
64 RCP<Matrix> originalAc = Get<RCP<Matrix> >(coarseLevel,
"A");
68 bool inPlace = pL.
get<
bool>(
"repartition: use subcommunicators in place");
71 RCP<const Map> newMap = Get<RCP<const Map> >(coarseLevel,
"InPlaceMap");
73 originalAc->removeEmptyProcessesInPlace(newMap);
76 if (newMap.
is_null()) originalAc = Teuchos::null;
78 Set(coarseLevel,
"A", originalAc);
82 RCP<const Import> rebalanceImporter = Get<RCP<const Import> >(coarseLevel,
"Importer");
84 if (rebalanceImporter != Teuchos::null) {
91 if (pL.
get<
bool>(
"repartition: use subcommunicators") ==
true) {
92 GetOStream(
Runtime0) <<
"Replacing maps with a subcommunicator" << std::endl;
93 XpetraList.
set(
"Restrict Communicator",
true);
96 XpetraList.
set(
"Timer Label",
"MueLu::RebalanceAc-" +
Teuchos::toString(coarseLevel.GetLevelID()));
98 SubFactoryMonitor subM2(*
this,
"Rebalancing existing Ac: MatrixFactory::Build", coarseLevel);
99 rebalancedAc = MatrixFactory::Build(originalAc, *rebalanceImporter, *rebalanceImporter, targetMap, targetMap,
rcp(&XpetraList,
false));
103 rebalancedAc->SetFixedBlockSize(originalAc->GetFixedBlockSize());
104 std::ostringstream oss;
105 oss <<
"A_" << coarseLevel.GetLevelID();
106 rebalancedAc->setObjectLabel(oss.str());
108 Set(coarseLevel,
"A", rebalancedAc);
111 int oldRank = SetProcRankVerbose(rebalancedAc->getRowMap()->getComm()->getRank());
114 params->set(
"printLoadBalancingInfo",
true);
115 params->set(
"printCommInfo",
true);
118 SetProcRankVerbose(oldRank);
123 GetOStream(
Runtime1) <<
"No rebalancing" << std::endl;
124 Set(coarseLevel,
"A", originalAc);
127 if (rebalanceFacts_.begin() != rebalanceFacts_.end()) {
131 for (std::vector<
RCP<const FactoryBase> >::const_iterator it = rebalanceFacts_.begin(); it != rebalanceFacts_.end(); ++it) {
132 GetOStream(
Runtime0) <<
"RebalanceAc: call rebalance factory " << (*it).get() <<
": " << (*it)->description() << std::endl;
133 (*it)->CallBuild(coarseLevel);
138 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
144 rebalanceFacts_.push_back(factory);
149 #endif // MUELU_REBALANCEACFACTORY_DEF_HPP
T & get(const std::string &name, T def_value)
Timer to be used in factories. Similar to Monitor but with additional timers.
One-liner description of what is happening.
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
RCP< const ParameterList > GetValidParameterList() const
Return a const parameter list of valid parameters that setParameterList() will accept.
Print even more statistics.
bool isParameter(const std::string &name) const
void AddRebalanceFactory(const RCP< const FactoryBase > &factory)
Add rebalancing factory in the end of list of rebalancing factories in RebalanceAcFactory.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Class that holds all level-specific information.
#define SET_VALID_ENTRY(name)
virtual ~RebalanceAcFactory()
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)
void Build(Level &fineLevel, Level &coarseLevel) const
Build an object with this factory.
void DeclareInput(Level &fineLevel, Level &coarseLevel) const
Input.
Description of what is happening (more verbose)
std::string toString(const T &t)