64 const Teuchos::ParameterList &pL = GetParameterList();
65 auto matrixName = pL.get<std::string>(
"Matrix name");
66 std::string coarseMatrixName;
67 if (matrixName.size() == 1)
68 coarseMatrixName = matrixName +
"c";
70 coarseMatrixName = matrixName +
"_coarse";
72 FactoryMonitor m(*
this,
"Computing " + coarseMatrixName, coarseLevel);
74 RCP<Matrix> originalAc = coarseLevel.
Get<RCP<Matrix> >(matrixName, GetFactory(
"A").get());
78 bool inPlace = pL.get<
bool>(
"repartition: use subcommunicators in place");
80 SubFactoryMonitor subM(*
this,
"Rebalancing existing " + coarseMatrixName +
" in-place", coarseLevel);
81 RCP<const Map> newMap = Get<RCP<const Map> >(coarseLevel,
"InPlaceMap");
83 originalAc->removeEmptyProcessesInPlace(newMap);
86 if (newMap.is_null()) originalAc = Teuchos::null;
88 Set(coarseLevel, matrixName, originalAc);
92 RCP<const Import> rebalanceImporter = Get<RCP<const Import> >(coarseLevel,
"Importer");
94 if (rebalanceImporter != Teuchos::null) {
95 RCP<Matrix> rebalancedAc;
97 SubFactoryMonitor subM(*
this,
"Rebalancing existing " + coarseMatrixName, coarseLevel);
98 RCP<const Map> targetMap = rebalanceImporter->getTargetMap();
100 ParameterList XpetraList;
101 if (pL.get<
bool>(
"repartition: use subcommunicators") ==
true) {
102 GetOStream(
Runtime0) <<
"Replacing maps with a subcommunicator" << std::endl;
103 XpetraList.set(
"Restrict Communicator",
true);
106 XpetraList.set(
"Timer Label",
"MueLu::RebalanceAc-" + Teuchos::toString(coarseLevel.
GetLevelID()));
108 SubFactoryMonitor subM2(*
this,
"Rebalancing existing " + coarseMatrixName +
": MatrixFactory::Build", coarseLevel);
109 rebalancedAc = MatrixFactory::Build(originalAc, *rebalanceImporter, *rebalanceImporter, targetMap, targetMap, rcp(&XpetraList,
false));
112 if (!rebalancedAc.is_null()) {
113 if (originalAc->IsFixedBlockSizeSet())
114 rebalancedAc->SetFixedBlockSize(originalAc->GetFixedBlockSize());
115 std::ostringstream oss;
117 rebalancedAc->setObjectLabel(oss.str());
119 Set(coarseLevel, matrixName, rebalancedAc);
121 if (!rebalancedAc.is_null() && IsPrint(
Statistics2)) {
122 int oldRank = SetProcRankVerbose(rebalancedAc->getRowMap()->getComm()->getRank());
124 RCP<ParameterList> params = rcp(
new ParameterList());
125 params->set(
"printLoadBalancingInfo",
true);
126 params->set(
"printCommInfo",
true);
129 SetProcRankVerbose(oldRank);
134 GetOStream(
Runtime1) <<
"No rebalancing" << std::endl;
135 Set(coarseLevel, matrixName, originalAc);
138 if (rebalanceFacts_.begin() != rebalanceFacts_.end()) {
142 for (std::vector<RCP<const FactoryBase> >::const_iterator it = rebalanceFacts_.begin(); it != rebalanceFacts_.end(); ++it) {
143 GetOStream(
Runtime0) <<
"RebalanceAc: call rebalance factory " << (*it).get() <<
": " << (*it)->description() << std::endl;
144 (*it)->CallBuild(coarseLevel);
void DeclareInput(const std::string &ename, const FactoryBase *factory, const FactoryBase *requestedBy=NoFactory::get())
Callback from FactoryBase::CallDeclareInput() and FactoryBase::DeclareInput()