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";
78 if (!(coarseLevel.
IsAvailable(matrixName, GetFactory(
"A").get())) && ((matrixName ==
"M") || (matrixName ==
"Minv") || (matrixName ==
"MinvA")))
return;
79 FactoryMonitor m(*
this,
"Computing " + coarseMatrixName, coarseLevel);
81 RCP<Matrix> originalAc = coarseLevel.
Get<RCP<Matrix> >(matrixName, GetFactory(
"A").get());
85 bool inPlace = pL.get<
bool>(
"repartition: use subcommunicators in place");
87 SubFactoryMonitor subM(*
this,
"Rebalancing existing " + coarseMatrixName +
" in-place", coarseLevel);
88 RCP<const Map> newMap = Get<RCP<const Map> >(coarseLevel,
"InPlaceMap");
90 originalAc->removeEmptyProcessesInPlace(newMap);
93 if (newMap.is_null()) originalAc = Teuchos::null;
95 Set(coarseLevel, matrixName, originalAc);
99 RCP<const Import> rebalanceImporter = Get<RCP<const Import> >(coarseLevel,
"Importer");
101 if (rebalanceImporter != Teuchos::null) {
102 RCP<Matrix> rebalancedAc;
104 SubFactoryMonitor subM(*
this,
"Rebalancing existing " + coarseMatrixName, coarseLevel);
105 RCP<const Map> targetMap = rebalanceImporter->getTargetMap();
107 ParameterList XpetraList;
108 if (pL.get<
bool>(
"repartition: use subcommunicators") ==
true) {
109 GetOStream(
Runtime0) <<
"Replacing maps with a subcommunicator" << std::endl;
110 XpetraList.set(
"Restrict Communicator",
true);
112 XpetraList.set(
"compute global constants", IsPrint(
Statistics1));
114 XpetraList.set(
"Timer Label",
"MueLu::RebalanceAc-" + Teuchos::toString(coarseLevel.
GetLevelID()));
116 SubFactoryMonitor subM2(*
this,
"Rebalancing existing " + coarseMatrixName +
": MatrixFactory::Build", coarseLevel);
117 rebalancedAc = MatrixFactory::Build(originalAc, *rebalanceImporter, *rebalanceImporter, targetMap, targetMap, rcp(&XpetraList,
false));
120 if (!rebalancedAc.is_null()) {
121 if (originalAc->IsFixedBlockSizeSet())
122 rebalancedAc->SetFixedBlockSize(originalAc->GetFixedBlockSize());
123 std::ostringstream oss;
125 rebalancedAc->setObjectLabel(oss.str());
127 Set(coarseLevel, matrixName, rebalancedAc);
129 if (!rebalancedAc.is_null() && IsPrint(
Statistics2)) {
130 int oldRank = SetProcRankVerbose(rebalancedAc->getRowMap()->getComm()->getRank());
132 RCP<ParameterList> params = rcp(
new ParameterList());
133 params->set(
"printLoadBalancingInfo",
true);
134 params->set(
"printCommInfo",
true);
137 SetProcRankVerbose(oldRank);
142 GetOStream(
Runtime1) <<
"No rebalancing" << std::endl;
143 Set(coarseLevel, matrixName, originalAc);
146 if (rebalanceFacts_.begin() != rebalanceFacts_.end()) {
150 for (std::vector<RCP<const FactoryBase> >::const_iterator it = rebalanceFacts_.begin(); it != rebalanceFacts_.end(); ++it) {
151 GetOStream(
Runtime0) <<
"RebalanceAc: call rebalance factory " << (*it).get() <<
": " << (*it)->description() << std::endl;
152 (*it)->CallBuild(coarseLevel);