SHFREE(3)
β¨ NAME β¨
okay so bestie, welcome to the Open MPI manual page for shfree(3) β and it's not just one function, it's a whole squad π«Ά
shmem_malloc(3),shmem_free(3),shmem_align(3),shmem_realloc(3)shmalloc(3),shfree(3),shmemalign(3),shrealloc(3)
...they're the symmetric heap memory management functions. that's the vibe. that's the whole job. β¨
πΈ 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 π
so the shmem_malloc function hands you back a pointer to a block of at least size bytes, suitably aligned for literally any use. and here's the tea β: this space comes out of the symmetric heap β not the private heap like plain old malloc(3) does. different heap, different girl. π
the shmem_align function allocates a block in the symmetric heap that has a byte alignment specified by the alignment argument. you want it aligned? bestie, it's aligned. β¨
the shmem_free function makes the block that ptr points to get deallocated β like, made available for further allocation, it's freed, it's gone, we release it back to the universe π¦
but watch out: ifptris a null pointer, nothing happens, no action occurs. BUT otherwise β if the argument doesn't match a pointer that a symmetric heap function handed out earlier, or if that space has already been deallocated β thenmalloc_errorgets set to indicate the error, andshfreereturns. that's double-free energy and we do not stan. π
the shmem_realloc function changes the size of the block to which ptr points, to the size (in bytes) specified by size. glow up?? maybe. π
the contents of the block stay 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 don't come for it, we simply don't know her yet. if ptr is a null pointer, the shrealloc function behaves like the shmalloc function for the specified size. if size is 0 and ptr is not a null pointer, the block to which it points gets freed. otherwise, if ptr doesn't match a pointer earlier returned by a symmetric heap function, or if the space has already been deallocated, the malloc_error variable is set to indicate the error, and shrealloc returns a null pointer. and if the space just cannot be allocated, the block to which ptr points stays unchanged. no harm, no foul, no relocation. π§
the shmem_malloc, shmem_free, and shmem_realloc functions exist so that multiple PEs in an application can allocate symmetric, remotely accessible memory blocks. those blocks can then be used with (shmem) communication routines. iconic behavior, truly. π
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. group project that actually works?? a miracle. π
β οΈ the user is responsible for calling these functions with identical argument(s) on all PEs. if differing size arguments get used, subsequent calls may not return the same symmetric heap address on all PEs. so like... coordinate, bestie. communication is key. π
π 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, iykyk. π
the shmem_malloc, shmem_free, and shmem_realloc 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). so yeah, it's giving main character energy but make it a collective β everyone's in the scene or nobody is. π«
β RETURN VALUES β
- the
shmem_mallocfunction returns a pointer to the allocated space (which should be identical on all PEs) π«Ά otherwise, it returns a null pointer (withmalloc_errorset). π¬ - the
shmem_freefunction returns no value. nothing. void. silence. π - the
shmem_reallocfunction returns a pointer to the allocated space (which may have moved) π otherwise, it returns a null pointer (withmalloc_errorset).
π SEE ALSO π
intro_shmem(3) Β· shmem_my_pe(3) Β· shmem_init(3)
π Copyright π
2003-2026, The Open MPI Community
and that's the whole page, bestie!! π this was brought to you by Open MPI, dated Sep 10, 2026 β go forth, allocate symmetrically, and free responsibly. slay. π
β¨
π¦ 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