MPI_FREE_MEM(3)
π MPI_Free_mem β the Open MPI glow-up π
Okay so bestie, welcome to MPI_FREE_MEM(3) from Open MPI β the manual page that's literally just "clean up after yourself" energy. You allocated memory with MPI_Alloc_mem? Slay. Now let's free it, because leaked memory is not the vibe. π
β¨ SYNTAX β¨
π C Syntax
#include <mpi.h>
int MPI_Free_mem(void *base)
πΈ Fortran Syntax
USE MPI
! or the older form: INCLUDE 'mpif.h'
MPI_FREE_MEM(BASE, IERROR)
<type> BASE(*)
INTEGER IERROR
π¦ Fortran 2008 Syntax
USE mpi_f08
MPI_Free_mem(base, ierror)
TYPE(*), DIMENSION(..), INTENT(IN), ASYNCHRONOUS :: base
INTEGER, OPTIONAL, INTENT(OUT) :: ierror
π INPUT PARAMETER π
baseβ the initial address of the memory segment thatMPI_Alloc_memallocated, bestie. It's a (choice) type. Hand it over and let it go π«Ά
π OUTPUT PARAMETER π
ierrorβ Fortran only, bb: the error status as an (integer). β¨
π DESCRIPTION π
So MPI_Free_mem frees memory that's been allocated by MPI_Alloc_mem. That's it. That's the whole thing. Alloc's other half, the "and release" to its "hold on," the thank u, next of MPI memory management. Iconic, honestly. π₯
π ERRORS π
Okay so this part is long but it's important, ngl. 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, the current MPI error handler associated with the communication object (think communicator, window, file) gets called. And if no communication object is associated with the MPI call? Then the call is considered attached to MPI_COMM_SELF and it'll call the associated MPI error handler. When MPI_COMM_SELF isn't initialized (i.e., before MPI_Init/MPI_Init_thread, after MPI_Finalize, or when 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 via 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 MPI_ERRORS_RETURN gets called for MPI I/O functions, and MPI_ERRORS_ABORT gets called for all the other MPI functions. π«‘
Open MPI ships three predefined error handlers you can use, and they're giving very much choose-your-own-adventure:
MPI_ERRORS_ARE_FATALβ causes the program to abort all connected MPI processes. Dramatic. πMPI_ERRORS_ABORTβ an error handler you can invoke 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. And if called on a session, it aborts only the local process. π―MPI_ERRORS_RETURNβ returns an error code to the application. Chill of it. π
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
β οΈ Real talk bestie: note that MPI does not guarantee that an MPI program can continue past an error. No cap. Don't build your whole app around it. π
See the MPI man page for a full list of MPI error codes β it's the whole menu, iykyk. And see the Error Handling section of the MPI-3.1 standard for more information if you wanna go deeper. π
π SEE ALSO π
MPI_Alloc_memβ the other half of this whole situation, the alloc to your free πΈ
π COPYRIGHT π
2003-2026, The Open MPI Community β legends, all of them. π
And that's the whole page, bestie! β¨ Signing off with the classic footer deets: this is from the Open MPI fam, dated Sep 11, 2026, and it's the MPI_FREE_MEM(3) page. Go free that memory, you gorgeous main character. π¦ππ
π¦ where this page comes from
- arch rolling: openmpi 5.0.11-1 Β· BSD-3-Clause AND LicenseRef-MPICH
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms