10 #ifndef MUELU_ZOLTAN2INTERFACE_DEF_HPP
11 #define MUELU_ZOLTAN2INTERFACE_DEF_HPP
17 #if defined(HAVE_MUELU_ZOLTAN2) && defined(HAVE_MPI)
19 #include <Zoltan2_XpetraMultiVectorAdapter.hpp>
20 #include <Zoltan2_XpetraCrsGraphAdapter.hpp>
21 #include <Zoltan2_PartitioningProblem.hpp>
25 #include <Teuchos_OpaqueWrapper.hpp>
33 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
36 defaultZoltan2Params->set(
"algorithm",
"multijagged");
37 defaultZoltan2Params->set(
"partitioning_approach",
"partition");
42 defaultZoltan2Params->set(
"mj_premigration_option", 1);
45 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
50 validParamList->
set<
RCP<const FactoryBase> >(
"number of partitions", Teuchos::null,
"Instance of RepartitionHeuristicFactory.");
53 validParamList->
set<
RCP<const FactoryBase> >(
"repartition: heuristic target rows per process", Teuchos::null,
"Factory for number of rows per process to use with MultiJagged");
55 return validParamList;
58 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
60 Input(currentLevel,
"A");
61 Input(currentLevel,
"number of partitions");
67 if (providedList != Teuchos::null && providedList->
isType<std::string>(
"algorithm")) {
68 const std::string algo = providedList->
get<std::string>(
"algorithm");
69 if (algo ==
"multijagged") {
70 Input(currentLevel,
"Coordinates");
71 Input(currentLevel,
"repartition: heuristic target rows per process");
72 }
else if (algo ==
"rcb") {
73 Input(currentLevel,
"Coordinates");
76 Input(currentLevel,
"repartition: heuristic target rows per process");
77 Input(currentLevel,
"Coordinates");
81 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
90 LO blkSize = A->GetFixedBlockSize();
92 int numParts = Get<int>(level,
"number of partitions");
93 if (numParts == 1 || numParts == -1) {
96 Set(level,
"Partition", decomposition);
110 if (providedList != Teuchos::null)
111 Zoltan2Params = *providedList;
116 const std::string& pName = defaultZoltan2Params->
name(param);
117 if (!Zoltan2Params.isParameter(pName))
118 Zoltan2Params.setEntry(pName, defaultZoltan2Params->getEntry(pName));
120 Zoltan2Params.set(
"num_global_parts", Teuchos::as<int>(numParts));
122 GetOStream(
Runtime0) <<
"Zoltan2 parameters:\n----------\n"
123 << Zoltan2Params <<
"----------" << std::endl;
125 const std::string& algo = Zoltan2Params.
get<std::string>(
"algorithm");
127 if (algo ==
"multijagged" || algo ==
"rcb") {
130 GO numElements = map->getLocalNumElements();
134 "Coordinate vector length (" +
toString(coords->getLocalLength()) <<
" is incompatible with number of block rows in A (" +
toString(rowMap->getLocalNumElements() / blkSize) +
"The vector length should be the same as the number of mesh points.");
135 #ifdef HAVE_MUELU_DEBUG
136 GO indexBase = rowMap->getIndexBase();
137 GetOStream(
Runtime0) <<
"Checking consistence of row and coordinates maps" << std::endl;
141 for (
LO i = 0; i < Teuchos::as<LO>(numElements); i++)
143 Exceptions::RuntimeError,
"i = " << i <<
", coords GID = " << coordsElements[i] <<
", row GID = " << rowElements[i * blkSize] <<
", blkSize = " << blkSize << std::endl);
146 typedef Zoltan2::XpetraMultiVectorAdapter<RealValuedMultiVector> InputAdapterType;
147 typedef Zoltan2::PartitioningProblem<InputAdapterType> ProblemType;
150 for (
LO i = 0; i < numElements; i++) {
151 weightsPerRow[i] = 0.0;
153 for (
LO j = 0; j < blkSize; j++) {
154 weightsPerRow[i] += A->getNumEntriesInLocalRow(i * blkSize + j);
159 if (algo ==
"multijagged" && !Zoltan2Params.isParameter(
"mj_premigration_coordinate_count")) {
160 LO heuristicTargetRowsPerProcess = Get<LO>(level,
"repartition: heuristic target rows per process");
161 Zoltan2Params.set(
"mj_premigration_coordinate_count", heuristicTargetRowsPerProcess);
163 const bool writeZoltan2DebuggingFiles = Zoltan2Params.
get(
"mj_debug",
false);
164 Zoltan2Params.remove(
"mj_debug");
166 std::vector<int> strides;
167 std::vector<const real_type*> weights(1, weightsPerRow.
getRawPtr());
172 InputAdapterType adapter(coords, weights, strides);
173 RCP<ProblemType> problem(
new ProblemType(&adapter, &Zoltan2Params, (*zoltanComm)()));
177 if (writeZoltan2DebuggingFiles)
178 adapter.generateFiles((
"mj_debug.lvl_" + std::to_string(level.GetLevelID())).c_str(), *(rowMap->getComm()));
183 ArrayRCP<GO> decompEntries = decomposition->getDataNonConst(0);
185 const typename InputAdapterType::part_t* parts = problem->getSolution().getPartListView();
187 for (
GO i = 0; i < numElements; i++) {
188 int partNum = parts[i];
190 for (
LO j = 0; j < blkSize; j++)
191 decompEntries[i * blkSize + j] = partNum;
194 Set(level,
"Partition", decomposition);
197 GO numElements = rowMap->getLocalNumElements();
199 typedef Zoltan2::XpetraCrsGraphAdapter<CrsGraph> InputAdapterType;
200 typedef Zoltan2::PartitioningProblem<InputAdapterType> ProblemType;
205 InputAdapterType adapter(A->getCrsGraph());
206 RCP<ProblemType> problem(
new ProblemType(&adapter, &Zoltan2Params, (*zoltanComm)()));
214 ArrayRCP<GO> decompEntries = decomposition->getDataNonConst(0);
216 const typename InputAdapterType::part_t* parts = problem->getSolution().getPartListView();
219 for (
GO i = 0; i < numElements / blkSize; i++) {
220 int partNum = parts[i * blkSize];
222 for (
LO j = 0; j < blkSize; j++)
223 decompEntries[i * blkSize + j] = partNum;
226 Set(level,
"Partition", decomposition);
232 #endif // if defined(HAVE_MUELU_ZOLTAN2) && defined(HAVE_MPI)
234 #endif // MUELU_ZOLTAN2INTERFACE_DEF_HPP
const std::string & name() const
std::string toString(const T &what)
Little helper function to convert non-string types to strings.
T & get(const std::string &name, T def_value)
Timer to be used in factories. Similar to Monitor but with additional timers.
Zoltan2Interface()
Constructor.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
One-liner description of what is happening.
void Build(Level ¤tLevel) const
Build an object with this factory.
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
Exception throws to report incompatible objects (like maps).
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Class that holds all level-specific information.
Timer to be used in factories. Similar to SubMonitor but adds a timer level by level.
params_t::ConstIterator ConstIterator
static RCP< Vector > Build(const Teuchos::RCP< const Map > &map, bool zeroOut=true)
any & getAny(bool activeQry=true)
bool isType(const std::string &name) const
Exception throws to report errors in the internal logical of the program.
ParameterEntry & getEntry(const std::string &name)
RCP< const ParameterList > GetValidParameterList() const
Return a const parameter list of valid parameters that setParameterList() will accept.
void DeclareInput(Level ¤tLevel) const
Specifies the data that this class needs, and the factories that generate that data.