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 that MPI_Alloc_mem allocated, 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 if MPI_Abort was called on that communicator. If it's called on a window or file, it acts as if MPI_Abort was 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_errhandler then MPI_Comm_set_errhandler
  • MPI_File_create_errhandler then MPI_File_set_errhandler
  • MPI_Session_create_errhandler then MPI_Session_set_errhandler or at MPI_Session_init
  • MPI_Win_create_errhandler then MPI_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 🌸

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