xref: /petsc/src/sys/tests/ex57.c (revision 856bee69f0e0908e75ff837867b1777dfb1ced96)
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++) PetscCall(PetscCommGetComm(comm, &comms[i]));
17   for (i = 0; i < 5; i++) PetscCall(PetscCommRestoreComm(comm, &comms[i]));
18   for (i = 0; i < 5; i++) PetscCall(PetscCommGetComm(comm, &comms[i]));
19   for (i = 0; i < 10; i++) PetscCall(PetscCommRestoreComm(comm, &comms[i]));
20   PetscCall(PetscRandomDestroy(&rand));
21   PetscCall(PetscFinalize());
22   return 0;
23 }
24 
25 /*TEST
26 
27    test:
28      requires: defined(PETSC_USE_LOG)
29      args: -info
30      filter: grep Reusing | wc -l
31 
32 TEST*/
33