SHMALLOC(3)
β¨ NAME β¨
shmalloc(3), shfree(3), shmemalign(3), shrealloc(3) β bestie, these are the symmetric heap memory management functions, from the Open MPI manual. πΈ
π¦ SYNOPSIS π¦
C or C++:
#include <mpp/shmem.h>
void *shmalloc(size_t size)
void shfree(void *ptr)
void *shrealloc(void *ptr, size_t size)
void *shmemalign(size_t alignment, size_t size)
extern long malloc_error
π DESCRIPTION π
okay so picture this. π shmalloc hands you back a pointer to a block of at least size bytes, and it's suitably aligned for any use. the whole vibe here is that this space comes from the symmetric heap β which is not what malloc(3) does, because malloc(3) is out here allocating from the private heap. different heap, different energy, iykyk. β¨
shmemalign is the alignment girlie π β it allocates a block in the symmetric heap that has a byte alignment specified by the alignment argument. chef's kiss.
shfree is the clean-up queen π§Ή β it causes the block that ptr points to, to be deallocated, aka made available for further allocation. but listen:
- if
ptris a null pointer, no action occurs, we move on, periodt. - otherwise, if the argument does not match a pointer earlier returned by a symmetric heap function, or if the space has already been deallocated, then
malloc_erroris set to indicate the error, andshfreereturns. π«
shrealloc is the glow-up function π¦ β it changes the size of the block that ptr points to, to the size (in bytes) you specified. here's the tea:
- 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 β so like, don't count on it, bestie. π
- if
ptris a null pointer,shreallocbehaves like theshmallocfunction for the specifiedsize. - if
sizeis 0 andptris not a null pointer, the block 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. π
okay and now the why of it all. the shmalloc, shfree, and shrealloc functions are provided so that multiple PEs in an application can allocate symmetric, remotely accessible memory blocks. π₯ those memory blocks can then be used with (shmem) communication routines. so real.
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. main character synchronization energy. β
β οΈ and this part is your job, not the library's: 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. no cap. π
π NOTES π
the total size of the symmetric heap is determined at job startup. π you can adjust the size of the heap using the SHMEM_SYMMETRIC_HEAP_SIZE environment variable β see the intro_shmem(3) man page for further details. πΈ
also, the shmalloc, shfree, and shrealloc functions differ from the private heap allocation functions in that all PEs in an application must call them (a barrier is used to ensure this). yes, everybody. it's giving group project but make it functional. π«Ά
π RETURN VALUES π
shmallocreturns a pointer to the allocated space β which should be identical on all PEs β otherwise, it returns a null pointer (withmalloc_errorset). β¨shfreereturns no value. that's it, that's the whole return. πshreallocreturns a pointer to the allocated space β which may have moved β otherwise, it returns a null pointer (withmalloc_errorset). π¦
π SEE ALSO π
intro_shmem(3)my_pe(3)start_pes(3)
π COPYRIGHT π
2003-2026, The Open MPI Community
and that's the whole page, bestie!! π this was the SHMALLOC(3) page from Open MPI, dated Sep 10, 2026 β go forth and allocate symmetrically, you absolute icon. π
β¨π
π¦ 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