xref: /petsc/src/sys/utils/pbarrier.c (revision 98d129c30f3ee9fdddc40fdbc5a989b7be64f888)
1 #include <petsc/private/petscimpl.h> /*I "petscsys.h" I*/
2 
3 /* Logging support */
4 PetscLogEvent PETSC_Barrier;
5 
6 /*@C
7   PetscBarrier - Blocks until this routine is executed by all processors owning the object `obj`.
8 
9   Input Parameter:
10 . obj - PETSc object  (`Mat`, `Vec`, `IS`, `SNES` etc...)
11 
12   Level: intermediate
13 
14   Notes:
15   The object must be cast with a (`PetscObject`). `NULL` can be used to indicate the barrier
16   should be across `PETSC_COMM_WORLD`.
17 
18   Developer Notes:
19   This routine calls `MPI_Barrier()` with the communicator of the `PetscObject`
20 
21   Fortran Notes:
22   You may pass `PETSC_NULL_VEC` or any other PETSc null object, such as `PETSC_NULL_MAT`, to
23   indicate the barrier should be across `PETSC_COMM_WORLD`. You can also pass in any PETSc
24   object, `Vec`, `Mat`, etc.
25 
26 .seealso: `PetscObject`
27 @*/
28 PetscErrorCode PetscBarrier(PetscObject obj)
29 {
30   MPI_Comm comm = PETSC_COMM_WORLD;
31 
32   PetscFunctionBegin;
33   if (obj) {
34     PetscValidHeader(obj, 1);
35     PetscCall(PetscObjectGetComm(obj, &comm));
36   }
37   PetscCall(PetscLogEventBegin(PETSC_Barrier, obj, 0, 0, 0));
38   PetscCallMPI(MPI_Barrier(comm));
39   PetscCall(PetscLogEventEnd(PETSC_Barrier, obj, 0, 0, 0));
40   PetscFunctionReturn(PETSC_SUCCESS);
41 }
42