INTRO_SHMEM(3)

πŸ’– INTRO_SHMEM(3) β€” Open MPI πŸ’–

okay bestie, welcome to intro_shmem β€” the OpenSHMEM programming model intro, and honestly? this is the glow-up your parallel code has been waiting for. ✨


🌸 DESCRIPTION 🌸

so like. the SHMEM programming model is literally a bunch of library routines that give you low-latency, high-bandwidth communication, specifically for highly parallelized scalable programs. that's the whole vibe. πŸ”₯

the routines in the OpenSHMEM application programming interface (API) hand you a programming model for exchanging data between cooperating parallel processes. and the resulting programs? they're similar in style to Message Passing Interface (MPI) programs. the SHMEM API can be used either alone or in combination with MPI routines in the same parallel program β€” so yes, you can absolutely have both, no cap. 🫢

an OpenSHMEM program is SPMD (single program, multiple data) in style. the SHMEM processes β€” called processing elements or PEs β€” all start at the same time and they all run the same program. iconic behaviour, honestly.

usually the PEs perform computation on their own subdomains of the larger problem, and periodically communicate with other PEs to exchange information that the next computation phase depends on. it's giving group chat but for compute. πŸ’…

the OpenSHMEM routines:

  • minimize the overhead associated with data transfer requests
  • maximize bandwidth
  • minimize data latency

and data latency is the period of time that starts when a PE initiates a transfer of data and ends when a PE can use the data. clock it. ⏱️

OpenSHMEM routines support remote data transfer through:

  • put operations β€” which transfer data to a different PE
  • get operations β€” which transfer data from a different PE
  • remote pointers β€” which allow direct references to data objects owned by another PE

other operations supported are collective broadcast and reduction, barrier synchronization, and atomic memory operations. and an atomic memory operation is an atomic read-and-update operation β€” such as a fetch-and-increment β€” on a remote or local data object. literally cannot lose, it's atomic. πŸ‘‘


okay that's part one bestie, stay tuned, more incoming πŸ’œ

✨ OPENSHMEM ROUTINES ✨

Okay bestie, this is the roster β€” the significant OpenSHMEM message-passing routines, all listed and accounted for πŸ’… no skips, no β€œI’ll get to it later”, fr fr. Buckle up πŸŽ€


πŸ¦‹ PE queries πŸ¦‹

C/C++ only

Fortran only

  • NUM_PES(3)
  • MY_PE(3)

🌸 Elemental data put routines 🌸

C/C++ only


πŸ’– Block data put routines πŸ’–

C/C++ and Fortran

C/C++ only

Fortran only

  • shmem_complex_put(3)
  • shmem_integer_put(3)
  • shmem_logical_put(3)
  • shmem_real_put(3)

πŸŽ€ Elemental data get routines πŸŽ€

C/C++ only


πŸ¦‹ Block data get routines πŸ¦‹

C/C++ and Fortran

C/C++ only

Fortran only

  • shmem_complex_get(3)
  • shmem_integer_get(3)
  • shmem_logical_get(3)
  • shmem_real_get(3)

🌈 Strided put routines 🌈

C/C++ and Fortran

C/C++ only

Fortran only

  • shmem_complex_iput(3)
  • shmem_integer_iput(3)
  • shmem_logical_iput(3)
  • shmem_real_iput(3)

⭐ Strided get routines ⭐

C/C++ and Fortran

C/C++ only

Fortran only

  • shmem_complex_iget(3)
  • shmem_integer_iget(3)
  • shmem_logical_iget(3)
  • shmem_real_iget(3)

πŸ”₯ Point-to-point synchronization routines πŸ”₯

C/C++ only

Fortran

  • shmem_int4_wait(3)
  • shmem_int4_wait_until(3)
  • shmem_int8_wait(3)
  • shmem_int8_wait_until(3)

πŸ‘‘ Barrier synchronization routines πŸ‘‘

C/C++ and Fortran


πŸ’€ Atomic memory fetch-and-operate (fetch-op) routines πŸ’€

C/C++ and Fortran

  • shmem_swap

πŸ“ Reduction routines πŸ“

C/C++ only

Fortran only

  • shmem_int4_and_to_all(3)
  • shmem_int8_and_to_all(3)
  • shmem_real4_max_to_all(3)
  • shmem_real8_max_to_all(3)
  • shmem_int4_max_to_all(3)
  • shmem_int8_max_to_all(3)
  • shmem_real4_min_to_all(3)
  • shmem_real8_min_to_all(3)
  • shmem_int4_min_to_all(3)
  • shmem_int8_min_to_all(3)
  • shmem_real4_sum_to_all(3)
  • shmem_real8_sum_to_all(3)
  • shmem_int4_sum_to_all(3)
  • shmem_int8_sum_to_all(3)
  • shmem_real4_prod_to_all(3)
  • shmem_real8_prod_to_all(3)
  • shmem_int4_prod_to_all(3)
  • shmem_int8_prod_to_all(3)
  • shmem_int4_or_to_all(3)
  • shmem_int8_or_to_all(3)
  • shmem_int4_xor_to_all(3)
  • shmem_int8_xor_to_all(3)

🧚 Broadcast routines 🧚

C/C++ and Fortran


πŸ’œ Cache management routines πŸ’œ

C/C++ and Fortran


🫢 Byte-granularity block put routines 🫢

C/C++ and Fortran

Fortran only

  • shmem_character_put(3)
  • shmem_character_get(3)

🌟 Collect routines 🌟

C/C++ and Fortran


πŸ’… Atomic memory fetch-and-operate (fetch-op) routines πŸ’…

C/C++ only

Fortran only

  • shmem_int4_cswap(3)
  • shmem_int4_fadd(3)
  • shmem_int4_finc(3)
  • shmem_int4_swap(3)
  • shmem_int8_swap(3)
  • shmem_real4_swap(3)
  • shmem_real8_swap(3)
  • shmem_int8_cswap(3)

🌸 Atomic memory operation routines 🌸

Fortran only

  • shmem_int4_add(3)
  • shmem_int4_inc(3)

πŸŽ€ Remote memory pointer function πŸŽ€

C/C++ and Fortran


πŸ¦‹ Reduction routines πŸ¦‹

C/C++ only

Fortran only

  • shmem_real16_max_to_all(3)
  • shmem_real16_min_to_all(3)
  • shmem_real16_prod_to_all(3)
  • shmem_real16_sum_to_all(3)

🌈 Accessibility query routines 🌈

C/C++ and Fortran


πŸ’Ž Symmetric Data Objects πŸ’Ž

Consistent with the SPMD nature of the OpenSHMEM programming model is the concept of symmetric data objects ✨ These are arrays or variables that exist with the same size, type, and relative address on all PEs. Another term for symmetric data objects is β€œremotely accessible data objects”. In the interface definitions for OpenSHMEM data transfer routines, one or more of the parameters are typically required to be symmetric or remotely accessible.

The following kinds of data objects are symmetric:

  • Fortran data objects in common blocks or with the SAVE attribute. These data objects must not be defined in a dynamic shared object (DSO).
  • Non-stack C and C++ variables. These data objects must not be defined in a DSO.
  • Fortran arrays allocated with shpalloc(3)
  • C and C++ data allocated by shmalloc(3)

🫢 Collective Routines 🫢

Some SHMEM routines, for example, shmem_broadcast(3) and shmem_float_sum_to_all(3), are classified as collective routines because they distribute work across a set of PEs. They must be called concurrently by all PEs in the active set defined by the PE_start, logPE_stride, PE_size argument triplet. The following man pages describe the OpenSHMEM collective routines:

  • shmem_and(3)
  • shmem_barrier(3)
  • shmem_broadcast(3)
  • shmem_collect(3)
  • shmem_max(3)
  • shmem_min(3)
  • shmem_or(3)
  • shmem_prod(3)
  • shmem_sum(3)
  • shmem_xor(3)

πŸŒ€ USING THE SYMMETRIC WORK ARRAY, PSYNC πŸŒ€

