20 #include <Tpetra_MultiVector.hpp> 
   43 "simple",       
"phg",          
"0",      
"2",
 
   44 "simple",       
"rcb",          
"0",      
"2",
 
   45 "vwgt2",        
"rcb",          
"2",      
"2",
 
   47 "bug",          
"rcb",          
"1",      
"3",
 
   48 "drake",        
"rcb",          
"0",      
"3",
 
   49 "onedbug",      
"rcb",          
"0",      
"3",
 
   50 "simple",       
"rcb",          
"0",      
"3",
 
   51 "vwgt",         
"rcb",          
"1",      
"3",
 
   52 "vwgt",         
"phg",          
"1",      
"3",
 
   53 "vwgt2",        
"rcb",          
"2",      
"3",
 
   55 "simple",       
"default",      
"0",      
"4",
 
   56 "ewgt",         
"hsfc",         
"0",      
"4",
 
   57 "grid20x19",    
"hsfc",         
"0",      
"4",
 
   58 "grid20x19",    
"hsfc",         
"0",      
"4",
 
   59 "grid20x19",    
"hsfc",         
"0",      
"4",
 
   60 "nograph",      
"rib",          
"0",      
"4",
 
   61 "nograph",      
"phg",          
"0",      
"4",
 
   62 "simple",       
"rib",          
"0",      
"4",
 
   63 "simple",       
"rib",          
"0",      
"4",
 
   64 "vwgt2",        
"rib",          
"2",      
"4",
 
   65 "simple",       
"rib",          
"0",      
"4",
 
   66 "simple",       
"phg",          
"0",      
"4",
 
   68 "brack2_3",     
"rcb",          
"3",      
"5",
 
   70 "hammond2",     
"rcb",          
"2",      
"6",
 
   71 "degenerateAA", 
"rcb",          
"0",      
"6",
 
   72 "degenerate",   
"rcb",          
"0",      
"6",
 
   73 "degenerate",   
"rcb",          
"0",      
"6",
 
   75 "hammond",      
"rcb",          
"0",      
"8",
 
   76 "hammond",      
"phg",          
"0",      
"8",
 
   77 "vwgt2",        
"rcb",          
"2",      
"8" 
   80 typedef Tpetra::CrsGraph<zlno_t, zgno_t, znode_t> 
tGraph_t;
 
   81 typedef Tpetra::CrsMatrix<zscalar_t, zlno_t, zgno_t, znode_t> 
tMatrix_t;
 
   82 typedef Tpetra::MultiVector<zscalar_t, zlno_t, zgno_t, znode_t> 
