46 #ifndef MUELU_ZOLTANINTERFACE_DEF_HPP 47 #define MUELU_ZOLTANINTERFACE_DEF_HPP 50 #if defined(HAVE_MUELU_ZOLTAN) && defined(HAVE_MPI) 52 #include <Teuchos_Utils.hpp> 53 #include <Teuchos_DefaultMpiComm.hpp> 54 #include <Teuchos_OpaqueWrapper.hpp> 59 #include "MueLu_Utilities.hpp" 63 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
65 RCP<ParameterList> validParamList = rcp(
new ParameterList());
67 validParamList->set< RCP<const FactoryBase> >(
"A", Teuchos::null,
"Factory of the matrix A");
68 validParamList->set< RCP<const FactoryBase> >(
"number of partitions", Teuchos::null,
"Instance of RepartitionHeuristicFactory.");
69 validParamList->set< RCP<const FactoryBase> >(
"Coordinates", Teuchos::null,
"Factory of the coordinates");
71 return validParamList;
75 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
77 Input(currentLevel,
"A");
78 Input(currentLevel,
"number of partitions");
79 Input(currentLevel,
"Coordinates");
82 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
86 RCP<Matrix> A = Get< RCP<Matrix> > (level,
"A");
87 RCP<const Map> rowMap = A->getRowMap();
90 RCP<double_multivector_type> Coords = Get< RCP<double_multivector_type> >(level,
"Coordinates");
93 int numParts = Get<int>(level,
"number of partitions");
98 Set(level,
"Partition", decomposition);
100 }
else if (numParts == -1) {
102 RCP<Xpetra::Vector<GO,LO,GO,NO> > decomposition = Teuchos::null;
103 Set(level,
"Partition", decomposition);
107 float zoltanVersion_;
108 Zoltan_Initialize(0, NULL, &zoltanVersion_);
110 RCP<const Teuchos::MpiComm<int> > dupMpiComm = rcp_dynamic_cast<
const Teuchos::MpiComm<int> >(rowMap->getComm()->duplicate());
111 RCP<const Teuchos::OpaqueWrapper<MPI_Comm> > zoltanComm = dupMpiComm->getRawMpiComm();
113 RCP<Zoltan> zoltanObj_ = rcp(
new Zoltan((*zoltanComm)()));
114 if (zoltanObj_ == Teuchos::null)
121 if ((rv = zoltanObj_->Set_Param(
"num_gid_entries",
"1")) != ZOLTAN_OK)
123 if ((rv = zoltanObj_->Set_Param(
"num_lid_entries",
"0") ) != ZOLTAN_OK)
125 if ((rv = zoltanObj_->Set_Param(
"obj_weight_dim",
"1") ) != ZOLTAN_OK)
128 if (GetVerbLevel() &
Statistics1) zoltanObj_->Set_Param(
"debug_level",
"1");
129 else zoltanObj_->Set_Param(
"debug_level",
"0");
131 zoltanObj_->Set_Param(
"num_global_partitions",
toString(numParts));
133 zoltanObj_->Set_Num_Obj_Fn(GetLocalNumberOfRows, (
void *) &*A);
134 zoltanObj_->Set_Obj_List_Fn(GetLocalNumberOfNonzeros, (
void *) &*A);
135 zoltanObj_->Set_Num_Geom_Fn(GetProblemDimension, (
void *) &dim);
136 zoltanObj_->Set_Geom_Multi_Fn(GetProblemGeometry, (
void *) Coords.get());
139 ZOLTAN_ID_PTR import_gids = NULL;
140 ZOLTAN_ID_PTR import_lids = NULL;
141 int *import_procs = NULL;
142 int *import_to_part = NULL;
143 ZOLTAN_ID_PTR export_gids = NULL;
144 ZOLTAN_ID_PTR export_lids = NULL;
145 int *export_procs = NULL;
146 int *export_to_part = NULL;
155 rv = zoltanObj_->LB_Partition(newDecomp, num_gid_entries, num_lid_entries,
156 num_imported, import_gids, import_lids, import_procs, import_to_part,
157 num_exported, export_gids, export_lids, export_procs, export_to_part);
158 if (rv == ZOLTAN_FATAL)
164 RCP<Xpetra::Vector<GO, LO, GO, NO> > decomposition;
167 ArrayRCP<GO> decompEntries = decomposition->getDataNonConst(0);
169 int mypid = rowMap->getComm()->getRank();
170 for (
typename ArrayRCP<GO>::iterator i = decompEntries.begin(); i != decompEntries.end(); ++i)
173 LO blockSize = A->GetFixedBlockSize();
174 for (
int i = 0; i < num_exported; ++i) {
177 LO localEl = rowMap->getLocalElement(export_gids[i]);
178 int partNum = export_to_part[i];
179 for (
LO j = 0; j < blockSize; ++j)
180 decompEntries[localEl + j] = partNum;
184 Set(level,
"Partition", decomposition);
186 zoltanObj_->LB_Free_Part(&import_gids, &import_lids, &import_procs, &import_to_part);
187 zoltanObj_->LB_Free_Part(&export_gids, &export_lids, &export_procs, &export_to_part);
195 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
198 *ierr = ZOLTAN_FATAL;
201 Matrix *A = (Matrix*) data;
204 LO blockSize = A->GetFixedBlockSize();
207 return A->getRowMap()->getNodeNumElements() / blockSize;
214 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
217 ZOLTAN_ID_PTR lids,
int wgtDim,
float *weights,
int *ierr) {
218 if (data == NULL || NumGidEntries < 1) {
219 *ierr = ZOLTAN_FATAL;
225 Matrix *A = (Matrix*) data;
226 RCP<const Map> map = A->getRowMap();
228 LO blockSize = A->GetFixedBlockSize();
231 size_t numElements = map->getNodeNumElements();
232 ArrayView<const GO> mapGIDs = map->getNodeElementList();
234 if (blockSize == 1) {
235 for (
size_t i = 0; i < numElements; i++) {
236 gids[i] = as<ZOLTAN_ID_TYPE>(mapGIDs[i]);
237 weights[i] = A->getNumEntriesInLocalRow(i);
241 LO numBlockElements = numElements / blockSize;
243 for (
LO i = 0; i < numBlockElements; i++) {
246 gids[i] = as<ZOLTAN_ID_TYPE>(mapGIDs[i*blockSize]);
248 for (
LO j = 0; j < blockSize; j++)
249 weights[i] += A->getNumEntriesInLocalRow(i*blockSize+j);
259 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
263 int dim = *((
int*)data);
273 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
276 ZOLTAN_ID_PTR gids, ZOLTAN_ID_PTR lids,
int dim,
double *coordinates,
int *ierr)
279 *ierr = ZOLTAN_FATAL;
284 double_multivector_type *Coords = (double_multivector_type*) data;
286 if (dim != Teuchos::as<int>(Coords->getNumVectors())) {
288 *ierr = ZOLTAN_FATAL;
292 TEUCHOS_TEST_FOR_EXCEPTION(numObjectIDs != Teuchos::as<int>(Coords->getLocalLength()),
Exceptions::Incompatible,
"Length of coordinates must be the same as the number of objects");
294 ArrayRCP<ArrayRCP<const double> > CoordsData(dim);
295 for (
int j = 0; j < dim; ++j)
296 CoordsData[j] = Coords->getData(j);
298 size_t numElements = Coords->getLocalLength();
299 for (
size_t i = 0; i < numElements; ++i)
300 for (
int j = 0; j < dim; ++j)
301 coordinates[i*dim+j] = (
double) CoordsData[j][i];
309 #endif //if defined(HAVE_MUELU_ZOLTAN) && defined(HAVE_MPI) 311 #endif // MUELU_ZOLTANINTERFACE_DEF_HPP
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.
static int GetProblemDimension(void *data, int *ierr)
Namespace for MueLu classes and methods.
static void GetProblemGeometry(void *data, int numGIDEntries, int numLIDEntries, int numObjectIDs, ZOLTAN_ID_PTR gids, ZOLTAN_ID_PTR lids, int dim, double *coordinates, int *ierr)
Exception throws to report incompatible objects (like maps).
RCP< const ParameterList > GetValidParameterList() const
Return a const parameter list of valid parameters that setParameterList() will accept.
Class that holds all level-specific information.
Timer to be used in factories. Similar to SubMonitor but adds a timer level by level.
static void GetLocalNumberOfNonzeros(void *data, int NumGidEntries, int NumLidEntries, ZOLTAN_ID_PTR gids, ZOLTAN_ID_PTR lids, int wgtDim, float *weights, int *ierr)
void Build(Level &level) const
Build an object with this factory.
void DeclareInput(Level &level) const
Specifies the data that this class needs, and the factories that generate that data.
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.
virtual size_t getNumVectors() const=0
static int GetLocalNumberOfRows(void *data, int *ierr)