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>
62 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
67 validParamList->
set<
RCP<const FactoryBase> >(
"number of partitions", Teuchos::null,
"Instance of RepartitionHeuristicFactory.");
70 return validParamList;
73 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
75 Input(currentLevel,
"A");
76 Input(currentLevel,
"number of partitions");
77 Input(currentLevel,
"Coordinates");
80 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
87 if (bA != Teuchos::null) {
91 rowMap = bRowMap->getFullMap();
93 rowMap = A->getRowMap();
98 size_t dim = Coords->getNumVectors();
99 int numParts = Get<int>(level,
"number of partitions");
101 if (numParts == 1 || numParts == -1) {
104 Set(level,
"Partition", decomposition);
106 }
else if (numParts == -1) {
109 Set(level,
"Partition", decomposition);
113 float zoltanVersion_;
114 Zoltan_Initialize(0, NULL, &zoltanVersion_);
120 if (zoltanObj_ == Teuchos::null)
127 if ((rv = zoltanObj_->Set_Param(
"num_gid_entries",
"1")) != ZOLTAN_OK)
129 if ((rv = zoltanObj_->Set_Param(
"num_lid_entries",
"0")) != ZOLTAN_OK)
131 if ((rv = zoltanObj_->Set_Param(
"obj_weight_dim",
"1")) != ZOLTAN_OK)
135 zoltanObj_->Set_Param(
"debug_level",
"1");
137 zoltanObj_->Set_Param(
"debug_level",
"0");
139 zoltanObj_->Set_Param(
"num_global_partitions",
toString(numParts));
141 zoltanObj_->Set_Num_Obj_Fn(GetLocalNumberOfRows, (
void *)A.
getRawPtr());
142 zoltanObj_->Set_Obj_List_Fn(GetLocalNumberOfNonzeros, (
void *)A.
getRawPtr());
143 zoltanObj_->Set_Num_Geom_Fn(GetProblemDimension, (
void *)&dim);
144 zoltanObj_->Set_Geom_Multi_Fn(GetProblemGeometry, (
void *)Coords.
get());
147 ZOLTAN_ID_PTR import_gids = NULL;
148 ZOLTAN_ID_PTR import_lids = NULL;
149 int *import_procs = NULL;
150 int *import_to_part = NULL;
151 ZOLTAN_ID_PTR export_gids = NULL;
152 ZOLTAN_ID_PTR export_lids = NULL;
153 int *export_procs = NULL;
154 int *export_to_part = NULL;
163 rv = zoltanObj_->LB_Partition(newDecomp, num_gid_entries, num_lid_entries,
164 num_imported, import_gids, import_lids, import_procs, import_to_part,
165 num_exported, export_gids, export_lids, export_procs, export_to_part);
166 if (rv == ZOLTAN_FATAL)
175 ArrayRCP<GO> decompEntries = decomposition->getDataNonConst(0);
177 int mypid = rowMap->getComm()->getRank();
181 LO blockSize = A->GetFixedBlockSize();
182 for (
int i = 0; i < num_exported; ++i) {
185 LO localEl = rowMap->getLocalElement(export_gids[i]);
186 int partNum = export_to_part[i];
187 for (
LO j = 0; j < blockSize; ++j)
188 decompEntries[localEl + j] = partNum;
192 Set(level,
"Partition", decomposition);
194 zoltanObj_->LB_Free_Part(&import_gids, &import_lids, &import_procs, &import_to_part);
195 zoltanObj_->LB_Free_Part(&export_gids, &export_lids, &export_procs, &export_to_part);
203 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
206 *ierr = ZOLTAN_FATAL;
209 Matrix *A = (Matrix *)data;
212 LO blockSize = A->GetFixedBlockSize();
215 return A->getRowMap()->getLocalNumElements() / blockSize;
222 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
225 ZOLTAN_ID_PTR ,
int ,
float *weights,
int *ierr) {
226 if (data == NULL || NumGidEntries < 1) {
227 *ierr = ZOLTAN_FATAL;
233 Matrix *A = (Matrix *)data;
236 LO blockSize = A->GetFixedBlockSize();
239 size_t numElements = map->getLocalNumElements();
242 if (blockSize == 1) {
243 for (
size_t i = 0; i < numElements; i++) {
244 gids[i] = as<ZOLTAN_ID_TYPE>(mapGIDs[i]);
245 weights[i] = A->getNumEntriesInLocalRow(i);
249 LO numBlockElements = numElements / blockSize;
251 for (
LO i = 0; i < numBlockElements; i++) {
254 gids[i] = as<ZOLTAN_ID_TYPE>(mapGIDs[i * blockSize]);
256 for (
LO j = 0; j < blockSize; j++)
257 weights[i] += A->getNumEntriesInLocalRow(i * blockSize + j);
266 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
269 int dim = *((
int *)data);
279 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
282 ZOLTAN_ID_PTR , ZOLTAN_ID_PTR ,
int dim,
double *coordinates,
int *ierr) {
284 *ierr = ZOLTAN_FATAL;
289 double_multivector_type *Coords = (double_multivector_type *)data;
291 if (dim != Teuchos::as<int>(Coords->getNumVectors())) {
293 *ierr = ZOLTAN_FATAL;
300 for (
int j = 0; j < dim; ++j)
301 CoordsData[j] = Coords->getData(j);
303 size_t numElements = Coords->getLocalLength();
304 for (
size_t i = 0; i < numElements; ++i)
305 for (
int j = 0; j < dim; ++j)
306 coordinates[i * dim + j] = (
double)CoordsData[j][i];
314 #endif // if defined(HAVE_MUELU_ZOLTAN) && defined(HAVE_MPI)
316 #endif // MUELU_ZOLTANINTERFACE_DEF_HPP
MueLu::DefaultLocalOrdinal LocalOrdinal
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)
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)