xref: /petsc/src/sys/tests/ex57.c (revision ebead697dbf761eb322f829370bbe90b3bd93fa3)
1 
2 static char help[] = "Tests PetscCommGetComm().\n";
3 
4 #include <petscsys.h>
5 
6 int main(int argc,char **argv)
7 {
8   MPI_Comm       comms[10],comm;
9   PetscInt       i;
10   PetscRandom    rand;
11 
12   PetscFunctionBeginUser;
13   PetscCall(PetscInitialize(&argc,&argv,(char*)0,help));
14   PetscCall(PetscRandomCreate(PETSC_COMM_WORLD,&rand));
15   PetscCall(PetscObjectGetComm((PetscObject)rand,&comm));
16   for (i=0; i<10; i++) {
17     PetscCall(PetscCommGetComm(comm,&comms[i]));
18   }
19   for (i=0; i<5; i++) {
20     PetscCall(PetscCommRestoreComm(comm,&comms[i]));
21   }
22   for (i=0; i<5; i++) {
23     PetscCall(PetscCommGetComm(comm,&comms[i]));
24   }
25   for (i=0; i<10; i++) {
26     PetscCall(PetscCommRestoreComm(comm,&comms[i]));
27   }
28   PetscCall(PetscRandomDestroy(&rand));
29   PetscCall(PetscFinalize());
30   return 0;
31 }
32 
33 /*TEST
34 
35    test:
36      requires: defined(PETSC_USE_LOG)
37      args: -info
38      filter: grep Reusing | wc -l
39 
40 TEST*/
41