Actual source code: ex13.c

  1: /*$Id: ex13.c,v 1.12 2001/03/23 23:20:59 balay Exp $*/

  3: /*
  4:      Tests PetscSetCommWorld()
  5: */
 6:  #include petsc.h

  8: int main(int argc,char **argv)
  9: {
 10:   int      ierr,rank,size;
 11:   MPI_Comm newcomm;

 13:   MPI_Init(&argc,&argv);

 15:   /* Note cannot use PETSc error handlers here,since PETSc not yet initialized */
 16:   MPI_Comm_rank(MPI_COMM_WORLD,&rank);
 17:   if (ierr) {
 18:     printf("Error in getting rank");
 19:     return 1;
 20:   }
 21:   MPI_Comm_size(MPI_COMM_WORLD,&size);
 22:   if (ierr) {
 23:     printf("Error in getting size");
 24:     return 1;
 25:   }

 27:   /*
 28:        make two new communicators each half the size of original
 29:   */
 30:   MPI_Comm_split(MPI_COMM_WORLD,2*rank<size,0,&newcomm);
 31:   if (ierr) {
 32:     printf("Error in splitting comm");
 33:     return 1;
 34:   }

 36:   PetscSetCommWorld(newcomm);
 37:   if (ierr) {
 38:     fprintf(stdout,"Unable to set PETSC_COMM_WORLDn");
 39:   }

 41:   PetscInitialize(&argc,&argv,PETSC_NULL,PETSC_NULL);
 42:   MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
 43:   printf("rank = %3dn",rank);

 45:   PetscFinalize();

 47:   MPI_Finalize();
 48:   return 0;
 49: }