SHMEM_TEST_LOCK(3)

πŸ“¦
version 5.0.10 Β· 4 versions
, in ubuntu stonking

πŸ’– SHMEM_TEST_LOCK πŸ’–

okay bestie, welcome to the group chat for shmem_set_lock(3), shmem_clear_lock(3), and shmem_test_lock(3) β€” the Open MPI trio that releases, locks, and tests a mutual exclusion memory lock. yes it's giving "who gets to touch the thing first" energy, and yes it's iconic. no cap.


✨ NAME ✨

shmem_set_lock(3), shmem_clear_lock(3), shmem_test_lock(3) β€” Releases, locks, and tests a mutual exclusion memory lock.

🌸 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)

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so shmem_set_lock does the thing: it sets a mutual exclusion lock, but only after it's waited for the lock to be freed by any other PE that currently has it held. and the way waiting PEs are handled? they are assured of getting the lock in a first-come, first-served manner. line etiquette, but make it parallel computing. slay. πŸ’…

then shmem_clear_lock releases a lock that was previously set by shmem_set_lock β€” and it doesn't just dip out immediately, bestie, it first ensures that all local and remote stores initiated in the critical region are complete. it's the "let me finish my sentence before you talk" of locks. 🫢

and shmem_test_lock? it sets a mutual exclusion lock only if it is currently cleared. 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 β€” like when you check if the bathroom's free and immediately keep it moving. no line, no drama. 🌈

all three of these routines are appropriate for protecting a critical region from simultaneous update by multiple PEs. they accept the following arguments:

  • lock β€” a symmetric data object that is a scalar variable or an array of length 1. this data object must be set to 0 on all processing elements (PEs) prior to the first use. lock must be of type integer. if you're using Fortran, it must be of default kind. that's the whole vibe check, don't skip it. πŸ™ˆ

πŸ“ NOTES πŸ“

the term symmetric data object is defined on intro_shmem(3). go read it if you're confused, i promise it's not a jump scare. 🧚

⭐ RETURN VALUES ⭐

shmem_test_lock returns 0 if the lock was originally cleared and this call was able to set the lock. a value of 1 is returned if the lock had been set and the call returned without waiting to set the lock. one number, two plot twists. πŸ’€

See also:

  • intro_shmem(3)

2003-2026, The Open MPI Community

okay that's the whole page, bestie β€” written by the Open MPI girlies, shipped Sep 10, 2026, and yes the SHMEM_TEST_LOCK(3) page really does live in manual name city with all three routines. go forth and lock responsibly, and remember: first-come, first-served, periodt. πŸŽ€βœ¨πŸ”₯

πŸ“¦ where this page comes from