Okay bestie, so here's the tea on pSync arrays: you're gonna need multiple pSync arrays, like, a lot of the time β€” especially if a particular PE calls a OpenSHMEM collective routine twice without an intervening barrier synchronization. And yeah, that's a whole situation. Problems would occur if some PEs in the active set for call 2 arrive at call 2 before processing of call 1 is complete by all PEs in the call 1 active set. Basically, chaos. 😭 You can use shmem_barrier(3) or shmem_barrier_all(3) to perform a barrier synchronization between consecutive calls to OpenSHMEM collective routines.

There are two special cases, and they're both kind of iconic:

  • The shmem_barrier(3) routine allows the same pSync array to be used on consecutive calls as long as the active PE set does not change.
  • If the same collective routine is called multiple times with the same active set, the calls may alternate between two pSync arrays. The SHMEM routines guarantee that a first call is completely finished by all PEs by the time processing of a third call begins on any PE.

Because the SHMEM routines restore pSync to its original contents, multiple calls that use the same pSync array do not require that pSync be reinitialized after the first call. Slay, no extra work. πŸ’…


🌸 SHMEM ENVIRONMENT VARIABLES 🌸

This section lists the significant SHMEM environment variables. Yes, they exist, and yes, they're lowkey useful.

  • SMA_VERSION β€” print the library version at start-up.
  • SMA_INFO β€” print helpful text about all these environment variables.
  • SMA_SYMMETRIC_SIZE β€” number of bytes to allocate for the symmetric heap.
  • SMA_DEBUG β€” enable debugging messages.
⚠️ The first call to SHMEM must be start_pes(3). This routine initializes the SHMEM runtime. Calling any other SHMEM routines beforehand has undefined behavior. Multiple calls to this routine are not allowed.

πŸ› οΈ COMPILING AND RUNNING OPENSHMEM PROGRAMS πŸ› οΈ

The OpenSHMEM specification is silent regarding how OpenSHMEM programs are compiled, linked and run. (Rude, but okay.) This section shows some examples of how wrapper programs could be utilized to compile and launch applications. The commands are styled after wrapper programs found in many MPI implementations.

The following sample command line demonstrates running an OpenSHMEM Program using a wrapper script (oshrun in this case):

  • C/C++:
oshcc c_program.c
  • FORTRAN:
oshfort fortran_program.f

The following sample command line demonstrates running an OpenSHMEM Program assuming that the library provides a wrapper script for such purpose (named oshrun for this example):

oshrun -n 32 ./a.out

✨ EXAMPLES ✨

Example 1: The following Fortran OpenSHMEM program directs all PEs to sum simultaneously the numbers in the VALUES variable across all PEs:

PROGRAM REDUCTION
  REAL VALUES, SUM
  COMMON /C/ VALUES
  REAL WORK

  CALL START_PES(0)
  VALUES = MY_PE()
  CALL SHMEM_BARRIER_ALL ! Synchronize all PEs
  SUM = 0.0
  DO I = 0, NUM_PES()-1
    CALL SHMEM_REAL_GET(WORK, VALUES, 1, I) ! Get next value
    SUM = SUM + WORK                ! Sum it
  ENDDO
  PRINT *, 'PE ', MY_PE(), ' COMPUTED SUM=', SUM
  CALL SHMEM_BARRIER_ALL
END

Example 2: The following C OpenSHMEM program transfers an array of 10 longs from PE 0 to PE 1:

#include <mpp/shmem.h>

main() {
  long source[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
  static long target[10];

  shmem_init();
  if (shmem_my_pe() == 0) {
    /* put 10 elements into target on PE 1 */
    shmem_long_put(target, source, 10, 1);
  }
  shmem_barrier_all(); /* sync sender and receiver */
  if (shmem_my_pe() == 1)
    printf("target[0] on PE %d is %d\n", shmem_my_pe(), target[0]);
}

πŸ‘€ SEE ALSO πŸ‘€

The following man pages also contain information on OpenSHMEM routines. See the specific man pages for implementation information.

(Yes, shmem_my_pe(3) is listed twice β€” we don't make the rules, we just vibe with them. πŸ’…)


2003-2026, The Open MPI Community

πŸ’– And that's a wrap on INTRO_SHMEM(3)! This page is dated May 14, 2026, and comes to you from the Open MPI Community (Β© 2003-2026). Now go forth and make those PEs talk to each other β€” periodt. 🫢✨
πŸ“¦ where this page comes from