static const char help[] = "Test ParMETIS handling of negative weights.\n\n"; /* Test contributed by John Fettig */ /* * This file implements two tests for a bug reported in ParMETIS. These tests are not expected to pass without the * patches in the PETSc distribution of ParMetis. See parmetis.py * * * The bug was reported upstream, but has received no action so far. * * http://glaros.dtc.umn.edu/gkhome/node/837 * */ #include #include #define CHKERRQPARMETIS(n) \ if (n == METIS_ERROR_INPUT) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_LIB,"ParMETIS error due to wrong inputs and/or options"); \ else if (n == METIS_ERROR_MEMORY) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_LIB,"ParMETIS error due to insufficient memory"); \ else if (n == METIS_ERROR) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_LIB,"ParMETIS general error"); \ int main(int argc, char *argv[]) { PetscErrorCode ierr; PetscBool flg; PetscMPIInt rank, size; int i, status; idx_t ni,isize,*vtxdist, *xadj, *adjncy, *vwgt, *part; idx_t wgtflag=0, numflag=0, ncon=1, ndims=3, edgecut=0; idx_t options[5]; PetscReal *xyz; real_t *sxyz, *tpwgts, ubvec[1]; MPI_Comm comm; FILE *fp; char fname[PETSC_MAX_PATH_LEN],prefix[PETSC_MAX_PATH_LEN] = ""; size_t red; ierr = PetscInitialize(&argc,&argv,NULL,help);if (ierr) return ierr; #if defined(PETSC_USE_64BIT_INDICES) ierr = PetscPrintf(PETSC_COMM_WORLD,"This example only works with 32 bit indices\n");CHKERRQ(ierr); ierr = PetscFinalize(); return ierr; #endif MPI_Comm_rank(PETSC_COMM_WORLD,&rank); MPI_Comm_size(PETSC_COMM_WORLD,&size); ierr = PetscOptionsBegin(PETSC_COMM_WORLD,NULL,"Parmetis test options","");CHKERRQ(ierr); ierr = PetscOptionsString("-prefix","Path and prefix of test file","",prefix,prefix,sizeof(prefix),&flg);CHKERRQ(ierr); if (!flg) SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_USER,"Must specify -prefix"); ierr = PetscOptionsEnd();CHKERRQ(ierr); ierr = PetscMalloc1(size+1,&vtxdist);CHKERRQ(ierr); ierr = PetscSNPrintf(fname,sizeof(fname),"%s.%d.graph",prefix,rank);CHKERRQ(ierr); ierr = PetscFOpen(PETSC_COMM_SELF,fname,"r",&fp);CHKERRQ(ierr); 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"); ni = vtxdist[rank+1]-vtxdist[rank]; ierr = PetscMalloc1(ni+1,&xadj);CHKERRQ(ierr); red = fread(xadj, sizeof(idx_t), ni+1, fp);if (red != (size_t) (ni+1)) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SYS,"Unable to read from data file"); ierr = PetscMalloc1(xadj[ni],&adjncy);CHKERRQ(ierr); for (i=0; i