INTRO_SHMEM(3)
π INTRO_SHMEM π
okay bestie, sit down, hydrate, because this is intro_shmem from Open MPI β the whole β¨ Introduction to the OpenSHMEM programming model β¨ β and it is a LOT, but we're gonna eat it bite by bite. π
πΈ DESCRIPTION πΈ
The SHMEM programming model is a whole library of routines that give you low-latency, high-bandwidth communication for highly parallelized, scalable programs. The routines in the OpenSHMEM application programming interface (API) hand you a whole programming model for exchanging data between cooperating parallel processes. The programs you end up writing? Very much giving Message Passing Interface (MPI) energy β same vibe, same style. And here's the tea: the SHMEM API can be used either alone, or combined with MPI routines in the same parallel program. Pick your fighter, or like, both. π«Ά
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. Periodt. Usually the PEs do their computation on their own subdomains of the bigger problem, and then every so often they ~communicate~ with the other PEs to swap the info that the next computation phase depends on. It's giving group project but everyone actually pulls their weight. π
The OpenSHMEM routines minimize the overhead associated with data transfer requests, maximize bandwidth, and minimize data latency. And what is data latency, you ask? It's the period of time that starts when a PE initiates a transfer of data and ends when a PE can use the data. Iconic definition, no notes. π
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. An atomic memory operation is an atomic read-and-update operation β like a fetch-and-increment β on a remote or local data object. Slay.
β¨ OPENSHMEM ROUTINES β¨
This section lists the significant OpenSHMEM message-passing routines. Buckle up, bestie, it's a long one. π
π PE queries
C/C++ only:
Fortran only:
NUM_PES(3)MY_PE(3)
π Elemental data put routines
C/C++ only:
shmem_double_p(3)shmem_float_p(3)shmem_int_p(3)shmem_long_p(3)shmem_short_p.*(3)
π Block data put routines
C/C++ and Fortran:
C/C++ only:
shmem_double_put(3)shmem_float_put(3)shmem_int_put(3)shmem_long_put(3)shmem_short_put.*(3)
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:
shmem_int_wait(3)shmem_int_wait_until(3)shmem_long_wait(3)shmem_long_wait_until(3)shmem_longlong_wait(3)shmem_longlong_wait_until(3)shmem_short_wait(3)shmem_short_wait_until(3)
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:
shmem_int_and_to_all(3)shmem_long_and_to_all(3)shmem_longlong_and_to_all(3)shmem_short_and_to_all(3)shmem_double_max_to_all(3)shmem_float_max_to_all(3)shmem_int_max_to_all(3)shmem_long_max_to_all(3)shmem_longlong_max_to_all(3)shmem_short_max_to_all(3)shmem_double_min_to_all(3)shmem_float_min_to_all(3)shmem_int_min_to_all(3)shmem_long_min_to_all(3)shmem_longlong_min_to_all(3)shmem_short_min_to_all(3)shmem_double_sum_to_all(3)shmem_float_sum_to_all(3)shmem_int_sum_to_all(3)shmem_long_sum_to_all(3)shmem_longlong_sum_to_all(3)shmem_short_sum_to_all(3)shmem_double_prod_to_all(3)shmem_float_prod_to_all(3)shmem_int_prod_to_all(3)shmem_long_prod_to_all(3)shmem_longlong_prod_to_all(3)shmem_short_prod_to_all(3)shmem_int_or_to_all(3)shmem_long_or_to_all(3)shmem_longlong_or_to_all(3)shmem_short_or_to_all(3)shmem_int_xor_to_all(3)shmem_long_xor_to_all(3)shmem_longlong_xor_to_all(3)shmem_short_xor_to_all(3)
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:
bestie we are SO not done, there's more coming β stay tuned for part 2 ππ
shmem_float_swap(3)shmem_int_cswap(3)shmem_int_fadd(3)shmem_int_finc(3)shmem_int_swap(3)shmem_long_cswap(3)shmem_long_fadd(3)shmem_long_finc(3)shmem_long_swap(3)shmem_longlong_cswap(3)shmem_longlong_fadd(3)shmem_longlong_finc(3)shmem_longlong_swap(3)- 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:
shmem_ptr(3)
π₯ Reduction routines
- C/C++ only:
shmem_longdouble_max_to_all(3)shmem_longdouble_min_to_all(3)shmem_longdouble_prod_to_all(3)shmem_longdouble_sum_to_all(3)
- 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:
shmem_pe_accessible(3)shmem_addr_accessible(3)
π¦ Symmetric Data Objects π¦
okay bestie so the whole OpenSHMEM vibe is SPMD (same program, multiple data), right? And out of that comes the concept of symmetric data objects. These are arrays or variables that exist with the same size, same type, and same relative address on all PEs. Another name for them 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. Like, that's the whole point. π
So here's what counts as symmetric:
- Fortran data objects in common blocks or with the
SAVEattribute. 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)
bestie the "must not be defined in a DSO" thing is not a suggestion, it's a rule, okay?? Do not test it. π
π Collective Routines π
Some SHMEM routines β like 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. (Say that three times fast, I dare you. π)
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 π
Multiple pSync arrays are often needed if a particular PE calls an OpenSHMEM collective routine twice without intervening barrier synchronization. Like, problems would happen 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. Chaos. Not the cute kind. π
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 honestly? they're giving plot twist:
- The
shmem_barrier(3) routine allows the samepSyncarray 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
pSyncarrays. 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.
And 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 cleanup required. β¨
β SHMEM ENVIRONMENT VARIABLES β
This section lists the significant SHMEM environment variables. Screenshot this, bestie:
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 is not allowed. I'm so serious. Do not.
π COMPILING AND RUNNING OPENSHMEM PROGRAMS π
The OpenSHMEM specification is silent regarding how OpenSHMEM programs are compiled, linked and run. (Iconic of her, honestly.) 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β¦ wait, that's the run one, keep reading π):
- 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.
shmem_add(3) shmem_and(3) shmem_barrier(3) shmem_barrier_all(3) shmem_broadcast(3) shmem_cache(3) shmem_collect(3) shmem_cswap(3) shmem_fadd(3) shmem_fence(3) shmem_finc(3) shmem_get(3) shmem_iget(3) shmem_inc(3) shmem_iput(3) shmem_lock(3) shmem_max(3) shmem_min(3) shmem_my_pe(3) shmem_or(3) shmem_prod(3) shmem_put(3) shmem_quiet(3) shmem_short_g(3) shmem_short_p(3) shmem_sum(3) shmem_swap(3) shmem_wait(3) shmem_xor(3) shmem_pe_accessible(3) shmem_addr_accessible(3) shmem_init(3) shmem_malloc(3) shmem_my_pe(3) shmem_n_pes(3)
π«Ά Copyright π«Ά
2003-2026, The Open MPI Community
and that's the whole page, bestie!! π¦π this was INTRO_SHMEM(3), dated Sep 10, 2026, brought to you by The Open MPI Community (copyright 2003-2026, we stan a long-running open source project π). go forth and symmetrically allocate. periodt. β¨
π¦ where this page comes from
- ubuntu stonking: openmpi-doc 5.0.10-6 Β· other
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms