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