Date: 2026-05-01T06:12:07+00:00

Actual source code: pbarrier.c

      1: #include <petsc/private/petscimpl.h>

      3: /* Logging support */
      4: PetscLogEvent PETSC_Barrier;

      6: /*@
      7:   PetscBarrier - Blocks until this routine is executed by all processors owning the object `obj`.

      9:   Input Parameter:
     10: . obj - PETSc object  (`Mat`, `Vec`, `IS`, `SNES` etc...)

     12:   Level: intermediate

     14:   Fortran Note:
     15:   You may pass `PETSC_NULL_VEC` or any other PETSc null object, such as `PETSC_NULL_MAT`, to
     16:   indicate the barrier should be across `PETSC_COMM_WORLD`. You can also pass in any PETSc
     17:   object, `Vec`, `Mat`, etc.

     19:   Note:
     20:   The object must be cast with a (`PetscObject`). `NULL` can be used to indicate the barrier
     21:   should be across `PETSC_COMM_WORLD`.

     23:   Developer Note:
     24:   This routine calls `MPI_Barrier()` with the communicator of the `PetscObject`

     26: .seealso: `PetscObject`, `MPI_Comm`, `MPI_Barrier`
     27: @*/
     28: PetscErrorCode PetscBarrier(PetscObject obj)
     29: {
     30:   MPI_Comm comm = PETSC_COMM_WORLD;

     32:   PetscFunctionBegin;
     33:   if (obj) {
     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: }