SHMEM_INT_SWAP(3)

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

πŸ’… SHMEM_INT_SWAP β€” bestie edition

okay so. we're in the Open MPI house tonight and the page is literally called SHMEM_INT_SWAP(3), but honestly? it's a whole girl squad. say hi to the family:

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

and what do they do? one job, and they do it flawlessly: performs an atomic swap to a remote data object. ✨ no cap.


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

the atomic swap routines write value to address target on PE pe, and return the previous contents of target β€” in one atomic operation. one. single. operation. it's giving main character energy and honestly we're obsessed. πŸ’–

the arguments are as follows:

  • target β€” the remotely accessible integer data object that's getting updated on the remote PE. if you're doing C/C++, the type of target should match whatever the SYNOPSIS section implied (look up, bestie πŸ‘†). if you're doing Fortran, it must 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 to be atomically written to the remote PE. value is the same type as target, they're matching, it's a coordinated outfit πŸŽ€
  • pe β€” an integer that indicates the PE number on which target is to be updated. if you're doing Fortran, it must be a default integer value.

πŸ“ NOTES πŸ“

the term remotely accessible is defined in intro_shmem(3). go read it, i'll wait 🫢


πŸ¦‹ RETURN VALUES πŸ¦‹

the contents that had been at the target address on the remote PE prior to the swap is returned. yes, you get the old thing back. the vibes are exchanged. it's a swap. it's literally in the name πŸ’…

see also:

intro_shmem(3)


lowkey reminder: if you're in Fortran, target types and default-integer pe are not a suggestion, they're the law.

and that's the whole page, bestie, we ate and left no crumbs. this whole thing is copyright 2003-2026, The Open MPI Community πŸ‘‘ and it comes to you from the Open MPI era, dated Sep 10, 2026 β€” so you know it's fresh. mwah. πŸ’‹πŸ§šβœ¨

πŸ“¦ where this page comes from