56 #include <Tpetra_MultiVector.hpp>
79 "simple",
"phg",
"0",
"2",
80 "simple",
"rcb",
"0",
"2",
81 "vwgt2",
"rcb",
"2",
"2",
83 "bug",
"rcb",
"1",
"3",
84 "drake",
"rcb",
"0",
"3",
85 "onedbug",
"rcb",
"0",
"3",
86 "simple",
"rcb",
"0",
"3",
87 "vwgt",
"rcb",
"1",
"3",
88 "vwgt",
"phg",
"1",
"3",
89 "vwgt2",
"rcb",
"2",
"3",
91 "simple",
"default",
"0",
"4",
92 "ewgt",
"hsfc",
"0",
"4",
93 "grid20x19",
"hsfc",
"0",
"4",
94 "grid20x19",
"hsfc",
"0",
"4",
95 "grid20x19",
"hsfc",
"0",
"4",
96 "nograph",
"rib",
"0",
"4",
97 "nograph",
"phg",
"0",
"4",
98 "simple",
"rib",
"0",
"4",
99 "simple",
"rib",
"0",
"4",
100 "vwgt2",
"rib",
"2",
"4",
101 "simple",
"rib",
"0",
"4",
102 "simple",
"phg",
"0",
"4",
104 "brack2_3",
"rcb",
"3",
"5",
106 "hammond2",
"rcb",
"2",
"6",
107 "degenerateAA",
"rcb",
"0",
"6",
108 "degenerate",
"rcb",
"0",
"6",
109 "degenerate",
"rcb",
"0",
"6",
111 "hammond",
"rcb",
"0",
"8",
112 "hammond",
"phg",
"0",
"8",
113 "vwgt2",
"rcb",
"2",
"8"
116 typedef Tpetra::CrsGraph<zlno_t, zgno_t, znode_t>
tGraph_t;
117 typedef Tpetra::CrsMatrix<zscalar_t, zlno_t, zgno_t, znode_t>
tMatrix_t;
118 typedef Tpetra::MultiVector<zscalar_t, zlno_t, zgno_t, znode_t>
tMVector_t;
125 #define SET_ZID(n,a,b) \
126 {int ZOLTAN_ID_LOOP; \
127 for (ZOLTAN_ID_LOOP = 0; ZOLTAN_ID_LOOP < (n); ZOLTAN_ID_LOOP++) \
128 (a)[ZOLTAN_ID_LOOP] = (b)[ZOLTAN_ID_LOOP]; \
139 return vec->getLocalLength();
142 static void zobjlist(
void *data,
int ngid,
int nlid,
143 ZOLTAN_ID_PTR gids, ZOLTAN_ID_PTR lids,
144 int nwgts,
float *wgts,
int *ierr)
148 size_t n = vec->getLocalLength();
150 for (
size_t i = 0; i < n; i++) {
151 zgno_t vgid = vec->getMap()->getGlobalElement(i);
152 ZOLTAN_ID_PTR vgidptr = (ZOLTAN_ID_PTR) &vgid;
157 for (
int w = 0; w < nwgts; w++) {
158 ArrayRCP<const zscalar_t> wvec = vec->getData(w);
159 for (
size_t i = 0; i < n; i++)
160 wgts[i*nwgts+w] = wvec[i];
168 return cvec->getNumVectors();
171 static void zgeom(
void *data,
int ngid,
int nlid,
int nobj,
172 ZOLTAN_ID_PTR gids, ZOLTAN_ID_PTR lids,
173 int ndim,
double *coords,
int *ierr)
177 for (
int d = 0; d < ndim; d++) {
178 ArrayRCP<const zscalar_t> cvec = vec->getData(d);
179 for (
int i = 0; i < nobj; i++) {
180 coords[lids[i]*ndim+d] = cvec[lids[i]];
185 static void zhgsize(
void *data,
int *nLists,
int *nPins,
int *format,
int *ierr)
188 *nLists = matrix->getLocalNumRows();
189 *nPins = matrix->getLocalNumEntries();
190 *format = ZOLTAN_COMPRESSED_VERTEX;
194 static void zhg(
void *data,
int ngid,
int nLists,
int nPins,
int format,
195 ZOLTAN_ID_PTR listGids,
int *offsets, ZOLTAN_ID_PTR pinGids,
199 RCP<const tGraph_t> graph = matrix->getCrsGraph();
200 zlno_t nrows = graph->getLocalNumRows();
203 for (
zlno_t i = 0; i < nrows; i++) {
205 zgno_t tmp = graph->getRowMap()->getGlobalElement(i);
206 ZOLTAN_ID_PTR ztmp = (ZOLTAN_ID_PTR) &tmp;
209 size_t nEntries = graph->getNumEntriesInLocalRow(i);
210 offsets[i+1] = offsets[i] + nEntries;
213 typename tMatrix_t::local_inds_host_view_type colind;
214 graph->getLocalRowView(i, colind);
216 for (
size_t j = 0; j < nEntries; j++) {
217 tmp = graph->getColMap()->getGlobalElement(colind[j]);
218 ztmp = (ZOLTAN_ID_PTR) &tmp;
219 SET_ZID(znGidEnt, &(pinGids[(offsets[i]+j)*znGidEnt]), ztmp);
230 const RCP<
const Comm<int> > &comm,
233 std::string *thisTest
236 #ifdef HAVE_ZOLTAN2_MPI
238 const Teuchos::MpiComm<int> *tmpicomm =
239 dynamic_cast<const Teuchos::MpiComm<int> *
>(comm.getRawPtr());
240 MPI_Comm mpiComm = *(tmpicomm->getRawMpiComm());
243 int me = comm->getRank();
244 int np = comm->getSize();
245 double tolerance = 1.05;
258 catch(std::exception &e){
260 std::cout <<
"Test " << testCnt <<
": FAIL: UserInputForTests "
261 << e.what() << std::endl;
265 RCP<tMatrix_t> matrix;
269 catch(std::exception &e){
271 std::cout <<
"Test " << testCnt <<
": FAIL: get matrix "
272 << e.what() << std::endl;
276 RCP<const tMatrix_t> matrixConst = rcp_const_cast<
const tMatrix_t>(matrix);
278 RCP<tMVector_t> coords;
282 catch(std::exception &e){
284 std::cout <<
"Test " << testCnt <<
": FAIL: get coordinates "
285 << e.what() << std::endl;
293 catch(std::exception &e){
295 std::cout <<
"Test " << testCnt <<
": FAIL: get weights "
296 << e.what() << std::endl;
302 std::cout <<
"Test " << testCnt <<
" filename = "
304 std::cout <<
"Test " << testCnt <<
" num processors = "
306 std::cout <<
"Test " << testCnt <<
" zoltan method = "
308 std::cout <<
"Test " << testCnt <<
" num_global_parts = "
309 << numGlobalParts << std::endl;
310 std::cout <<
"Test " << testCnt <<
" imbalance_tolerance = "
311 << tolerance << std::endl;
312 std::cout <<
"Test " << testCnt <<
" num weights per ID = "
313 << nWeights << std::endl;
320 if (me == 0) std::cout <<
"Calling Zoltan directly" << std::endl;
322 # ifdef HAVE_ZOLTAN2_MPI
332 zz.Set_Param(
"NUM_GID_ENTRIES", tmp);
333 sprintf(tmp,
"%d", numGlobalParts);
334 zz.Set_Param(
"NUM_GLOBAL_PARTS", tmp);
335 sprintf(tmp,
"%d", nWeights);
336 zz.Set_Param(
"OBJ_WEIGHT_DIM", tmp);
337 sprintf(tmp,
"%f", tolerance);
338 zz.Set_Param(
"IMBALANCE_TOL", tmp);
339 zz.Set_Param(
"RETURN_LISTS",
"PART");
340 zz.Set_Param(
"FINAL_OUTPUT",
"1");
341 zz.Set_Param(
"SEED",
"1111");
342 zz.Set_Param(
"LB_APPROACH",
"PARTITION");
344 zz.Set_Num_Obj_Fn(
znumobj, (
void *) coords.getRawPtr());
346 zz.Set_Obj_List_Fn(
zobjlist, (
void *) weights.getRawPtr());
348 zz.Set_Obj_List_Fn(
zobjlist, (
void *) coords.getRawPtr());
349 zz.Set_Num_Geom_Fn(
znumgeom, (
void *) coords.getRawPtr());
350 zz.Set_Geom_Multi_Fn(
zgeom, (
void *) coords.getRawPtr());
351 zz.Set_HG_Size_CS_Fn(
zhgsize, (
void *) &(*matrix));
352 zz.Set_HG_CS_Fn(
zhg, (
void *) &(*matrix));
354 int changes, ngid, nlid;
356 ZOLTAN_ID_PTR dgid = NULL, dlid = NULL, pgid = NULL, plid = NULL;
357 int *dproc = NULL, *dpart = NULL, *pproc = NULL, *ppart = NULL;
359 int ierr = zz.LB_Partition(changes, ngid, nlid,
360 numd, dgid, dlid, dproc, dpart,
361 nump, pgid, plid, pproc, ppart);
362 if (ierr != ZOLTAN_OK && ierr != ZOLTAN_WARN) {
364 std::cout <<
"Test " << testCnt <<
": FAIL: direct Zoltan call" << std::endl;
365 zz.LB_Free_Part(&pgid, &plid, &pproc, &ppart);
369 for(
int i = 0; i < nump; i++) {
370 std::cout << me <<
" KDD Z1 " << pgid[i] <<
" " << plid[i] <<
" " << ppart[i] << std::endl;
377 if (me == 0) std::cout <<
"Calling Zoltan through Zoltan2" << std::endl;
383 catch(std::exception &e){
385 std::cout <<
"Test " << testCnt <<
": FAIL: matrix adapter "
386 << e.what() << std::endl;
389 for (
int idx=0; idx < nWeights; idx++)
390 ia->
setRowWeights(weights->getData(idx).getRawPtr(), 1, idx);
396 catch(std::exception &e){
398 std::cout <<
"Test " << testCnt <<
": FAIL: vector adapter "
399 << e.what() << std::endl;
404 Teuchos::ParameterList params;
405 params.set(
"timer_output_stream" ,
"std::cout");
408 params.set(
"algorithm",
"zoltan");
409 params.set(
"imbalance_tolerance", tolerance );
410 params.set(
"num_global_parts", numGlobalParts);
412 if (thisTest[TESTMETHODOFFSET] !=
"default") {
414 Teuchos::ParameterList &zparams = params.sublist(
"zoltan_parameters",
false);
415 zparams.set(
"LB_METHOD",thisTest[TESTMETHODOFFSET]);
416 zparams.set(
"LB_APPROACH",
"PARTITION");
417 zparams.set(
"SEED",
"1111");
421 # ifdef HAVE_ZOLTAN2_MPI
431 catch(std::exception &e){
432 std::cout <<
"Test " << testCnt <<
" FAIL: problem " << e.what() << std::endl;
439 catch(std::exception &e){
440 std::cout <<
"Test " << testCnt <<
" FAIL: solve " << e.what() << std::endl;
444 for(
int i = 0; i < nump; i++) {
445 std::cout << me <<
" KDD Z2 " << coords->getMap()->getGlobalElement(i) <<
" " << i <<
" " << problem->
getSolution().getPartListView()[i] << std::endl;
450 RCP<quality_t>metricObject = rcp(
new quality_t(ia,¶ms,problem->
getComm(),
453 metricObject->printMetrics(std::cout);
460 size_t nObj = coords->getLocalLength();
461 const int *z2parts = problem->
getSolution().getPartListView();
462 int diffcnt = 0, gdiffcnt = 0;
463 for (
size_t i = 0; i < nObj; i++) {
464 if (z2parts[plid[i]] != ppart[i]) {
466 std::cout << me <<
" DIFF for " << i <<
" ("
467 << coords->getMap()->getGlobalElement(i) <<
"): "
468 <<
"Z2 = " << z2parts[i] <<
"; Z1 = " << ppart[plid[i]] << std::endl;
475 zz.LB_Free_Part(&pgid, &plid, &pproc, &ppart);
481 Teuchos::reduceAll(*comm, Teuchos::REDUCE_SUM, 1, &diffcnt, &gdiffcnt);
484 std::cout <<
"Test " << testCnt <<
" "
488 <<
" FAIL: comparison " << std::endl;
497 int main(
int narg,
char *arg[])
499 Tpetra::ScopeGuard tscope(&narg, &arg);
500 Teuchos::RCP<const Teuchos::Comm<int> > comm = Tpetra::getDefaultComm();
502 int me = comm->getRank();
503 int np = comm->getSize();
507 Array<int> ranks(np);
508 for (
int i = 0; i < np; i++) ranks[i] = i;
513 if (nTestProcs > np) {
515 std::cout <<
"Skipping test " << i <<
" on "
517 <<
"; required number of procs " << nTestProcs
518 <<
" is greater than available procs " << np << std::endl;
524 RCP<const Comm<int> > testcomm;
525 if (nTestProcs == np)
528 testcomm = comm->createSubcommunicator(ranks.view(0,nTestProcs));
531 if (me < nTestProcs) {
532 fail +=
run(testcomm, nTestProcs, i, thisTest);
536 if (me == 0 && !fail)
537 std::cout <<
"PASS" << std::endl;
static void zhg(void *data, int ngid, int nLists, int nPins, int format, ZOLTAN_ID_PTR listGids, int *offsets, ZOLTAN_ID_PTR pinGids, int *ierr)
void setRowWeights(const scalar_t *weightVal, int stride, int idx=0)
Specify a weight for each row.
static void zgeom(void *data, int ngid, int nlid, int nobj, ZOLTAN_ID_PTR gids, ZOLTAN_ID_PTR lids, int ndim, double *coords, int *ierr)
Provides access for Zoltan2 to Xpetra::CrsMatrix data.
Zoltan2::XpetraCrsMatrixAdapter< tMatrix_t, tMVector_t > matrixAdapter_t
static void zobjlist(void *data, int ngid, int nlid, ZOLTAN_ID_PTR gids, ZOLTAN_ID_PTR lids, int nwgts, float *wgts, int *ierr)
Zoltan2::EvaluatePartition< matrixAdapter_t > quality_t
int main(int narg, char **arg)
Defines the PartitioningSolution class.
common code used by tests
static void zhgsize(void *data, int *nLists, int *nPins, int *format, int *ierr)
Tpetra::CrsGraph< zlno_t, zgno_t, znode_t > tGraph_t
Zoltan2::XpetraMultiVectorAdapter< tMVector_t > vectorAdapter_t
Defines the XpetraMultiVectorAdapter.
Defines the XpetraCrsMatrixAdapter class.
RCP< const Comm< int > > getComm()
Return the communicator used by the problem.
void printTimers() const
Return the communicator passed to the problem.
An adapter for Xpetra::MultiVector.
static constexpr int znGidEnt
Tpetra::Map::local_ordinal_type zlno_t
static const std::string fail
const PartitioningSolution< Adapter > & getSolution()
Get the solution to the problem.
PartitioningProblem sets up partitioning problems for the user.
Tpetra::CrsMatrix< zscalar_t, zlno_t, zgno_t, znode_t > tMatrix_t
int run(const RCP< const Comm< int > > &comm, int numGlobalParts, int testCnt, std::string *thisTest)
Defines the PartitioningProblem class.
void setCoordinateInput(VectorAdapter< UserCoord > *coordData) override
Allow user to provide additional data that contains coordinate info associated with the MatrixAdapter...
A class that computes and returns quality metrics.
Tpetra::MultiVector< zscalar_t, zlno_t, zgno_t, znode_t > tMVector_t
Tpetra::Map::global_ordinal_type zgno_t
void solve(bool updateInputData=true)
Direct the problem to create a solution.
std::string zoltanTestDirectory(".")
static int znumobj(void *data, int *ierr)
static int znumgeom(void *data, int *ierr)