Actual source code: ex152.c
petsc-3.10.5 2019-03-28
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: * following two patches.
8: *
9: * http://petsc.cs.iit.edu/petsc/externalpackages/parmetis-4.0.2/rev/2dd2eae596ac
10: * http://petsc.cs.iit.edu/petsc/externalpackages/parmetis-4.0.2/rev/1c2b9fe39201
11: *
12: * The bug was reported upstream, but has received no action so far.
13: *
14: * http://glaros.dtc.umn.edu/gkhome/node/837
15: *
16: */
18: #include <petscsys.h>
19: #include <parmetis.h>
21: #define CHKERRQPARMETIS(n) \
22: if (n == METIS_ERROR_INPUT) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_LIB,"ParMETIS error due to wrong inputs and/or options"); \
23: else if (n == METIS_ERROR_MEMORY) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_LIB,"ParMETIS error due to insufficient memory"); \
24: else if (n == METIS_ERROR) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_LIB,"ParMETIS general error"); \
26: int main(int argc, char *argv[])
27: {
29: PetscBool flg;
30: PetscMPIInt rank, size;
31: int i, status;
32: idx_t ni,isize,*vtxdist, *xadj, *adjncy, *vwgt, *part;
33: idx_t wgtflag=0, numflag=0, ncon=1, ndims=3, edgecut=0;
34: idx_t options[5];
35: real_t *xyz, *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;
41: PetscInitialize(&argc,&argv,NULL,help);if (ierr) return ierr;
42: #if defined(PETSC_USE_64BIT_INDICES)
43: PetscPrintf(PETSC_COMM_WORLD,"This example only works with 32 bit indices\n");
44: PetscFinalize();
45: return ierr;
46: #endif
47: MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
48: MPI_Comm_size(PETSC_COMM_WORLD,&size);
50: PetscOptionsBegin(PETSC_COMM_WORLD,NULL,"Parmetis test options","");
51: PetscOptionsString("-prefix","Path and prefix of test file","",prefix,prefix,sizeof(prefix),&flg);
52: if (!flg) SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_USER,"Must specify -prefix");
53: PetscOptionsEnd();
55: PetscMalloc1(size+1,&vtxdist);
57: PetscSNPrintf(fname,sizeof(fname),"%s.%d.graph",prefix,rank);
59: PetscFOpen(PETSC_COMM_SELF,fname,"r",&fp);
61: red = fread(vtxdist, sizeof(idx_t), size+1, fp);if (red != (size_t) (size+1)) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SYS,"Unable to read from data file");
63: ni = vtxdist[rank+1]-vtxdist[rank];
65: PetscMalloc1(ni+1,&xadj);
67: red = fread(xadj, sizeof(idx_t), ni+1, fp);if (red != (size_t) (size+1)) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SYS,"Unable to read from data file");
69: PetscMalloc1(xadj[ni],&adjncy);
71: for (i=0; i<ni; i++) {
72: red = fread(&adjncy[xadj[i]], sizeof(idx_t), xadj[i+1]-xadj[i], fp);if (red != (size_t) (size+1)) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SYS,"Unable to read from data file");
73: }
75: PetscFClose(PETSC_COMM_SELF,fp);
77: PetscSNPrintf(fname,sizeof(fname),"%s.%d.graph.xyz",prefix,rank);
78: PetscFOpen(PETSC_COMM_SELF,fname,"r",&fp);
80: PetscMalloc3(ni*ndims,&xyz,ni,&part,size,&tpwgts);
82: red = fread(xyz, sizeof(real_t), ndims*ni, fp);if (red != (size_t) (size+1)) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SYS,"Unable to read from data file");
84: PetscFClose(PETSC_COMM_SELF,fp);
86: vwgt = NULL;
88: for (i = 0; i < size; i++) tpwgts[i] = 1. / size;
89: isize = size;
91: ubvec[0] = 1.05;
92: options[0] = 1;
93: options[1] = 2;
94: options[2] = 15;
95: options[3] = 0;
96: options[4] = 0;
98: MPI_Comm_dup(MPI_COMM_WORLD, &comm);
99: status = ParMETIS_V3_PartGeomKway(vtxdist, xadj, adjncy, vwgt, NULL, &wgtflag, &numflag, &ndims, xyz, &ncon, &isize, tpwgts, ubvec,options, &edgecut, part, &comm);CHKERRQPARMETIS(status);
100: MPI_Comm_free(&comm);
102: PetscFree(vtxdist);
103: PetscFree(xadj);
104: PetscFree(adjncy);
105: PetscFree3(xyz,part,tpwgts);
106: PetscFinalize();
107: return ierr;
108: }
111: /*TEST
113: build:
114: requires: parmetis
116: test:
117: nsize: 2
118: requires: parmetis datafilespath !complex double !define(PETSC_USE_64BIT_INDICES)
119: args: -prefix ${DATAFILESPATH}/parmetis-test/testnp2
120: TODO: crashes
122: test:
123: suffix: 2
124: nsize: 4
125: requires: parmetis datafilespath !complex double !define(PETSC_USE_64BIT_INDICES)
126: args: -prefix ${DATAFILESPATH}/parmetis-test/testnp4
127: TODO: crashes
129: TEST*/