MPI_ALLOC_MEM(3)
β¨ MPI_ALLOC_MEM(3) β¨
okay so we're hanging out in the Open MPI manual today bestie, and the icon of the hour is:
MPI_Alloc_mem β Allocates a specified memory segment. π
no cap, that's the whole vibe. let's get into it.
π¦ SYNTAX π¦
C Syntax
#include <mpi.h>
int MPI_Alloc_mem(MPI_Aint size, MPI_Info info, void *baseptr)
Fortran Syntax
USE MPI
! or the older form: INCLUDE 'mpif.h'
MPI_ALLOC_MEM(SIZE, INFO, BASEPTR, IERROR)
INTEGER INFO, IERROR
INTEGER(KIND=MPI_ADDRESS_KIND) SIZE, BASEPTR
Fortran 2008 Syntax
USE mpi_f08
MPI_Alloc_mem(size, info, baseptr, ierror)
USE, INTRINSIC :: ISO_C_BINDING, ONLY
INTEGER(KIND=MPI_ADDRESS_KIND), INTENT(IN) :: size
TYPE(MPI_Info), INTENT(IN) :: info
TYPE(C_PTR), INTENT(OUT) :: baseptr
INTEGER, OPTIONAL, INTENT(OUT) :: ierror
π INPUT PARAMETERS π
sizeβ how many bytes of memory we're manifesting. nonnegative integer, so no negative vibes allowed π ββοΈinfoβ the Info argument (a handle). yes, handle, like a little handle you hold it by.
π OUTPUT PARAMETERS π
baseptrβ pointer to the beginning of the memory segment that just got allocated. the starting line of your new memory block, periodt.ierrorβ Fortran only: error status (integer).
πΈ DESCRIPTION πΈ
MPI_Alloc_mem allocates size bytes of memory. the starting address of that memory comes back to you in the variable baseptr. that's it, that's the whole serve. π«Ά
π C NOTES π
the parameter baseptr is of type void * so that literally any pointer object can be passed through it. so the argument you hand over should be a pointer to a pointer of arbitrary type (like void **). yeah, pointer-to-pointer. iykyk. β¨
π§ FORTRAN NOTES π§
lowkey important: the MPI_Alloc_mem calls require you to use the iso_c_binding module, because of the whole TYPE(C_PTR) situation.
use iso_c_binding
type(c_ptr) :: alloc_ptr
integer :: size, ierr
double precision, pointer :: array(:,:)
! A 2D array of 100 elements
size = 10 * 10
call MPI_Alloc_Mem(size * 8, MPI_INFO_NULL, alloc_ptr, ierr)
! Point to the array
call c_f_pointer(alloc_ptr, array, [10, 10])
! ... use the array ...
! Free the memory, no need for the alloc_ptr
call MPI_Free_mem(array, ierr)
look at that, iconic behavior. π
π ERRORS π
almost all MPI routines return an error value β C routines give it back as the return result of the function, and Fortran routines put it in the last argument.
before that error value comes back to you, the current MPI error handler associated with the communication object (e.g., communicator, window, file) gets called. if there's no communication object associated with the MPI call, then the call counts as attached to MPI_COMM_SELF and it'll call the associated MPI error handler. and when MPI_COMM_SELF is not initialized (i.e., before MPI_Init/MPI_Init_thread, after MPI_Finalize, or when you're using the Sessions Model exclusively), the error raises the initial error handler. you can change that initial error handler by calling MPI_Comm_set_errhandler on MPI_COMM_SELF when you're using the World model, or with the mpi_initial_errhandler CLI argument to mpiexec, or the info key to MPI_Comm_spawn/MPI_Comm_spawn_multiple. and if no other appropriate error handler has been set? then the MPI_ERRORS_RETURN error handler gets called for MPI I/O functions, and the MPI_ERRORS_ABORT error handler gets called for all other MPI functions.
Open MPI ships three predefined error handlers you can use, bestie:
MPI_ERRORS_ARE_FATALβ causes the program to abort all connected MPI processes. yes, all of them. πMPI_ERRORS_ABORTβ an error handler that can be invoked on a communicator, window, file, or session. when called on a communicator, it acts as ifMPI_Abortwas called on that communicator. if it's called on a window or file, it acts as ifMPI_Abortwas called on a communicator containing the group of processes in the corresponding window or file. if it's called on a session, it aborts only the local process.MPI_ERRORS_RETURNβ returns an error code to the application. polite. considerate. we love her.
MPI applications can also implement their own error handlers by calling:
MPI_Comm_create_errhandlerthenMPI_Comm_set_errhandlerMPI_File_create_errhandlerthenMPI_File_set_errhandlerMPI_Session_create_errhandlerthenMPI_Session_set_errhandleror atMPI_Session_initMPI_Win_create_errhandlerthenMPI_Win_set_errhandler
note that MPI does not guarantee that an MPI program can continue past an error. so likeβ¦ don't build your whole personality on surviving one. π
see the MPI man page for a full list of MPI error codes.
see the Error Handling section of the MPI-3.1 standard for more information.
See also:
MPI_Free_mem
π Copyright π
2003-2026, The Open MPI Community
and that's the whole page, bestie β no notes, no missing details, ate and left no crumbs. πβ this was MPI_ALLOC_MEM(3) from the Open MPI manual, page dated Sep 10, 2026. go forth and allocate responsibly. πππ¦
π¦ 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