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