SHMEM_SWAP(3)
π SHMEM_SWAP(3) π
okay so bestie, welcome to the Open MPI manual page for the swap girlies π β yes, we're talking about shmem_double_swap(3), shmem_float_swap(3), shmem_int_swap(3), shmem_long_swap(3), shmem_swap(3), shmem_int4_swap(3), shmem_int8_swap(3), shmem_real4_swap(3), shmem_real8_swap(3), and shmem_longlong_swap(3). These iconic little functions perform an atomic swap to a remote data object and honestly? they ate. π₯
β¨ SYNOPSIS β¨
C or C++ π
#include <mpp/shmem.h>
double shmem_double_swap(double *target, double value,
int pe);
float shmem_float_swap(float *target, float value, int pe);
int shmem_int_swap(int *target, int value, int pe);
long shmem_long_swap(long *target, long value, int pe);
long long shmem_longlong_swap(long long *target,
long long value, int pe);
long shmem_swap(long *target, long value, int pe);
Fortran π¦
INCLUDE "mpp/shmem.fh"
INTEGER pe
INTEGER SHMEM_SWAP
ires = SHMEM_SWAP(target, value, pe)
INTEGER(KIND=4) SHMEM_INT4_SWAP
ires = SHMEM_INT4_SWAP(target, value, pe)
INTEGER(KIND=8) SHMEM_INT8_SWAP
ires = SHMEM_INT8_SWAP(target, value, pe)
REAL(KIND=4) SHMEM_REAL4_SWAP
res = SHMEM_REAL4_SWAP(target, value, pe)
REAL(KIND=8) SHMEM_REAL8_SWAP
res = SHMEM_REAL8_SWAP(target, value, pe)
πΈ DESCRIPTION πΈ
So like, here's the vibe: the atomic swap routines write value to address target on PE pe, and they return the previous contents of target β all in one atomic operation. no half-swaps, no messy in-between states, it's giving main character energy who has her life together fr fr π
Now let's meet the arguments, bestie:
targetβ the remotely accessible integer data object that's getting updated on the remote PE. if you're in C/C++ land, the type oftargetshould match that implied in the SYNOPSIS section (iykyk, type-matching is self care). if you're doing Fortran, it's gotta be one of these bad boys:SHMEM_SWAP: Integer of default kindSHMEM_INT4_SWAP: 4-byte integerSHMEM_INT8_SWAP: 8-byte integerSHMEM_REAL4_SWAP: 4-byte realSHMEM_REAL8_SWAP: 8-byte real
valueβ the value being atomically written to the remote PE.valueis the same type astarget. matching types, matching vibes, periodt πpeβ an integer that tells you which PE numbertargetlives on and is gonna be updated. if you're in Fortran, it must be a default integer value. no funny business πΈ
π§ NOTES π§
the term remotely accessible is defined in intro_shmem(3). go read that one if you need the full lore drop, iykyk πβ¨
π RETURN VALUES π
what you get back is the contents that had been at the target address on the remote PE prior to the swap. like, the old thing. the before-times. the swap hands it to you on a little platter π«Ά
π¦ SEE ALSO π¦
intro_shmem(3) β the whole friend group, honestly π
so yeah, that's the whole page! here's the official tea at the bottom: this is from gitclone, the Unreleased developer copy, and the page itself is dated SHMEM_SWAP(3). bye bestie, go swap something atomically, slay π
β¨π
π¦ where this page comes from
- arch rolling: nvhpc-comm-libs 26.9-1 Β· LicenseRef-NVIDIA-HPC-SDK
- Copyright (c) 2015 University of Houston. All rights reserved
- Copyright (c) 2015 Mellanox Technologies, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms