10#ifndef MUELU_REBALANCEACFACTORY_DEF_HPP
11#define MUELU_REBALANCEACFACTORY_DEF_HPP
13#include <Xpetra_Matrix.hpp>
14#include <Xpetra_CrsMatrix.hpp>
15#include <Xpetra_CrsMatrixWrap.hpp>
16#include <Xpetra_MatrixFactory.hpp>
22#include "MueLu_PerfUtils.hpp"
23#include "MueLu_RAPFactory.hpp"
27template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
30template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
33template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
35 RCP<ParameterList> validParamList = rcp(
new ParameterList());
37#define SET_VALID_ENTRY(name) validParamList->setEntry(name, MasterList::getEntry(name))
42 validParamList->set<std::string>(
"Matrix name",
"A",
"Name of the matrix that will be transferred on the coarse grid (level key)");
44 validParamList->set<RCP<const FactoryBase> >(
"A", Teuchos::null,
"Generating factory of the matrix A for rebalancing");
45 validParamList->set<RCP<const FactoryBase> >(
"Importer", Teuchos::null,
"Generating factory of the importer");
46 validParamList->set<RCP<const FactoryBase> >(
"InPlaceMap", Teuchos::null,
"Generating factory of the InPlaceMap");
48 return validParamList;
51template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
54 std::string matrixName = pL.get<std::string>(
"Matrix name");
56 if (pL.isParameter(
"repartition: use subcommunicators in place") && pL.get<
bool>(
"repartition: use subcommunicators in place") ==
true) {
57 Input(coarseLevel,
"InPlaceMap");
59 Input(coarseLevel,
"Importer");
62template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
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);
90 originalAc->removeEmptyProcessesInPlace(newMap);
93 if (newMap.is_null()) originalAc = Teuchos::null;
95 Set(coarseLevel, matrixName, originalAc);
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) {
110 XpetraList.set(
"Restrict Communicator",
true);
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);
132 RCP<ParameterList> params = rcp(
new ParameterList());
133 params->set(
"printLoadBalancingInfo",
true);
134 params->set(
"printCommInfo",
true);
143 Set(coarseLevel, matrixName, originalAc);
151 GetOStream(
Runtime0) <<
"RebalanceAc: call rebalance factory " << (*it).get() <<
": " << (*it)->description() << std::endl;
152 (*it)->CallBuild(coarseLevel);
157template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
#define SET_VALID_ENTRY(name)
void Input(Level &level, const std::string &varName) const
T Get(Level &level, const std::string &varName) const
void Set(Level &level, const std::string &varName, const T &data) const
const RCP< const FactoryBase > GetFactory(const std::string &varName) const
Default implementation of FactoryAcceptor::GetFactory().
Timer to be used in factories. Similar to Monitor but with additional timers.
Class that holds all level-specific information.
bool IsAvailable(const std::string &ename, const FactoryBase *factory=NoFactory::get()) const
Test whether a need's value has been saved.
void DeclareInput(const std::string &ename, const FactoryBase *factory, const FactoryBase *requestedBy=NoFactory::get())
Callback from FactoryBase::CallDeclareInput() and FactoryBase::DeclareInput().
int GetLevelID() const
Return level number.
T & Get(const std::string &ename, const FactoryBase *factory=NoFactory::get())
Get data without decrementing associated storage counter (i.e., read-only access)....
virtual const Teuchos::ParameterList & GetParameterList() const
static std::string PrintMatrixInfo(const Matrix &A, const std::string &msgTag, RCP< const Teuchos::ParameterList > params=Teuchos::null)
void AddRebalanceFactory(const RCP< const FactoryBase > &factory)
Add rebalancing factory in the end of list of rebalancing factories in RebalanceAcFactory.
void Build(Level &fineLevel, Level &coarseLevel) const
Build an object with this factory.
RCP< const ParameterList > GetValidParameterList() const
Return a const parameter list of valid parameters that setParameterList() will accept.
virtual ~RebalanceAcFactory()
void DeclareInput(Level &fineLevel, Level &coarseLevel) const
Input.
std::vector< RCP< const FactoryBase > > rebalanceFacts_
list of user-defined rebalancing Factories
Timer to be used in factories. Similar to SubMonitor but adds a timer level by level.
Teuchos::FancyOStream & GetOStream(MsgType type, int thisProcRankOnly=0) const
Get an output stream for outputting the input message type.
int SetProcRankVerbose(int procRank) const
Set proc rank used for printing.
bool IsPrint(MsgType type, int thisProcRankOnly=-1) const
Find out whether we need to print out information for a specific message type.
Namespace for MueLu classes and methods.
@ Statistics2
Print even more statistics.
@ Statistics1
Print more statistics.
@ Runtime0
One-liner description of what is happening.
@ Runtime1
Description of what is happening (more verbose).