tMVector_t;
 
   89 #define SET_ZID(n,a,b)                                            \ 
   90    {int ZOLTAN_ID_LOOP;                                                 \ 
   91     for (ZOLTAN_ID_LOOP = 0; ZOLTAN_ID_LOOP < (n); ZOLTAN_ID_LOOP++)    \ 
   92       (a)[ZOLTAN_ID_LOOP] = (b)[ZOLTAN_ID_LOOP];                        \ 
  103   return vec->getLocalLength();
 
  106 static void zobjlist(
void *data, 
int ngid, 
int nlid, 
 
  107                      ZOLTAN_ID_PTR gids, ZOLTAN_ID_PTR lids,
 
  108                      int nwgts, 
float *wgts, 
int *ierr)
 
  112   size_t n = vec->getLocalLength();
 
  114   for (
size_t i = 0; i < n; i++) {
 
  115     zgno_t vgid = vec->getMap()->getGlobalElement(i);
 
  116     ZOLTAN_ID_PTR vgidptr = (ZOLTAN_ID_PTR) &vgid;
 
  121   for (
int w = 0; w < nwgts; w++) {
 
  122     ArrayRCP<const zscalar_t> wvec = vec->getData(w);
 
  123     for (
size_t i = 0; i < n; i++)
 
  124       wgts[i*nwgts+w] = wvec[i];
 
  132   return cvec->getNumVectors();
 
  135 static void zgeom(
void *data, 
int ngid, 
int nlid, 
int nobj, 
 
  136                   ZOLTAN_ID_PTR gids, ZOLTAN_ID_PTR lids,
 
  137                   int ndim, 
double *coords, 
int *ierr)
 
  141   for (
int d = 0; d < ndim; d++) {
 
  142     ArrayRCP<const zscalar_t> cvec = vec->getData(d);
 
  143     for (
int i = 0; i < nobj; i++) {
 
  144       coords[lids[i]*ndim+d] = cvec[lids[i]];
 
  149 static void zhgsize(
void *data, 
int *nLists, 
int *nPins, 
int *format, 
int *ierr)
 
  152   *nLists = matrix->getLocalNumRows();
 
  153   *nPins = matrix->getLocalNumEntries();
 
  154   *format = ZOLTAN_COMPRESSED_VERTEX;
 
  158 static void zhg(
void *data, 
int ngid, 
int nLists, 
int nPins, 
int format,
 
  159                 ZOLTAN_ID_PTR listGids, 
int *offsets, ZOLTAN_ID_PTR pinGids, 
 
  163   RCP<const tGraph_t> graph = matrix->getCrsGraph();
 
  164   zlno_t nrows = graph->getLocalNumRows();
 
  167   for (
zlno_t i = 0; i < nrows; i++) {
 
  169     zgno_t tmp = graph->getRowMap()->getGlobalElement(i);
 
  170     ZOLTAN_ID_PTR ztmp = (ZOLTAN_ID_PTR) &tmp;
 
  173     size_t nEntries = graph->getNumEntriesInLocalRow(i);
 
  174     offsets[i+1] = offsets[i] + nEntries;
 
  177     typename tMatrix_t::local_inds_host_view_type colind;
 
  178     graph->getLocalRowView(i, colind);
 
  180     for (
size_t j = 0; j < nEntries; j++) {
 
  181       tmp = graph->getColMap()->getGlobalElement(colind[j]);
 
  182       ztmp = (ZOLTAN_ID_PTR) &tmp;
 
  183       SET_ZID(znGidEnt, &(pinGids[(offsets[i]+j)*znGidEnt]), ztmp);
 
  194   const RCP<
const Comm<int> > &comm,
 
  197   std::string *thisTest
 
  200 #ifdef HAVE_ZOLTAN2_MPI 
  202   const Teuchos::MpiComm<int> *tmpicomm =
 
  203                dynamic_cast<const Teuchos::MpiComm<int> *
>(comm.getRawPtr());
 
  204   MPI_Comm mpiComm = *(tmpicomm->getRawMpiComm());
 
  207   int me = comm->getRank();
 
  208   int np = comm->getSize();
 
  209   double tolerance = 1.05;
 
  222   catch(std::exception &e){
 
  224       std::cout << 
"Test " << testCnt << 
":  FAIL: UserInputForTests " 
  225            << e.what() << std::endl;
 
  229   RCP<tMatrix_t> matrix;
 
  233   catch(std::exception &e){
 
  235       std::cout << 
"Test " << testCnt << 
":  FAIL: get matrix " 
  236            << e.what() << std::endl;
 
  240   RCP<const tMatrix_t> matrixConst = rcp_const_cast<
const tMatrix_t>(matrix);
 
  242   RCP<tMVector_t> coords;
 
  246   catch(std::exception &e){
 
  248       std::cout << 
"Test " << testCnt << 
":  FAIL: get coordinates " 
  249            << e.what() << std::endl;
 
  257   catch(std::exception &e){
 
  259       std::cout << 
"Test " << testCnt << 
":  FAIL: get weights " 
  260            << e.what() << std::endl;
 
  266     std::cout << 
"Test " << testCnt << 
" filename            = " 
  268     std::cout << 
"Test " << testCnt << 
" num processors      = " 
  270     std::cout << 
"Test " << testCnt << 
" zoltan method       = " 
  272     std::cout << 
"Test " << testCnt << 
" num_global_parts    = " 
  273          << numGlobalParts << std::endl;
 
  274     std::cout << 
"Test " << testCnt << 
" imbalance_tolerance = " 
  275          << tolerance << std::endl;
 
  276     std::cout << 
"Test " << testCnt << 
" num weights per ID  = " 
  277          << nWeights << std::endl;
 
  284   if (me == 0) std::cout << 
"Calling Zoltan directly" << std::endl;
 
  286 # ifdef HAVE_ZOLTAN2_MPI 
  296   zz.Set_Param(
"NUM_GID_ENTRIES", tmp);
 
  297   sprintf(tmp, 
"%d", numGlobalParts);
 
  298   zz.Set_Param(
"NUM_GLOBAL_PARTS", tmp);
 
  299   sprintf(tmp, 
"%d", nWeights);
 
  300   zz.Set_Param(
"OBJ_WEIGHT_DIM", tmp);
 
  301   sprintf(tmp, 
"%f", tolerance);
 
  302   zz.Set_Param(
"IMBALANCE_TOL", tmp);
 
  303   zz.Set_Param(
"RETURN_LISTS", 
"PART");
 
  304   zz.Set_Param(
"FINAL_OUTPUT", 
"1");
 
  305   zz.Set_Param(
"SEED", 
"1111");
 
  306   zz.Set_Param(
"LB_APPROACH", 
"PARTITION");
 
  308   zz.Set_Num_Obj_Fn(
znumobj, (
void *) coords.getRawPtr());
 
  310     zz.Set_Obj_List_Fn(
zobjlist, (
void *) weights.getRawPtr());
 
  312     zz.Set_Obj_List_Fn(
zobjlist, (
void *) coords.getRawPtr());
 
  313   zz.Set_Num_Geom_Fn(
znumgeom, (
void *) coords.getRawPtr());
 
  314   zz.Set_Geom_Multi_Fn(
zgeom, (
void *) coords.getRawPtr());
 
  315   zz.Set_HG_Size_CS_Fn(
zhgsize, (
void *) &(*matrix));
 
  316   zz.Set_HG_CS_Fn(
zhg, (
void *) &(*matrix));
 
  318   int changes, ngid, nlid;
 
  320   ZOLTAN_ID_PTR dgid = NULL, dlid = NULL, pgid = NULL, plid = NULL;
 
  321   int *dproc = NULL, *dpart = NULL, *pproc = NULL, *ppart = NULL;
 
  323   int ierr = zz.LB_Partition(changes, ngid, nlid,
 
  324                              numd, dgid, dlid, dproc, dpart,
 
  325                              nump, pgid, plid, pproc, ppart);
 
  326   if (ierr != ZOLTAN_OK && ierr != ZOLTAN_WARN) {
 
  328       std::cout << 
"Test " << testCnt << 
":  FAIL: direct Zoltan call" << std::endl;
 
  329     zz.LB_Free_Part(&pgid, &plid, &pproc, &ppart);
 
  333 for(
int i = 0; i < nump; i++) {
 
  334   std::cout << me << 
" KDD Z1 " << pgid[i] << 
" " << plid[i] << 
" " << ppart[i] << std::endl;
 
  341   if (me == 0) std::cout << 
"Calling Zoltan through Zoltan2" << std::endl;
 
  347   catch(std::exception &e){
 
  349       std::cout << 
"Test " << testCnt << 
":  FAIL: matrix adapter " 
  350            << e.what() << std::endl;
 
  353   for (
int idx=0; idx < nWeights; idx++)
 
  354     ia->
setRowWeights(weights->getData(idx).getRawPtr(), 1, idx);
 
  360   catch(std::exception &e){
 
  362       std::cout << 
"Test " << testCnt << 
":  FAIL: vector adapter " 
  363            << e.what() << std::endl;
 
  368   Teuchos::ParameterList params;
 
  369   params.set(
"timer_output_stream" , 
"std::cout");
 
  372   params.set(
"algorithm", 
"zoltan");
 
  373   params.set(
"imbalance_tolerance", tolerance );
 
  374   params.set(
"num_global_parts", numGlobalParts);
 
  376   if (thisTest[TESTMETHODOFFSET] != 
"default") {
 
  378     Teuchos::ParameterList &zparams = params.sublist(
"zoltan_parameters",
false);
 
  379     zparams.set(
"LB_METHOD",thisTest[TESTMETHODOFFSET]);
 
  380     zparams.set(
"LB_APPROACH", 
"PARTITION");
 
  381     zparams.set(
"SEED", 
"1111");
 
  385 # ifdef HAVE_ZOLTAN2_MPI 
  395   catch(std::exception &e){
 
  396     std::cout << 
"Test " << testCnt << 
" FAIL: problem " << e.what() << std::endl;
 
  403   catch(std::exception &e){
 
  404     std::cout << 
"Test " << testCnt << 
" FAIL: solve " << e.what() << std::endl;
 
  408 for(
int i = 0; i < nump; i++) {
 
  409   std::cout << me << 
" KDD Z2 " << coords->getMap()->getGlobalElement(i)  << 
" " << i << 
" " << problem->
getSolution().getPartListView()[i] << std::endl;
 
  414  RCP<quality_t>metricObject = rcp(
new quality_t(ia,¶ms,problem->
getComm(),
 
  417     metricObject->printMetrics(std::cout);
 
  424   size_t nObj = coords->getLocalLength();
 
  425   const int *z2parts = problem->
getSolution().getPartListView();
 
  426   int diffcnt = 0, gdiffcnt = 0;
 
  427   for (
size_t i = 0; i < nObj; i++) {
 
  428     if (z2parts[plid[i]] != ppart[i]) {
 
  430       std::cout << me << 
" DIFF for " << i << 
" ("  
  431            << coords->getMap()->getGlobalElement(i) << 
"):  " 
  432            << 
"Z2 = " << z2parts[i] << 
"; Z1 = " << ppart[plid[i]] << std::endl;
 
  439   zz.LB_Free_Part(&pgid, &plid, &pproc, &ppart);
 
  445   Teuchos::reduceAll(*comm, Teuchos::REDUCE_SUM, 1, &diffcnt, &gdiffcnt);
 
  448       std::cout << 
"Test " << testCnt << 
" " 
  452            << 
" FAIL: comparison " << std::endl;
 
  461 int main(
int narg, 
char *arg[])
 
  463   Tpetra::ScopeGuard tscope(&narg, &arg);
 
  464   Teuchos::RCP<const Teuchos::Comm<int> > comm = Tpetra::getDefaultComm();
 
  466   int me = comm->getRank();
 
  467   int np = comm->getSize();
 
  471   Array<int> ranks(np);
 
  472   for (
int i = 0; i < np; i++) ranks[i] = i;
 
  477     if (nTestProcs > np) {
 
  479         std::cout << 
"Skipping test " << i << 
" on " 
  481              << 
"; required number of procs " << nTestProcs 
 
  482              << 
" is greater than available procs " << np << std::endl;
 
  488     RCP<const Comm<int> > testcomm;
 
  489     if (nTestProcs == np)
 
  492       testcomm = comm->createSubcommunicator(ranks.view(0,nTestProcs));
 
  495     if (me < nTestProcs) {
 
  496       fail += 
run(testcomm, nTestProcs, i, thisTest);
 
  500   if (me == 0 && !fail)
 
  501     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)