46 #ifndef MUELU_ZOLTAN2INTERFACE_DEF_HPP
47 #define MUELU_ZOLTAN2INTERFACE_DEF_HPP
53 #if defined(HAVE_MUELU_ZOLTAN2) && defined(HAVE_MPI)
55 #include <Zoltan2_XpetraMultiVectorAdapter.hpp>
56 #include <Zoltan2_XpetraCrsGraphAdapter.hpp>
57 #include <Zoltan2_PartitioningProblem.hpp>
61 #include <Teuchos_OpaqueWrapper.hpp>
69 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
72 defaultZoltan2Params->set(
"algorithm",
"multijagged");
73 defaultZoltan2Params->set(
"partitioning_approach",
"partition");
78 defaultZoltan2Params->set(
"mj_premigration_option", 1);
81 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
86 validParamList->
set<
RCP<const FactoryBase> >(
"number of partitions", Teuchos::null,
"Instance of RepartitionHeuristicFactory.");
89 validParamList->
set<
RCP<const FactoryBase> >(
"repartition: heuristic target rows per process", Teuchos::null,
"Factory for number of rows per process to use with MultiJagged");
91 return validParamList;
94 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
96 Input(currentLevel,
"A");
97 Input(currentLevel,
"number of partitions");
103 if (providedList != Teuchos::null && providedList->
isType<std::string>(
"algorithm")) {
104 const std::string algo = providedList->
get<std::string>(
"algorithm");
105 if (algo ==
"multijagged") {
106 Input(currentLevel,
"Coordinates");
107 Input(currentLevel,
"repartition: heuristic target rows per process");
108 }
else if (algo ==
"rcb") {
109 Input(currentLevel,
"Coordinates");
112 Input(currentLevel,
"repartition: heuristic target rows per process");
113 Input(currentLevel,
"Coordinates");
117 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
126 LO blkSize = A->GetFixedBlockSize();
128 int numParts = Get<int>(level,
"number of partitions");
129 if (numParts == 1 || numParts == -1) {
132 Set(level,
"Partition", decomposition);
146 if (providedList != Teuchos::null)
147 Zoltan2Params = *providedList;
152 const std::string& pName = defaultZoltan2Params->
name(param);
153 if (!Zoltan2Params.isParameter(pName))
154 Zoltan2Params.setEntry(pName, defaultZoltan2Params->getEntry(pName));
156 Zoltan2Params.set(
"num_global_parts", Teuchos::as<int>(numParts));
158 GetOStream(
Runtime0) <<
"Zoltan2 parameters:\n----------\n"
159 << Zoltan2Params <<
"----------" << std::endl;
161 const std::string& algo = Zoltan2Params.
get<std::string>(
"algorithm");
163 if (algo ==
"multijagged" || algo ==
"rcb") {
166 GO numElements = map->getLocalNumElements();
170 "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.");
171 #ifdef HAVE_MUELU_DEBUG
172 GO indexBase = rowMap->getIndexBase();
173 GetOStream(
Runtime0) <<
"Checking consistence of row and coordinates maps" << std::endl;
177 for (
LO i = 0; i < Teuchos::as<LO>(numElements); i++)
179 Exceptions::RuntimeError,
"i = " << i <<
", coords GID = " << coordsElements[i] <<
", row GID = " << rowElements[i * blkSize] <<
", blkSize = " << blkSize << std::endl);
182 typedef Zoltan2::XpetraMultiVectorAdapter<RealValuedMultiVector> InputAdapterType;
183 typedef Zoltan2::PartitioningProblem<InputAdapterType> ProblemType;
186 for (
LO i = 0; i < numElements; i++) {
187 weightsPerRow[i] = 0.0;
189 for (
LO j = 0; j < blkSize; j++) {
190 weightsPerRow[i] += A->getNumEntriesInLocalRow(i * blkSize + j);
195 if (algo ==
"multijagged" && !Zoltan2Params.isParameter(
"mj_premigration_coordinate_count")) {
196 LO heuristicTargetRowsPerProcess = Get<LO>(level,
"repartition: heuristic target rows per process");
197 Zoltan2Params.set(
"mj_premigration_coordinate_count", heuristicTargetRowsPerProcess);
199 const bool writeZoltan2DebuggingFiles = Zoltan2Params.
get(
"mj_debug",
false);
200 Zoltan2Params.remove(
"mj_debug");
202 std::vector<int> strides;
203 std::vector<const real_type*> weights(1, weightsPerRow.
getRawPtr());
208 InputAdapterType adapter(coords, weights, strides);
209 RCP<ProblemType> problem(
new ProblemType(&adapter, &Zoltan2Params, (*zoltanComm)()));
213 if (writeZoltan2DebuggingFiles)
214 adapter.generateFiles((
"mj_debug.lvl_" + std::to_string(level.GetLevelID())).c_str(), *(rowMap->getComm()));
219 ArrayRCP<GO> decompEntries = decomposition->getDataNonConst(0);
221 const typename InputAdapterType::part_t* parts = problem->getSolution().getPartListView();
223 for (
GO i = 0; i < numElements; i++) {
224 int partNum = parts[i];
226 for (
LO j = 0; j < blkSize; j++)
227 decompEntries[i * blkSize + j] = partNum;
230 Set(level,
"Partition", decomposition);
233 GO numElements = rowMap->getLocalNumElements();
235 typedef Zoltan2::XpetraCrsGraphAdapter<CrsGraph> InputAdapterType;
236 typedef Zoltan2::PartitioningProblem<InputAdapterType> ProblemType;
241 InputAdapterType adapter(A->getCrsGraph());
242 RCP<ProblemType> problem(
new ProblemType(&adapter, &Zoltan2Params, (*zoltanComm)()));
250 ArrayRCP<GO> decompEntries = decomposition->getDataNonConst(0);
252 const typename InputAdapterType::part_t* parts = problem->getSolution().getPartListView();
255 for (
GO i = 0; i < numElements / blkSize; i++) {
256 int partNum = parts[i * blkSize];
258 for (
LO j = 0; j < blkSize; j++)
259 decompEntries[i * blkSize + j] = partNum;
262 Set(level,
"Partition", decomposition);
268 #endif // if defined(HAVE_MUELU_ZOLTAN2) && defined(HAVE_MPI)
270 #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)
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
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.
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.