SHMEM_LONG_SWAP(3)

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

🌸 NAME 🌸

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), shmem_longlong_swap(3) β€” bestie, these all do one iconic thing: perform an atomic swap to a remote data object πŸ’–

This is the <cyan>shmem_long_swap(3)</cyan> page from the Open MPI manual, and she contains multitudes (a whole lil family of swap functions, actually). Let's get into it ✨


πŸ¦‹ SYNOPSIS πŸ¦‹

okay so, C or C++ girlies:

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

and for the Fortran besties:

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 πŸ‘‘

The atomic swap routines write value to address target on PE pe, and return the previous contents of target in one atomic operation 🌈 Like, it's all one move, no in-between, no half-swapped mess. Periodt.

Here's the cast of arguments, and yes they each have main character energy πŸ’…

  • target β€” the remotely accessible integer data object being updated on the remote PE. If you're in C/C++ land, the type of target should match whatever the SYNOPSIS says it is (no mixing and matching, iykyk). If you're doing Fortran, it's gotta be one of these types:
    • 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 getting atomically written to the remote PE. She is the same type as target, no cap 🫢
  • pe β€” an integer that says which PE number target is getting updated on. In Fortran it must be a default integer value, fr fr.

πŸ“ NOTES πŸ“

The term remotely accessible is defined over in intro_shmem(3). Go peek if you need the full tea 🍡


πŸ’– RETURN VALUES πŸ’–

Whatever was sitting at the target address on the remote PE before the swap happened? Yeah, that's what you get back. The old value is returned to you, bestie β€” nothing gets lost, everything gets traded 😭πŸ”₯

See also: intro_shmem(3)


2003-2026, The Open MPI Community β€” they've been holding it down since 2003, iconic behavior honestly πŸ‘‘


okay that's the whole page!! this was SHMEM_LONG_SWAP(3) from Open MPI, last touched Sep 10, 2026 β€” go forth and swap atomically, you've got this πŸ’œπŸ§šβœ¨

πŸ“¦ where this page comes from