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 of target should 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 kind
    • SHMEM_INT4_SWAP: 4-byte integer
    • SHMEM_INT8_SWAP: 8-byte integer
    • SHMEM_REAL4_SWAP: 4-byte real
    • SHMEM_REAL8_SWAP: 8-byte real
  • value β€” the value being atomically written to the remote PE. value is the same type as target. matching types, matching vibes, periodt πŸ’–
  • pe β€” an integer that tells you which PE number target lives 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
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms