xref: /petsc/src/sys/tests/ex57.c (revision f97672e55eacc8688507b9471cd7ec2664d7f203)
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   PetscCall(PetscInitialize(&argc,&argv,(char*)0,help));
13   PetscCall(PetscRandomCreate(PETSC_COMM_WORLD,&rand));
14   PetscCall(PetscObjectGetComm((PetscObject)rand,&comm));
15   for (i=0; i<10; i++) {
16     PetscCall(PetscCommGetComm(comm,&comms[i]));
17   }
18   for (i=0; i<5; i++) {
19     PetscCall(PetscCommRestoreComm(comm,&comms[i]));
20   }
21   for (i=0; i<5; i++) {
22     PetscCall(PetscCommGetComm(comm,&comms[i]));
23   }
24   for (i=0; i<10; i++) {
25     PetscCall(PetscCommRestoreComm(comm,&comms[i]));
26   }
27   PetscCall(PetscRandomDestroy(&rand));
28   PetscCall(PetscFinalize());
29   return 0;
30 }
31 
32 /*TEST
33 
34    test:
35      requires: defined(PETSC_USE_LOG)
36      args: -info
37      filter: grep Reusing | wc -l
38 
39 TEST*/
40