SHMALLOC(3)
π SHMALLOC(3) π
okay so bestie, this is the Open MPI manual page for SHMALLOC(3) β symmetric heap memory management, but make it group-chat. It's giving "all your PEs have to agree on the allocation vibe," and honestly? main character energy.
β¨ NAME β¨
shmem_malloc(3),shmem_free(3),shmem_align(3),shmem_realloc(3),shmalloc(3),shfree(3),shmemalign(3),shrealloc(3)β symmetric heap memory management functions. That's the whole squad, no cap π
π SYNOPSIS π
C or C++:
#include <mpp/shmem.h>
void *shmem_malloc(size_t size);
void *shmalloc(size_t size);
void shmem_free(void *ptr);
void shfree(void *ptr);
void *shmem_realloc(void *ptr, size_t size);
void *shrealloc(void *ptr, size_t size);
void *shmem_align(size_t alignment, size_t size);
void *shmemalign(size_t alignment, size_t size);
extern long malloc_error;
π DESCRIPTION π
okay so here's the tea, function by function:
shmem_mallocreturns a pointer to a block of at leastsizebytes, suitably aligned for any use. This space is allocated from the symmetric heap β not the private heap likemalloc(3C)does. periodt.shmem_alignallocates a block in the symmetric heap that has a byte alignment specified by thealignmentargument. slay.shmem_freecauses the block thatptrpoints to to be deallocated, aka made available for further allocation. Ifptris a null pointer, no action occurs. Otherwise, if the argument does not match a pointer earlier returned by a symmetric heap function, or if the space has already been deallocated,malloc_erroris set to indicate the error, andshfreereturns. yes bestie, the original specifically saysshfreethere π«Άshmem_reallocchanges the size of the block thatptrpoints to, to the size in bytes specified bysize.- The contents of the block are unchanged up to the lesser of the new and old sizes.
- If the new size is larger, the value of the newly allocated portion of the block is indeterminate. that means don't trust it, bestie π
- If
ptris a null pointer, theshreallocfunction behaves like theshmallocfunction for the specifiedsize. - If
sizeis0andptris not a null pointer, the block that it points to is freed. - Otherwise, if
ptrdoes not match a pointer earlier returned by a symmetric heap function, or if the space has already been deallocated, themalloc_errorvariable is set to indicate the error, andshreallocreturns a null pointer. - If the space cannot be allocated, the block that
ptrpoints to is unchanged.
The shmem_malloc, shmem_free, and shmem_realloc functions are provided so that multiple PEs in an application can allocate symmetric, remotely accessible memory blocks. These memory blocks can then be used with (shmem) communication routines. Each of these functions calls the shmem_barrier_all(3) function before returning; this ensures that all PEs participate in the memory allocation, and that the memory on other PEs can be used as soon as the local PE returns. barrier girlies rise π
The user is responsible for calling these functions with identical argument(s) on all PEs. If differing size arguments are used, subsequent calls may not return the same symmetric heap address on all PEs. that's the warning, don't ignore it π
π«Ά NOTES π«Ά
- The total size of the symmetric heap is determined at job startup. One can adjust the size of the heap using the
SHMEM_SYMMETRIC_HEAP_SIZEenvironment variable. See theintro_shmem(3)man page for futher details. (the page literally says "futher" β typo preserved, bestie π) - The
shmem_malloc,shmem_free, andshmem_reallocfunctions differ from the private heap allocation functions in that all PEs in an application must call them (a barrier is used to ensure this). important!! π¨
π RETURN VALUES π
shmem_mallocreturns a pointer to the allocated space (which should be identical on all PEs); otherwise, it returns a null pointer (withmalloc_errorset).shmem_freereturns no value.shmem_reallocreturns a pointer to the allocated space (which may have moved); otherwise, it returns a null pointer (withmalloc_errorset).
that's the whole return tea on this page, no extra lore β¨
π¦ SEE ALSO π¦
intro_shmem(3)shmem_my_pe(3I)shmem_init(3)
okay that's the whole page! the footer stamp is gitclone / Unreleased developer copy / SHMALLOC(3), with no date shown β dev-copy vibes only. go forth and allocate symmetrically, bestie πβ¨
π¦ where this page comes from
- arch rolling: nvhpc-comm-libs 26.9-1 Β· LicenseRef-NVIDIA-HPC-SDK
- Copyright (c) 2015 University of Houston. All rights reserved
- Copyright (c) 2015 Mellanox Technologies, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms