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
10: int main(int argc,char **argv)
11: {
12: int ierr,rank,size;
13: MPI_Comm newcomm;
15: MPI_Init(&argc,&argv);
17: /* Note cannot use PETSc error handlers here,since PETSc not yet initialized */
18: MPI_Comm_rank(MPI_COMM_WORLD,&rank);
19: if (ierr) {
20: printf("Error in getting rank");
21: return 1;
22: }
23: MPI_Comm_size(MPI_COMM_WORLD,&size);
24: if (ierr) {
25: printf("Error in getting size");
26: return 1;
27: }
29: /*
30: make two new communicators each half the size of original
31: */
32: MPI_Comm_split(MPI_COMM_WORLD,2*rank<size,0,&newcomm);
33: if (ierr) {
34: printf("Error in splitting comm");
35: return 1;
36: }
38: PetscSetCommWorld(newcomm);
39: if (ierr) {
40: fprintf(stdout,"Unable to set PETSC_COMM_WORLD\n");
41: }
43: PetscInitialize(&argc,&argv,PETSC_NULL,PETSC_NULL);
44: MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
45: printf("rank = %3d\n",rank);
47: PetscFinalize();
49: MPI_Finalize();
50: return 0;
51: }