Actual source code: ex152.c

  1: static const char help[] = "Test ParMETIS handling of negative weights.\n\n";

  3: /* Test contributed by John Fettig */

  5: /*
  6:  * This file implements two tests for a bug reported in ParMETIS. These tests are not expected to pass without the
  7:  * patches in the PETSc distribution of ParMetis. See parmetis.py
  8:  *
  9:  *
 10:  * The bug was reported upstream, but has received no action so far.
 11:  *
 12:  * http://glaros.dtc.umn.edu/gkhome/node/837
 13:  *
 14:  */

 16: #include <petscsys.h>
 17: #include <parmetis.h>

 19: #define PetscCallPARMETIS(...) \
 20:   do { \
 21:     int metis___VA_ARGS__; \
 25:   } while (0)

 27: int main(int argc, char *argv[])
 28: {
 29:   PetscBool   flg;
 30:   PetscMPIInt rank, size;
 31:   idx_t       ni, isize, *vtxdist, *xadj, *adjncy, *vwgt, *part;
 32:   idx_t       wgtflag = 0, numflag = 0, ncon = 1, ndims = 3, edgecut = 0;
 33:   idx_t       options[5];
 34:   PetscReal  *xyz;
 35:   real_t     *sxyz, *tpwgts, ubvec[1];
 36:   MPI_Comm    comm;
 37:   FILE       *fp;
 38:   char        fname[PETSC_MAX_PATH_LEN], prefix[PETSC_MAX_PATH_LEN] = "";
 39:   size_t      red;

 42:   PetscInitialize(&argc, &argv, NULL, help);
 43: #if defined(PETSC_USE_64BIT_INDICES)
 44:   PetscPrintf(PETSC_COMM_WORLD, "This example only works with 32 bit indices\n");
 45:   PetscFinalize();
 46:   return 0;
 47: #endif
 48:   MPI_Comm_rank(PETSC_COMM_WORLD, &rank);
 49:   MPI_Comm_size(PETSC_COMM_WORLD, &size);

 51:   PetscOptionsBegin(PETSC_COMM_WORLD, NULL, "Parmetis test options", "");
 52:   PetscOptionsString("-prefix", "Path and prefix of test file", "", prefix, prefix, sizeof(prefix), &flg);
 54:   PetscOptionsEnd();

 56:   PetscMalloc1(size + 1, &vtxdist);

 58:   PetscSNPrintf(fname, sizeof(fname), "%s.%d.graph", prefix, rank);

 60:   PetscFOpen(PETSC_COMM_SELF, fname, "r", &fp);

 62:   red = fread(vtxdist, sizeof(idx_t), size + 1, fp);

 65:   ni = vtxdist[rank + 1] - vtxdist[rank];

 67:   PetscMalloc1(ni + 1, &xadj);

 69:   red = fread(xadj, sizeof(idx_t), ni + 1, fp);

 72:   PetscMalloc1(xadj[ni], &adjncy);

 74:   for (PetscInt i = 0; i < ni; i++) {
 75:     red = fread(&adjncy[xadj[i]], sizeof(idx_t), xadj[i + 1] - xadj[i], fp);
 77:   }

 79:   PetscFClose(PETSC_COMM_SELF, fp);

 81:   PetscSNPrintf(fname, sizeof(fname), "%s.%d.graph.xyz", prefix, rank);
 82:   PetscFOpen(PETSC_COMM_SELF, fname, "r", &fp);

 84:   PetscMalloc3(ni * ndims, &xyz, ni, &part, size, &tpwgts);
 85:   PetscMalloc1(ni * ndims, &sxyz);

 87:   red = fread(xyz, sizeof(PetscReal), ndims * ni, fp);
 89:   for (PetscInt i = 0; i < ni * ndims; i++) sxyz[i] = (size_t)xyz[i];

 91:   PetscFClose(PETSC_COMM_SELF, fp);

 93:   vwgt = NULL;

 95:   for (PetscInt i = 0; i < size; i++) tpwgts[i] = 1. / size;
 96:   isize = size;

 98:   ubvec[0]   = 1.05;
 99:   options[0] = 0;
100:   options[1] = 2;
101:   options[2] = 15;
102:   options[3] = 0;
103:   options[4] = 0;

105:   MPI_Comm_dup(MPI_COMM_WORLD, &comm);
106:   ParMETIS_V3_PartGeomKway(vtxdist, xadj, adjncy, vwgt, NULL, &wgtflag, &numflag, &ndims, sxyz, &ncon, &isize, tpwgts, ubvec, options, &edgecut, part, &comm);
107:   MPI_Comm_free(&comm);

109:   PetscFree(vtxdist);
110:   PetscFree(xadj);
111:   PetscFree(adjncy);
112:   PetscFree3(xyz, part, tpwgts);
113:   PetscFree(sxyz);
114:   PetscFinalize();
115:   return 0;
116: }

118: /*TEST

120:    build:
121:       requires: parmetis

123:    test:
124:       nsize: 2
125:       requires: parmetis datafilespath !complex double !defined(PETSC_USE_64BIT_INDICES)
126:       args: -prefix ${DATAFILESPATH}/parmetis-test/testnp2

128:    test:
129:       suffix: 2
130:       nsize: 4
131:       requires: parmetis datafilespath !complex double !defined(PETSC_USE_64BIT_INDICES)
132:       args: -prefix ${DATAFILESPATH}/parmetis-test/testnp4

134: TEST*/