MPI_FREE_MEM(3)

πŸ’– MPI_FREE_MEM(3) β€” bestie, it's Open MPI and we're freeing memory πŸ’–

okay so. hi. you're here because you called MPI_Alloc_mem, you got your little block of memory, and now the vibe is over and you need to let it go. this is the page for that. it's MPI_Free_mem, from Open MPI, and honestly? it's giving "cleaning up after yourself, main character energy." πŸŽ€


✨ 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 got allocated by MPI_Alloc_mem <#mpi-alloc-mem>. that's it, that's the one you're handing back. (type: choice.) 🫢

πŸ’œ OUTPUT PARAMETER

  • ierror β€” Fortran only, babes: the error status, and it's an integer. πŸ’«

πŸ‘‘ DESCRIPTION

okay so here's the whole thing, and it's not complicated:

MPI_Free_mem frees memory that has been allocated by MPI_Alloc_mem <#mpi-alloc-mem>.

that's the tea. you allocated with one, you free with the other. periodt. πŸ“


πŸ’€ ERRORS πŸ’€

buckle up bestie, this part is long but it's important, no cap.

Almost all MPI routines return an error value β€” C routines hand it back as the return result of the function, and Fortran routines put it in the last argument. MPI_Free_mem is no exception, so check your ierror in Fortran. πŸ™ˆ

Before that error value ever gets returned, the current MPI error handler associated with the communication object (think: communicator, window, file) is called. and if there's no communication object associated with the MPI call? then the call is considered attached to MPI_COMM_SELF, and it will call the associated MPI error handler. when MPI_COMM_SELF is not initialized β€” meaning before MPI_Init <#mpi-init> / MPI_Init_thread <#mpi-init-thread>, after MPI_Finalize <#mpi-finalize>, or when you're using the Sessions Model exclusively β€” the error raises the initial error handler. and that initial error handler can be changed by:

  • calling MPI_Comm_set_errhandler <#mpi-comm-set-errhandler> on MPI_COMM_SELF when you're using the World model, or
  • the mpi_initial_errhandler CLI argument to mpiexec, or
  • the info key to MPI_Comm_spawn <#mpi-comm-spawn> / MPI_Comm_spawn_multiple <#mpi-comm-spawn-multiple>.

and if no other appropriate error handler has been set, then MPI_ERRORS_RETURN is the handler that gets called for MPI I/O functions, and MPI_ERRORS_ABORT is the handler that gets called for all other MPI functions.

Open MPI ships three predefined error handlers you can use:

  • MPI_ERRORS_ARE_FATAL β€” causes the program to abort all connected MPI processes. 😭
  • MPI_ERRORS_ABORT β€” an error handler that can be invoked on a communicator, window, file, or session. when it's called on a communicator, it acts as if MPI_Abort <#mpi-abort> was called on that communicator. if it's called on a window or a file, it acts as if MPI_Abort <#mpi-abort> was called on a communicator containing the group of processes in the corresponding window or file. and if it's called on a session, it aborts only the local process. πŸ‘€
  • MPI_ERRORS_RETURN β€” returns an error code to the application. nice, gentle, we love her. 🫢

MPI applications can also implement their own error handlers by calling:

  • MPI_Comm_create_errhandler <#mpi-comm-create-errhandler> and then MPI_Comm_set_errhandler <#mpi-comm-set-errhandler>
  • MPI_File_create_errhandler <#mpi-file-create-errhandler> and then MPI_File_set_errhandler <#mpi-file-set-errhandler>
  • MPI_Session_create_errhandler <#mpi-session-create-errhandler> and then MPI_Session_set_errhandler <#mpi-session-set-errhandler>, or at MPI_Session_init <#mpi-session-init>
  • MPI_Win_create_errhandler <#mpi-win-create-errhandler> and then MPI_Win_set_errhandler <#mpi-win-set-errhandler>
⚠️ note that MPI does not guarantee that an MPI program can continue past an error. fr fr. plan accordingly. πŸ’€

see the MPI man page <#open-mpi> for a full list of MPI error codes <#open-mpi-errors>.

and see the Error Handling section of the MPI-3.1 standard for even more info, iykyk. πŸ“š


πŸ”₯ SEE ALSO πŸ”₯

  • MPI_Alloc_mem <#mpi-alloc-mem> β€” because every free needs its alloc, bestie. they're a matched set. πŸ’ž

2003-2026, The Open MPI Community ✨


and that's the whole page!! you freed your memory, you checked your error codes, you're thriving. this was MPI_FREE_MEM(3) from Open MPI, last touched Sep 10, 2026 β€” mwah, sending you a big Open MPI Community kiss, go forth and MPI_Free_mem responsibly πŸ’–πŸ¦‹πŸŒΈπŸ’…πŸ‘‘

πŸ“¦ where this page comes from