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<RCP<const FactoryBase> >(
"A", Teuchos::null,
"Generating factory of the matrix A for rebalancing");
43 validParamList->set<RCP<const FactoryBase> >(
"Importer", Teuchos::null,
"Generating factory of the importer");
44 validParamList->set<RCP<const FactoryBase> >(
"InPlaceMap", Teuchos::null,
"Generating factory of the InPlaceMap");
46 return validParamList;
49template <
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");
59template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
68 bool inPlace = pL.get<
bool>(
"repartition: use subcommunicators in place");
73 originalAc->removeEmptyProcessesInPlace(newMap);
76 if (newMap.is_null()) originalAc = Teuchos::null;
78 Set(coarseLevel,
"A", originalAc);
84 if (rebalanceImporter != Teuchos::null) {
85 RCP<Matrix> rebalancedAc;
88 RCP<const Map> targetMap = rebalanceImporter->getTargetMap();
90 ParameterList XpetraList;
91 if (pL.get<
bool>(
"repartition: use subcommunicators") ==
true) {
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));
102 if (!rebalancedAc.is_null()) {
103 rebalancedAc->SetFixedBlockSize(originalAc->GetFixedBlockSize());
104 std::ostringstream oss;
106 rebalancedAc->setObjectLabel(oss.str());
108 Set(coarseLevel,
"A", rebalancedAc);
113 RCP<ParameterList> params = rcp(
new ParameterList());
114 params->set(
"printLoadBalancingInfo",
true);
115 params->set(
"printCommInfo",
true);
124 Set(coarseLevel,
"A", originalAc);
132 GetOStream(
Runtime0) <<
"RebalanceAc: call rebalance factory " << (*it).get() <<
": " << (*it)->description() << std::endl;
133 (*it)->CallBuild(coarseLevel);
138template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
#define SET_VALID_ENTRY(name)
Timer to be used in factories. Similar to Monitor but with additional timers.
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
Class that holds all level-specific information.
int GetLevelID() const
Return level number.
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.
@ Runtime0
One-liner description of what is happening.
@ Runtime1
Description of what is happening (more verbose).