46 #ifndef MUELU_ZOLTANINTERFACE_DEF_HPP 47 #define MUELU_ZOLTANINTERFACE_DEF_HPP 50 #if defined(HAVE_MUELU_ZOLTAN) && defined(HAVE_MPI) 54 #include <Teuchos_OpaqueWrapper.hpp> 59 #include "MueLu_Utilities.hpp" 63 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
68 validParamList->
set<
RCP<const FactoryBase> >(
"number of partitions", Teuchos::null,
"Instance of RepartitionHeuristicFactory.");
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>
91 size_t dim = Coords->getNumVectors();
93 int numParts = Get<int>(level,
"number of partitions");
98 Set(level,
"Partition", decomposition);
100 }
else if (numParts == -1) {
103 Set(level,
"Partition", decomposition);
107 float zoltanVersion_;
108 Zoltan_Initialize(0, NULL, &zoltanVersion_);
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)
167 ArrayRCP<GO> decompEntries = decomposition->getDataNonConst(0);
169 int mypid = rowMap->getComm()->getRank();
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;
228 LO blockSize = A->GetFixedBlockSize();
231 size_t numElements = map->getNodeNumElements();
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;
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.
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.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
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.
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.
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.
std::string toString(const T &t)
static int GetLocalNumberOfRows(void *data, int *ierr)