10 #ifndef MUELU_ZOLTANINTERFACE_DEF_HPP
11 #define MUELU_ZOLTANINTERFACE_DEF_HPP
14 #if defined(HAVE_MUELU_ZOLTAN) && defined(HAVE_MPI)
18 #include <Teuchos_OpaqueWrapper.hpp>
26 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
31 validParamList->
set<
RCP<const FactoryBase> >(
"number of partitions", Teuchos::null,
"Instance of RepartitionHeuristicFactory.");
34 return validParamList;
37 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
39 Input(currentLevel,
"A");
40 Input(currentLevel,
"number of partitions");
41 Input(currentLevel,
"Coordinates");
44 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
51 if (bA != Teuchos::null) {
55 rowMap = bRowMap->getFullMap();
57 rowMap = A->getRowMap();
62 size_t dim = Coords->getNumVectors();
63 int numParts = Get<int>(level,
"number of partitions");
65 if (numParts == 1 || numParts == -1) {
68 Set(level,
"Partition", decomposition);
70 }
else if (numParts == -1) {
73 Set(level,
"Partition", decomposition);
78 Zoltan_Initialize(0, NULL, &zoltanVersion_);
84 if (zoltanObj_ == Teuchos::null)
91 if ((rv = zoltanObj_->Set_Param(
"num_gid_entries",
"1")) != ZOLTAN_OK)
93 if ((rv = zoltanObj_->Set_Param(
"num_lid_entries",
"0")) != ZOLTAN_OK)
95 if ((rv = zoltanObj_->Set_Param(
"obj_weight_dim",
"1")) != ZOLTAN_OK)
99 zoltanObj_->Set_Param(
"debug_level",
"1");
101 zoltanObj_->Set_Param(
"debug_level",
"0");
103 zoltanObj_->Set_Param(
"num_global_partitions",
toString(numParts));
105 zoltanObj_->Set_Num_Obj_Fn(GetLocalNumberOfRows, (
void *)A.
getRawPtr());
106 zoltanObj_->Set_Obj_List_Fn(GetLocalNumberOfNonzeros, (
void *)A.
getRawPtr());
107 zoltanObj_->Set_Num_Geom_Fn(GetProblemDimension, (
void *)&dim);
108 zoltanObj_->Set_Geom_Multi_Fn(GetProblemGeometry, (
void *)Coords.
get());
111 ZOLTAN_ID_PTR import_gids = NULL;
112 ZOLTAN_ID_PTR import_lids = NULL;
113 int *import_procs = NULL;
114 int *import_to_part = NULL;
115 ZOLTAN_ID_PTR export_gids = NULL;
116 ZOLTAN_ID_PTR export_lids = NULL;
117 int *export_procs = NULL;
118 int *export_to_part = NULL;
127 rv = zoltanObj_->LB_Partition(newDecomp, num_gid_entries, num_lid_entries,
128 num_imported, import_gids, import_lids, import_procs, import_to_part,
129 num_exported, export_gids, export_lids, export_procs, export_to_part);
130 if (rv == ZOLTAN_FATAL)
139 ArrayRCP<GO> decompEntries = decomposition->getDataNonConst(0);
141 int mypid = rowMap->getComm()->getRank();
145 LO blockSize = A->GetFixedBlockSize();
146 for (
int i = 0; i < num_exported; ++i) {
149 LO localEl = rowMap->getLocalElement(export_gids[i]);
150 int partNum = export_to_part[i];
151 for (
LO j = 0; j < blockSize; ++j)
152 decompEntries[localEl + j] = partNum;
156 Set(level,
"Partition", decomposition);
158 zoltanObj_->LB_Free_Part(&import_gids, &import_lids, &import_procs, &import_to_part);
159 zoltanObj_->LB_Free_Part(&export_gids, &export_lids, &export_procs, &export_to_part);
167 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
170 *ierr = ZOLTAN_FATAL;
173 Matrix *A = (Matrix *)data;
176 LO blockSize = A->GetFixedBlockSize();
179 return A->getRowMap()->getLocalNumElements() / blockSize;
186 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
189 ZOLTAN_ID_PTR ,
int ,
float *weights,
int *ierr) {
190 if (data == NULL || NumGidEntries < 1) {
191 *ierr = ZOLTAN_FATAL;
197 Matrix *A = (Matrix *)data;
200 LO blockSize = A->GetFixedBlockSize();
203 size_t numElements = map->getLocalNumElements();
206 if (blockSize == 1) {
207 for (
size_t i = 0; i < numElements; i++) {
208 gids[i] = as<ZOLTAN_ID_TYPE>(mapGIDs[i]);
209 weights[i] = A->getNumEntriesInLocalRow(i);
213 LO numBlockElements = numElements / blockSize;
215 for (
LO i = 0; i < numBlockElements; i++) {
218 gids[i] = as<ZOLTAN_ID_TYPE>(mapGIDs[i * blockSize]);
220 for (
LO j = 0; j < blockSize; j++)
221 weights[i] += A->getNumEntriesInLocalRow(i * blockSize + j);
230 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
233 int dim = *((
int *)data);
243 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
246 ZOLTAN_ID_PTR , ZOLTAN_ID_PTR ,
int dim,
double *coordinates,
int *ierr) {
248 *ierr = ZOLTAN_FATAL;
253 double_multivector_type *Coords = (double_multivector_type *)data;
255 if (dim != Teuchos::as<int>(Coords->getNumVectors())) {
257 *ierr = ZOLTAN_FATAL;
264 for (
int j = 0; j < dim; ++j)
265 CoordsData[j] = Coords->getData(j);
267 size_t numElements = Coords->getLocalLength();
268 for (
size_t i = 0; i < numElements; ++i)
269 for (
int j = 0; j < dim; ++j)
270 coordinates[i * dim + j] = (
double)CoordsData[j][i];
278 #endif // if defined(HAVE_MUELU_ZOLTAN) && defined(HAVE_MPI)
280 #endif // MUELU_ZOLTANINTERFACE_DEF_HPP
MueLu::DefaultLocalOrdinal LocalOrdinal
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.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
static int GetProblemDimension(void *data, int *ierr)
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
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).
void Build(Level &level) const
Build an object with this factory.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
MueLu::DefaultGlobalOrdinal GlobalOrdinal
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 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.
RCP< const ParameterList > GetValidParameterList() const
Return a const parameter list of valid parameters that setParameterList() will accept.
std::string toString(const T &t)
static int GetLocalNumberOfRows(void *data, int *ierr)