Actual source code: ex57.c

  1: static char help[] = "Tests PetscCommGetComm().\n";

  3: #include <petscsys.h>

  5: int main(int argc, char **argv)
  6: {
  7:   MPI_Comm    comms[10], comm;
  8:   PetscRandom rand;

 10:   PetscFunctionBeginUser;
 11:   PetscCall(PetscInitialize(&argc, &argv, NULL, help));
 12:   PetscCall(PetscRandomCreate(PETSC_COMM_WORLD, &rand));
 13:   PetscCall(PetscObjectGetComm((PetscObject)rand, &comm));
 14:   for (PetscInt i = 0; i < 10; i++) PetscCall(PetscCommGetComm(comm, &comms[i]));
 15:   for (PetscInt i = 0; i < 5; i++) PetscCall(PetscCommRestoreComm(comm, &comms[i]));
 16:   for (PetscInt i = 0; i < 5; i++) PetscCall(PetscCommGetComm(comm, &comms[i]));
 17:   for (PetscInt i = 0; i < 10; i++) PetscCall(PetscCommRestoreComm(comm, &comms[i]));
 18:   PetscCall(PetscRandomDestroy(&rand));
 19:   PetscCall(PetscFinalize());
 20:   return 0;
 21: }

 23: /*TEST

 25:    test:
 26:      requires: defined(PETSC_USE_LOG)
 27:      args: -info
 28:      filter: grep Reusing | wc -l

 30: TEST*/