MPI_FILE_SET_ERRHANDLER(3)

πŸ’… MPI_File_set_errhandler(3) β€” the Open MPI glow-up ✨

okay bestie, welcome to the MPI_File_set_errhandler page from the Open MPI manual, section 3. this one's short and sweet but it's giving "important little function that you'll forget about until 2am" energy, so let's lock in 🫢


🌸 NAME 🌸

MPI_File_set_errhandler β€” sets the error handler for a file. literally that's it, that's the whole vibe πŸ’…


✨ SYNTAX ✨

πŸŽ€ C Syntax

#include <mpi.h>

int MPI_File_set_errhandler(MPI_File file, MPI_Errhandler
     errhandler)

πŸ¦‹ Fortran Syntax

USE MPI
! or the older form: INCLUDE 'mpif.h'
MPI_FILE_SET_ERRHANDLER(FILE, ERRHANDLER, IERROR)
     INTEGER FILE, ERRHANDLER, IERROR

🌈 Fortran 2008 Syntax

USE mpi_f08
MPI_File_set_errhandler(file, errhandler, ierror)
     TYPE(MPI_File), INTENT(IN) :: file
     TYPE(MPI_Errhandler), INTENT(IN) :: errhandler
     INTEGER, OPTIONAL, INTENT(OUT) :: ierror

note the Fortran 2008 version has ierror as OPTIONAL β€” she's flexible like that πŸ’–


πŸ’– INPUT/OUTPUT PARAMETER

  • file β€” the file handle. that's your file bestie, the main character 🎬

🌟 INPUT PARAMETER

  • errhandler β€” the new error handler for the file (it's a handle too, iykyk). this is the whole point of the function, no pressure πŸ’…

🧚 OUTPUT PARAMETER

  • ierror β€” Fortran only: the error status, and yeah it's an integer πŸ™ˆ

πŸ‘‘ DESCRIPTION πŸ‘‘

so what she does: she attaches a new error handler to a file. that's the tea 🍡

and there's a rule, bestie, don't skip it β€” the error handler must be either:

  • a predefined error handler, or
  • an error handler created by a call to MPI_File_create_errhandler

no random off-brand handlers, the vibe check is strict 😀


πŸ’€ ERRORS πŸ’€

okay this is the long part but it's all facts, so stay with me 🫢

Almost all MPI routines return an error value. C routines return it as the return result of the function, and Fortran routines put it in the last argument. classic.

Before the error value gets returned, the current MPI error handler associated with the communication object (think: communicator, window, file) is called. If there's no communication object associated with the MPI call, then the call is considered attached to MPI_COMM_SELF and will call the associated MPI error handler. πŸŒ€

and here's the little edge case that gets people: when MPI_COMM_SELF is not initialized β€” like before MPI_Init/MPI_Init_thread, after MPI_Finalize, or when using the Sessions Model exclusively β€” the error raises the initial error handler. and you can change that initial error handler:

  • by calling MPI_Comm_set_errhandler on MPI_COMM_SELF when using the World model, or
  • with the mpi_initial_errhandler CLI argument to mpiexec, or
  • with the info key to MPI_Comm_spawn/MPI_Comm_spawn_multiple

If no other appropriate error handler has been set, then the MPI_ERRORS_RETURN error handler is called for MPI I/O functions, and the MPI_ERRORS_ABORT error handler is called for all other MPI functions. periodt. πŸ”₯


🌸 the three predefined error handlers that ship with Open MPI 🌸

Open MPI includes three predefined error handlers that can be used:

  • MPI_ERRORS_ARE_FATAL β€” causes the program to abort all connected MPI processes. dramatic? yes. effective? also yes πŸ’€
  • 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 if MPI_Abort was called on that communicator. if 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. if called on a session, it aborts only the local process. context-dependent queen πŸ‘‘
  • MPI_ERRORS_RETURN β€” returns an error code to the application. the gentle one, the "here's your problem back, you deal with it" one πŸŽ€

πŸ¦‹ DIY error handlers (yes you can make your own) πŸ¦‹

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

look at that pipeline, it's giving create-then-set, create-then-set, over and over 😌✨

⚠️ important caveat, do not skip: note that MPI does not guarantee that an MPI program can continue past an error. like, fr fr, plan accordingly πŸ™ˆ

also: see the MPI man page for a full list of MPI error codes, and see the Error Handling section of the MPI-3.1 standard for more information. ngl the standard is a lot but it's there if you need it πŸ“š


2003-2026, The Open MPI Community 🫢


and that's the whole page bestie!! short, iconic, and now you know exactly how to give your file a brand new error handler ✨

~ with love, your Open MPI era ~ πŸ’œ

this edition of MPI_FILE_SET_ERRHANDLER(3) dropped Sep 11, 2026, courtesy of the Open MPI crew β€” slay, and good luck out there πŸŽ€

πŸ“¦ where this page comes from