SHMEM_TEST_LOCK(3)
π SHMEM_TEST_LOCK(3) β an Open MPI moment π
ok so bestie, this is section 3 of the Open MPI manual, and today we're learning about the lock girlies: shmem_set_lock(3), shmem_clear_lock(3) and shmem_test_lock(3). yes they all share one page, they're a package deal π
β¨ NAME β¨
shmem_set_lock(3), shmem_clear_lock(3), shmem_test_lock(3) β releases, locks, and tests a mutual exclusion memory lock. that's the whole vibe. three functions, one job: keeping your critical region from getting jumped by everybody at once π
πΈ SYNOPSIS πΈ
C or C++:
#include <mpp/shmem.h>
void shmem_clear_lock(volatile long *lock)
void shmem_set_lock(volatile long *lock)
int shmem_test_lock(volatile long *lock)
Fortran:
INCLUDE "mpp/shmem.fh"
INTEGER lock, SHMEM_TEST_LOCK
CALL SHMEM_CLEAR_LOCK(lock)
CALL SHMEM_SET_LOCK(lock)
I = SHMEM_TEST_LOCK(lock)
like, copy-paste these exactly, bestie, don't freestyle the signatures π
π¦ DESCRIPTION π¦
okay so, storytime. shmem_set_lock sets a mutual exclusion lock β and the way it does it is it waits for the lock to be freed by any other PE that's currently holding it. and here's the slay part: waiting PEs are assured of getting the lock in a first-come, first-served manner. no line-cutting. the queue is sacred. π§
shmem_clear_lock releases a lock that was previously set by shmem_set_lock β but only after making sure that all the local and remote stores you started inside the critical region are actually complete. she's thorough. she does not leave the group chat mid-sentence. β¨
shmem_test_lock sets a mutual exclusion lock only if it's currently cleared. this one's for my no-ghosting girlies: by using this function, a PE can avoid blocking on a set lock. if the lock is currently set, the function just returns without waiting. no sitting around, no "seen 2:14am", she moves on. π
these routines are appropriate for protecting a critical region from simultaneous update by multiple PEs. they accept the following argument:
lockβ a symmetric data object that is a scalar variable or an array of length 1. it must be set to0on all processing elements (PEs) prior to the first use.lockmust be of type integer. if you're in Fortran-land, it must be of default kind. (yes, all of them. no cap. π₯)
π NOTES π
the term symmetric data object is defined on intro_shmem(3) β go check her out if you're nosy like me π«Ά
β RETURN VALUES β
shmem_test_lock is the one that actually gives you a number back:
- returns
0if the lock was originally cleared and this call was able to set the lock β you got her π - returns
1if the lock had been set and the call returned without waiting to set the lock β she was taken, no waiting around π
π SEE ALSO π
π COPYRIGHT π
2003-2026, The Open MPI Community
okay and that's the page!! written down for you on May 14, 2026, from the Open MPI girlies, SHMEM_TEST_LOCK(3) era. go forth and lock responsibly bestie ππ
π¦ where this page comes from
- arch rolling: nvhpc-comm-libs 26.9-1 Β· LicenseRef-NVIDIA-HPC-SDK
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms