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> 66 #include "MueLu_Utilities.hpp" 70 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
73 defaultZoltan2Params->set(
"algorithm",
"multijagged");
74 defaultZoltan2Params->set(
"partitioning_approach",
"partition");
79 defaultZoltan2Params->set(
"mj_premigration_option", 1);
82 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
87 validParamList->
set<
RCP<const FactoryBase> > (
"number of partitions", Teuchos::null,
"Instance of RepartitionHeuristicFactory.");
91 return validParamList;
95 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
97 Input(currentLevel,
"A");
98 Input(currentLevel,
"number of partitions");
104 if (providedList != Teuchos::null && providedList->
isType<std::string>(
"algorithm")) {
105 const std::string algo = providedList->
get<std::string>(
"algorithm");
106 if (algo ==
"multijagged" || algo ==
"rcb")
107 Input(currentLevel,
"Coordinates");
109 Input(currentLevel,
"Coordinates");
112 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
117 typedef typename Xpetra::MultiVector<real_type,LO,GO,NO> RealValuedMultiVector;
121 LO blkSize = A->GetFixedBlockSize();
123 int numParts = Get<int>(level,
"number of partitions");
124 if (numParts == 1 || numParts == -1) {
127 Set(level,
"Partition", decomposition);
141 if (providedList != Teuchos::null)
142 Zoltan2Params = *providedList;
147 const std::string& pName = defaultZoltan2Params->
name(param);
148 if (!Zoltan2Params.isParameter(pName))
149 Zoltan2Params.setEntry(pName, defaultZoltan2Params->getEntry(pName));
151 Zoltan2Params.set(
"num_global_parts", Teuchos::as<int>(numParts));
153 GetOStream(
Runtime0) <<
"Zoltan2 parameters:\n----------\n" << Zoltan2Params <<
"----------" << std::endl;
155 const std::string& algo = Zoltan2Params.
get<std::string>(
"algorithm");
157 if (algo ==
"multijagged" || algo ==
"rcb") {
161 GO numElements = map->getNodeNumElements();
165 "Coordinate vector length (" +
toString(coords->getLocalLength()) <<
" is incompatible with number of block rows in A (" 166 +
toString(rowMap->getNodeNumElements()/blkSize) +
"The vector length should be the same as the number of mesh points.");
167 #ifdef HAVE_MUELU_DEBUG 168 GO indexBase = rowMap->getIndexBase();
169 GetOStream(
Runtime0) <<
"Checking consistence of row and coordinates maps" << std::endl;
173 for (LO i = 0; i < Teuchos::as<LO>(numElements); i++)
176 <<
", row GID = " << rowElements[i*blkSize] <<
", blkSize = " << blkSize << std::endl);
179 typedef Zoltan2::XpetraMultiVectorAdapter<RealValuedMultiVector> InputAdapterType;
180 typedef Zoltan2::PartitioningProblem<InputAdapterType> ProblemType;
183 for (LO i = 0; i < numElements; i++) {
184 weightsPerRow[i] = 0.0;
186 for (LO j = 0; j < blkSize; j++) {
187 weightsPerRow[i] += A->getNumEntriesInLocalRow(i*blkSize+j);
191 std::vector<int> strides;
192 std::vector<const double*> weights(1, weightsPerRow.
getRawPtr());
197 InputAdapterType adapter(coords, weights, strides);
198 RCP<ProblemType> problem(
new ProblemType(&adapter, &Zoltan2Params, (*zoltanComm)()));
206 ArrayRCP<GO> decompEntries = decomposition->getDataNonConst(0);
208 const typename InputAdapterType::part_t * parts = problem->getSolution().getPartListView();
210 for (GO i = 0; i < numElements; i++) {
211 int partNum = parts[i];
213 for (LO j = 0; j < blkSize; j++)
214 decompEntries[i*blkSize + j] = partNum;
217 Set(level,
"Partition", decomposition);
221 GO numElements = rowMap->getNodeNumElements();
223 typedef Zoltan2::XpetraCrsGraphAdapter<CrsGraph> InputAdapterType;
224 typedef Zoltan2::PartitioningProblem<InputAdapterType> ProblemType;
229 InputAdapterType adapter(A->getCrsGraph());
230 RCP<ProblemType> problem(
new ProblemType(&adapter, &Zoltan2Params, (*zoltanComm)()));
238 ArrayRCP<GO> decompEntries = decomposition->getDataNonConst(0);
240 const typename InputAdapterType::part_t * parts = problem->getSolution().getPartListView();
242 for (GO i = 0; i < numElements; i++) {
243 int partNum = parts[i];
245 for (LO j = 0; j < blkSize; j++)
246 decompEntries[i*blkSize + j] = partNum;
249 Set(level,
"Partition", decomposition);
255 #endif //if defined(HAVE_MUELU_ZOLTAN2) && defined(HAVE_MPI) 257 #endif // MUELU_ZOLTAN2INTERFACE_DEF_HPP
void DeclareInput(Level ¤tLevel) const
Specifies the data that this class needs, and the factories that generate that data.
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.
Namespace for MueLu classes and methods.
Exception throws to report incompatible objects (like maps).
void Build(Level ¤tLevel) const
Build an object with this factory.
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
bool isType(const std::string &name) const
const std::string & name() const
any & getAny(bool activeQry=true)
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.