xref: /petsc/src/sys/tests/ex57.c (revision b122ec5aa1bd4469eb4e0673542fb7de3f411254)
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   CHKERRQ(PetscInitialize(&argc,&argv,(char*)0,help));
13   CHKERRQ(PetscRandomCreate(PETSC_COMM_WORLD,&rand));
14   CHKERRQ(PetscObjectGetComm((PetscObject)rand,&comm));
15   for (i=0; i<10; i++) {
16     CHKERRQ(PetscCommGetComm(comm,&comms[i]));
17   }
18   for (i=0; i<5; i++) {
19     CHKERRQ(PetscCommRestoreComm(comm,&comms[i]));
20   }
21   for (i=0; i<5; i++) {
22     CHKERRQ(PetscCommGetComm(comm,&comms[i]));
23   }
24   for (i=0; i<10; i++) {
25     CHKERRQ(PetscCommRestoreComm(comm,&comms[i]));
26   }
27   CHKERRQ(PetscRandomDestroy(&rand));
28   CHKERRQ(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