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