SHMEM_BARRIER(3)

πŸ’… SHMEM_BARRIER(3) β€” the Open MPI glow-up

okay bestie, welcome to Open MPI, and welcome to shmem_barrier β€” the routine that does a barrier operation on a subset of processing elements (PEs). yes, a subset. not the whole world. we're being selective. iconic behavior honestly πŸŽ€


✨ SYNOPSIS ✨

C or C++:

#include <mpp/shmem.h>

void shmem_barrier(int PE_start, int logPE_stride, int PE_size,
  long *pSync)

Fortran:

INCLUDE "mpp/shmem.fh"

INTEGER PE_start, logPE_stride, PE_size
INTEGER pSync(SHMEM_BARRIER_SYNC_SIZE)

CALL SHMEM_BARRIER(PE_start, logPE_stride, PE_size, pSync)

🌸 DESCRIPTION 🌸

okay so here's the whole vibe: shmem_barrier does not return until that subset of PEs you specified with PE_start, logPE_stride and PE_size has all entered this routine at the same point of the execution path. it's giving "we don't move until everyone's here." main character meetup energy πŸ‘‘

and like all SHMEM collective routines, each one of these routines assumes that only PEs in the active set call it. if a PE that is not in the active set calls a SHMEM collective routine?? undefined behavior. no cap. 🚩

the arguments, bestie, are as follows:

  • PE_start β€” the lowest virtual PE number of the active set of PEs. PE_start must be of type integer. if you're using Fortran, it must be a default integer value.
  • logPE_stride β€” the log (base 2) of the stride between consecutive virtual PE numbers in the active set. logPE_stride must be of type integer. if you're using Fortran, it must be a default integer value.
  • PE_size β€” the number of PEs in the active set. PE_size must be of type integer. if you're using Fortran, it must be a default integer value.
  • pSync β€” a symmetric work array. in C/C++, pSync must be of type int and size _SHMEM_BARRIER_SYNC_SIZE. in Fortran, pSync must be of type integer and size SHMEM_BARRIER_SYNC_SIZE. if you're using Fortran, it must be a default integer type. every element of this array must be initialized to 0 before any of the PEs in the active set enter shmem_barrier the first time. don't skip this. seriously. 🫢

the values of the arguments PE_start, logPE_stride, and PE_size must be equal on all PEs in the active set. and the same work array must be passed in pSync to all PEs in the active set. matchy-matchy or it doesn't work, periodt.

shmem_barrier ensures that all previously issued local stores and previously issued remote memory updates done by any of the PEs in the active set (by using SHMEM calls, for example shmem_put(3)) are complete before returning. so like… everything's actually done done. not "sent and vibing in transit." done. ✨

and the same pSync array may be reused on consecutive calls to shmem_barrier if the same active PE set is used. free real estate, bestie πŸ’–


πŸ¦‹ NOTES πŸ¦‹

  • the term symmetric is defined in intro_shmem(3). go read it, it's right there.
  • if the pSync array is initialized at run time, be sure to use some type of synchronization, for example, a call to shmem_barrier_all(3), before calling shmem_barrier for the first time. this is the "text them before you show up" of collective routines 😭
  • if the active set does not change, shmem_barrier can be called repeatedly with the same pSync array. no additional synchronization beyond that implied by shmem_barrier itself is necessary in this case. lowkey convenient, we love a routine that doesn't make us do extra work 🌈

πŸ“ EXAMPLES πŸ“

C/C++ example:

shmem_barrier(PE_start, logPE_stride, size, pSync);

Fortran example:

INTEGER PSYNC(SHMEM_BARRIER_SYNC_SIZE)
INTEGER PE_START, LOGPE_STRIDE, PE_SIZE, PSYNC
DATA PSYNC /SHMEM_BARRIER_SYNC_SIZE*0/

CALL SHMEM_BARRIER(PE_START, LOGPE_STRIDE, PE_SIZE, PSYNC)

see? DATA PSYNC /SHMEM_BARRIER_SYNC_SIZE*0/ β€” that's the zero-init we were yelling about. ate. πŸ’…


πŸ”₯ SEE ALSO πŸ”₯


copyright 2003-2026, The Open MPI Community. respect the elders 🫢


okay that's the whole page, bestie β€” brought to you by Open MPI, version dated May 14, 2026. now go forth and synchronize responsibly. πŸ’–βœ¨πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from