47 #ifndef PACKAGES_MUELU_SRC_REBALANCING_MUELU_REPARTITIONHEURISTICFACTORY_DEF_HPP_ 48 #define PACKAGES_MUELU_SRC_REBALANCING_MUELU_REPARTITIONHEURISTICFACTORY_DEF_HPP_ 56 #include <Teuchos_DefaultMpiComm.hpp> 57 #include <Teuchos_CommHelpers.hpp> 60 #include <Xpetra_Matrix.hpp> 62 #include "MueLu_Utilities.hpp" 64 #include "MueLu_RAPFactory.hpp" 65 #ifdef HAVE_MUELU_EXPERIMENTAL 66 #include "MueLu_BlockedRAPFactory.hpp" 68 #include "MueLu_SubBlockAFactory.hpp" 73 #include "MueLu_RepartitionHeuristicFactory.hpp" 77 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
79 RCP<ParameterList> validParamList = rcp(
new ParameterList());
81 #define SET_VALID_ENTRY(name) validParamList->setEntry(name, MasterList::getEntry(name)) 85 #undef SET_VALID_ENTRY 87 validParamList->set< RCP<const FactoryBase> >(
"A", Teuchos::null,
"Factory of the matrix A");
89 return validParamList;
92 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
94 Input(currentLevel,
"A");
97 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
101 const Teuchos::ParameterList & pL = GetParameterList();
104 const int startLevel = pL.get<
int> (
"repartition: start level");
105 const LO minRowsPerProcessor = pL.get<LO> (
"repartition: min rows per proc");
106 const double nonzeroImbalance = pL.get<
double>(
"repartition: max imbalance");
108 RCP<const FactoryBase> Afact = GetFactory(
"A");
109 if(Teuchos::rcp_dynamic_cast<const RAPFactory>(Afact) == Teuchos::null &&
110 #ifdef HAVE_MUELU_EXPERIMENTAL
111 Teuchos::rcp_dynamic_cast<const BlockedRAPFactory>(Afact) == Teuchos::null &&
113 Teuchos::rcp_dynamic_cast<const SubBlockAFactory>(Afact) == Teuchos::null)
115 "MueLu::RepartitionHeuristicFactory::Build: The generation factory for A must " \
116 "be a RAPFactory or a SubBlockAFactory providing the non-rebalanced matrix information! " \
117 "It specifically must not be of type Rebalance(Blocked)AcFactory or similar. " \
118 "Please check the input. Make also sure that \"number of partitions\" is provided to" \
119 "the Interface class and the RepartitionFactory instance." << std::endl;
122 RCP<Matrix> A = Get< RCP<Matrix> >(currentLevel,
"A");
132 if (currentLevel.GetLevelID() < startLevel) {
133 GetOStream(
Statistics1) <<
"Repartitioning? NO:" <<
135 ", first level where repartitioning can happen is " +
Teuchos::toString(startLevel) << std::endl;
138 Set(currentLevel,
"number of partitions", -1);
143 RCP<const Map> rowMap = A->getRowMap();
148 RCP<const Teuchos::Comm<int> > origComm = rowMap->getComm();
149 RCP<const Teuchos::Comm<int> > comm = origComm->duplicate();
155 int numActiveProcesses = 0;
156 MueLu_sumAll(comm, Teuchos::as<int>((A->getNodeNumRows() > 0) ? 1 : 0), numActiveProcesses);
158 if (numActiveProcesses == 1) {
159 GetOStream(
Statistics1) <<
"Repartitioning? NO:" <<
160 "\n # processes with rows = " <<
Teuchos::toString(numActiveProcesses) << std::endl;
162 Set(currentLevel,
"number of partitions", 1);
167 bool test3 =
false, test4 =
false;
168 std::string msg3, msg4;
172 if (minRowsPerProcessor > 0) {
173 LO numMyRows = Teuchos::as<LO>(A->getNodeNumRows()), minNumRows, LOMAX = Teuchos::OrdinalTraits<LO>::max();
174 LO haveFewRows = (numMyRows < minRowsPerProcessor ? 1 : 0), numWithFewRows = 0;
176 MueLu_minAll(comm, (numMyRows > 0 ? numMyRows : LOMAX), minNumRows);
181 if (numWithFewRows > 0)
189 GO minNnz, maxNnz, numMyNnz = Teuchos::as<GO>(A->getNodeNumEntries());
191 MueLu_minAll(comm, (numMyNnz > 0 ? numMyNnz : maxNnz), minNnz);
192 double imbalance = Teuchos::as<double>(maxNnz)/minNnz;
194 if (imbalance > nonzeroImbalance)
200 if (!test3 && !test4) {
201 GetOStream(
Statistics1) <<
"Repartitioning? NO:" << msg3 + msg4 << std::endl;
204 Set(currentLevel,
"number of partitions", -1);
208 GetOStream(
Statistics1) <<
"Repartitioning? YES:" << msg3 + msg4 << std::endl;
222 if (Teuchos::as<GO>(A->getGlobalNumRows()) < minRowsPerProcessor) {
228 numPartitions = A->getGlobalNumRows() / minRowsPerProcessor;
230 numPartitions = std::min(numPartitions, comm->getSize());
232 Set(currentLevel,
"number of partitions", numPartitions);
234 GetOStream(
Statistics1) <<
"Number of partitions to use = " << numPartitions << std::endl;
238 #endif //ifdef HAVE_MPI #define MueLu_sumAll(rcpComm, in, out)
std::string toString(const T &what)
Little helper function to convert non-string types to strings.
#define MueLu_maxAll(rcpComm, in, out)
void DeclareInput(Level ¤tLevel) const
Determines the data that RepartitionHeuristicFactory needs, and the factories that generate that data...
Timer to be used in factories. Similar to Monitor but with additional timers.
void Build(Level ¤tLevel) const
Build an object with this factory.
#define SET_VALID_ENTRY(name)
Namespace for MueLu classes and methods.
#define MueLu_minAll(rcpComm, in, out)
Class that holds all level-specific information.
RCP< const ParameterList > GetValidParameterList() const
Return a const parameter list of valid parameters that setParameterList() will accept.
Print all warning messages.