Actual source code: ex13.c
1: /*
2: Tests PetscSetCommWorld()
3: */
4: #include petsc.h
8: int main(int argc,char **argv)
9: {
11: PetscMPIInt rank,size;
12: MPI_Comm newcomm;
14: MPI_Init(&argc,&argv);
16: /* Note cannot use PETSc error handlers here,since PETSc not yet initialized */
17: MPI_Comm_rank(MPI_COMM_WORLD,&rank);
18: if (ierr) {
19: printf("Error in getting rank");
20: return 1;
21: }
22: MPI_Comm_size(MPI_COMM_WORLD,&size);
23: if (ierr) {
24: printf("Error in getting size");
25: return 1;
26: }
28: /*
29: make two new communicators each half the size of original
30: */
31: MPI_Comm_split(MPI_COMM_WORLD,2*rank<size,0,&newcomm);
32: if (ierr) {
33: printf("Error in splitting comm");
34: return 1;
35: }
37: PetscSetCommWorld(newcomm);
38: if (ierr) {
39: fprintf(stdout,"Unable to set PETSC_COMM_WORLD\n");
40: }
42: PetscInitialize(&argc,&argv,PETSC_NULL,PETSC_NULL);
43: MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
44: printf("rank = %3d\n",(int)rank);
46: PetscFinalize();
48: MPI_Finalize();
49: return 0;
50: }