SHMEM_INIT(3)

πŸ’– SHMEM_INIT(3) πŸ’–

okay so this is straight out of the Open MPI manual, bestie, and it's about shmem_init and start_pes β€” no cap, this is the moment your whole SHMEM era begins ✨

🌸 NAME 🌸

shmem_init, start_pes β€” Allocates a block of memory from the symmetric heap.

✨ SYNOPSIS ✨

C or C++:

void shmem_init(void)
void start_pes(int npes)

Fortran:

CALL SHMEM_INIT()
CALL START_PES(npes)

πŸŽ€ DESCRIPTION πŸŽ€

okay so picture this: the start_pes routine should be the first statement in a SHMEM parallel program. like, main character energy β€” it goes first, no discussion πŸ’…

start_pes accepts the following argument:

  • npes β€” Unused. Should be set to 0. that's it, that's the whole job, it's literally just sitting there being zero πŸ™ˆ

This routine initializes the SHMEM API, which means it must be called before calling any other SHMEM routine. fr fr, before anything else. This routine is responsible inter alia for setting up the symmetric heap on the calling PE, and the creation of the virtual PE numbers. Once this routine returns successfully, the calling PE will be able to communicate with and transfer data to other PEs. like, you're connected now, you're in the group chat 🫢

πŸ’€ Multiple calls to this function are not allowed. one and done. do not come back for seconds.

For an overview of programming with SHMEM communication routines, example SHMEM programs, and instructions for compiling SHMEM programs, see the intro_shmem(3) man page. it's giving prerequisite reading πŸ“š

πŸ¦‹ EXAMPLES πŸ¦‹

This is a simple program that calls shmem_integer_put(3):

PROGRAM PUT
  INCLUDE "mpp/shmem.fh"

  INTEGER TARG, SRC, RECEIVER, BAR
  COMMON /T/ TARG
  PARAMETER (RECEIVER=1)

  CALL SHMEM_INIT()
  IF (MY_PE() .EQ. 0) THEN
    SRC = 33
    CALL SHMEM_INTEGER_PUT(TARG, SRC, 1, RECEIVER)
  ENDIF
  CALL SHMEM_BARRIER_ALL ! SYNCHRONIZES SENDER AND RECEIVER
  IF (MY_PE() .EQ. RECEIVER) THEN
    PRINT *,'PE ', MY_PE(),' TARG=',TARG,' (expect 33)'
  ENDIF
END

lowkey iconic example tbh β€” PE 0 puts 33, everybody hits the barrier, receiver prints. expect 33, bestie 🌈

⭐ NOTES ⭐

😭 If the start_pes call is not the first statement in a program, unexpected results may occur on some architectures. not kidding around here, put it first.

SEE ALSO:

intro_shmem(3) shmem_barrier(3) shmem_barrier_all(3) shmem_put(3) my_pe(3) shmem_n_pes(3)

2003-2026, The Open MPI Community


and that's the whole page, bestie πŸ’œ β€” brought to you by Open MPI, dated May 14, 2026. go forth and initialize responsibly 🧚✨

πŸ“¦ where this page comes from