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_PartitioningProblem.hpp> 58 #include <Teuchos_Utils.hpp> 59 #include <Teuchos_DefaultMpiComm.hpp> 60 #include <Teuchos_OpaqueWrapper.hpp> 65 #include "MueLu_Utilities.hpp" 69 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
71 defaultZoltan2Params = rcp(
new ParameterList());
72 defaultZoltan2Params->set(
"algorithm",
"multijagged");
73 defaultZoltan2Params->set(
"partitioning_approach",
"partition");
76 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
78 RCP<ParameterList> validParamList = rcp(
new ParameterList());
80 validParamList->set<
int > (
"rowWeight", 0,
"Default weight to rows (total weight = nnz + rowWeight");
82 validParamList->set< RCP<const FactoryBase> > (
"A", Teuchos::null,
"Factory of the matrix A");
83 validParamList->set< RCP<const FactoryBase> > (
"number of partitions", Teuchos::null,
"Instance of RepartitionHeuristicFactory.");
84 validParamList->set< RCP<const FactoryBase> > (
"Coordinates", Teuchos::null,
"Factory of the coordinates");
85 validParamList->set< RCP<const ParameterList> > (
"ParameterList", Teuchos::null,
"Zoltan2 parameters");
87 return validParamList;
91 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
93 Input(currentLevel,
"A");
94 Input(currentLevel,
"number of partitions");
95 Input(currentLevel,
"Coordinates");
98 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
102 RCP<Matrix> A = Get<RCP<Matrix> >(level,
"A");
103 RCP<const Map> rowMap = A->getRowMap();
106 RCP<dMultiVector> coords = Get<RCP<dMultiVector> >(level,
"Coordinates");
107 RCP<const Map> map = coords->
getMap();
108 GO numElements = map->getNodeNumElements();
110 LO blkSize = A->GetFixedBlockSize();
113 TEUCHOS_TEST_FOR_EXCEPTION(rowMap->getNodeNumElements()/blkSize != coords->getLocalLength(),
Exceptions::Incompatible,
114 "Coordinate vector length (" +
toString(coords->getLocalLength()) <<
" is incompatible with number of block rows in A (" 115 +
toString(rowMap->getNodeNumElements()/blkSize) +
"The vector length should be the same as the number of mesh points.");
116 #ifdef HAVE_MUELU_DEBUG 117 GO indexBase = rowMap->getIndexBase();
118 GetOStream(
Runtime0) <<
"Checking consistence of row and coordinates maps" << std::endl;
120 ArrayView<const GO> rowElements = rowMap->getNodeElementList();
121 ArrayView<const GO> coordsElements = map ->getNodeElementList();
122 for (
LO i = 0; i < Teuchos::as<LO>(numElements); i++)
123 TEUCHOS_TEST_FOR_EXCEPTION((coordsElements[i]-indexBase)*blkSize + indexBase != rowElements[i*blkSize],
125 <<
", row GID = " << rowElements[i*blkSize] <<
", blkSize = " << blkSize << std::endl);
128 int numParts = Get<int>(level,
"number of partitions");
132 Set(level,
"Partition", decomposition);
134 }
else if (numParts == -1) {
136 RCP<Xpetra::Vector<GO,LO,GO,NO> > decomposition = Teuchos::null;
138 Set(level,
"Partition", decomposition);
143 const ParameterList& pL = GetParameterList();
145 RCP<const ParameterList> providedList = pL.get<RCP<const ParameterList> >(
"ParameterList");
146 ParameterList Zoltan2Params;
147 if (providedList != Teuchos::null)
148 Zoltan2Params = *providedList;
152 for (ParameterList::ConstIterator param = defaultZoltan2Params->begin(); param != defaultZoltan2Params->end(); param++) {
153 const std::string& pName = defaultZoltan2Params->name(param);
154 if (!Zoltan2Params.isParameter(pName))
155 Zoltan2Params.set(pName, defaultZoltan2Params->get<std::string>(pName));
157 Zoltan2Params.set(
"num_global_parts", Teuchos::as<int>(numParts));
159 GetOStream(
Runtime0) <<
"Zoltan2 parameters:\n----------\n" << Zoltan2Params <<
"----------" << std::endl;
161 const std::string& algo = Zoltan2Params.get<std::string>(
"algorithm");
163 "Unknown partitioning algorithm: \"" << algo <<
"\"");
165 typedef Zoltan2::XpetraMultiVectorAdapter<dMultiVector> InputAdapterType;
166 typedef Zoltan2::PartitioningProblem<InputAdapterType> ProblemType;
168 int rowWeight = pL.get<
int>(
"rowWeight");
169 GetOStream(
Runtime0) <<
"Using weights formula: nnz + " << rowWeight << std::endl;
171 Array<double> weightsPerRow(numElements);
172 for (
LO i = 0; i < numElements; i++) {
173 weightsPerRow[i] = 0.0;
175 for (
LO j = 0; j < blkSize; j++) {
176 weightsPerRow[i] += A->getNumEntriesInLocalRow(i*blkSize+j);
182 weightsPerRow[i] += rowWeight;
186 std::vector<int> strides;
187 std::vector<const double*> weights(1, weightsPerRow.getRawPtr());
189 RCP<const Teuchos::MpiComm<int> > dupMpiComm = rcp_dynamic_cast<
const Teuchos::MpiComm<int> >(rowMap->getComm()->duplicate());
190 RCP<const Teuchos::OpaqueWrapper<MPI_Comm> > zoltanComm = dupMpiComm->getRawMpiComm();
192 InputAdapterType adapter(coords, weights, strides);
193 RCP<ProblemType> problem(
new ProblemType(&adapter, &Zoltan2Params, (*zoltanComm)()));
201 ArrayRCP<GO> decompEntries = decomposition->getDataNonConst(0);
203 const typename InputAdapterType::part_t * parts = problem->getSolution().getPartListView();
205 for (
GO i = 0; i < numElements; i++) {
206 int partNum = parts[i];
208 for (
LO j = 0; j < blkSize; j++)
209 decompEntries[i*blkSize + j] = partNum;
212 Set(level,
"Partition", decomposition);
217 #endif //if defined(HAVE_MUELU_ZOLTAN2) && defined(HAVE_MPI) 219 #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.
Timer to be used in factories. Similar to Monitor but with additional timers.
Zoltan2Interface()
Constructor.
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.
Class that holds all level-specific information.
Timer to be used in factories. Similar to SubMonitor but adds a timer level by level.
virtual Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getMap() const =0
static RCP< Vector > Build(const Teuchos::RCP< const Map > &map, bool zeroOut=true)
Exception throws to report errors in the internal logical of the program.
RCP< const ParameterList > GetValidParameterList() const
Return a const parameter list of valid parameters that setParameterList() will accept.