46 #ifndef MUELU_REBALANCEACFACTORY_DEF_HPP 47 #define MUELU_REBALANCEACFACTORY_DEF_HPP 49 #include <Xpetra_Matrix.hpp> 50 #include <Xpetra_CrsMatrix.hpp> 51 #include <Xpetra_CrsMatrixWrap.hpp> 52 #include <Xpetra_MatrixFactory.hpp> 58 #include "MueLu_PerfUtils.hpp" 59 #include "MueLu_RAPFactory.hpp" 63 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
65 RCP<ParameterList> validParamList = rcp(
new ParameterList());
67 #define SET_VALID_ENTRY(name) validParamList->setEntry(name, MasterList::getEntry(name)) 69 #undef SET_VALID_ENTRY 71 validParamList->set< RCP<const FactoryBase> >(
"A", Teuchos::null,
"Generating factory of the matrix A for rebalancing");
72 validParamList->set< RCP<const FactoryBase> >(
"Importer", Teuchos::null,
"Generating factory of the importer");
74 return validParamList;
77 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
79 Input(coarseLevel,
"A");
80 Input(coarseLevel,
"Importer");
83 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
87 RCP<Matrix> originalAc = Get< RCP<Matrix> >(coarseLevel,
"A");
89 RCP<const Import> rebalanceImporter = Get< RCP<const Import> >(coarseLevel,
"Importer");
91 if (rebalanceImporter != Teuchos::null) {
92 RCP<Matrix> rebalancedAc;
95 RCP<const Map> targetMap = rebalanceImporter->getTargetMap();
97 const ParameterList & pL = GetParameterList();
99 ParameterList XpetraList;
100 if (pL.get<
bool>(
"repartition: use subcommunicators") ==
true) {
101 GetOStream(
Runtime0) <<
"Replacing maps with a subcommunicator" << std::endl;
102 XpetraList.set(
"Restrict Communicator",
true);
105 XpetraList.set(
"Timer Label",
"MueLu::RebalanceAc-" +
Teuchos::toString(coarseLevel.GetLevelID()));
106 rebalancedAc = MatrixFactory::Build(originalAc, *rebalanceImporter, *rebalanceImporter, targetMap, targetMap, rcp(&XpetraList,
false));
108 if (!rebalancedAc.is_null())
109 rebalancedAc->SetFixedBlockSize(originalAc->GetFixedBlockSize());
111 Set(coarseLevel,
"A", rebalancedAc);
114 if (!rebalancedAc.is_null() && IsPrint(
Statistics1)) {
115 int oldRank = SetProcRankVerbose(rebalancedAc->getRowMap()->getComm()->getRank());
117 RCP<ParameterList> params = rcp(
new ParameterList());
118 params->set(
"printLoadBalancingInfo",
true);
119 params->set(
"printCommInfo",
true);
122 SetProcRankVerbose(oldRank);
127 GetOStream(
Runtime1) <<
"No rebalancing" << std::endl;
128 Set(coarseLevel,
"A", originalAc);
131 if (rebalanceFacts_.begin() != rebalanceFacts_.end()) {
135 for (std::vector<RCP<const FactoryBase> >::const_iterator it = rebalanceFacts_.begin(); it != rebalanceFacts_.end(); ++it) {
136 GetOStream(
Runtime0) <<
"RebalanceAc: call rebalance factory " << (*it).get() <<
": " << (*it)->description() << std::endl;
137 (*it)->CallBuild(coarseLevel);
143 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
150 rebalanceFacts_.push_back(factory);
155 #endif // MUELU_REBALANCEACFACTORY_DEF_HPP
std::string toString(const T &what)
Little helper function to convert non-string types to strings.
Timer to be used in factories. Similar to Monitor but with additional timers.
One-liner description of what is happening.
Namespace for MueLu classes and methods.
void Build(Level &fineLevel, Level &coarseLevel) const
Build an object with this factory.
void AddRebalanceFactory(const RCP< const FactoryBase > &factory)
Add rebalancing factory in the end of list of rebalancing factories in RebalanceAcFactory.
Class that holds all level-specific information.
#define SET_VALID_ENTRY(name)
Timer to be used in factories. Similar to SubMonitor but adds a timer level by level.
RCP< const ParameterList > GetValidParameterList() const
Return a const parameter list of valid parameters that setParameterList() will accept.
static std::string PrintMatrixInfo(const Matrix &A, const std::string &msgTag, RCP< const Teuchos::ParameterList > params=Teuchos::null)
Description of what is happening (more verbose)
void DeclareInput(Level &fineLevel, Level &coarseLevel) const
Input.