MPI_COMM_SET_ERRHANDLER(3)

πŸ’– MPI_COMM_SET_ERRHANDLER πŸ’–

okay bestie, this is a page from the Open MPI manual, and it's about MPI_Comm_set_errhandler β€” aka the glow-up where you give a communicator a whole new error handler. it's giving "new phone, who dis" but for error handling. πŸŽ€


✨ NAME ✨

MPI_Comm_set_errhandler β€” attaches a new error handler to a communicator.


🌸 SYNTAX 🌸

C Syntax

#include <mpi.h>

int MPI_Comm_set_errhandler(MPI_Comm comm,
     MPI_Errhandler errhandler)

Fortran Syntax

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

Fortran 2008 Syntax

USE mpi_f08
MPI_Comm_set_errhandler(comm, errhandler, ierror)
     TYPE(MPI_Comm), INTENT(IN) :: comm
     TYPE(MPI_Errhandler), INTENT(IN) :: errhandler
     INTEGER, OPTIONAL, INTENT(OUT) :: ierror

πŸ¦‹ INPUT/OUTPUT PARAMETER πŸ¦‹

  • comm β€” the communicator in question, a handle. πŸ’…

πŸ’œ OUTPUT PARAMETERS πŸ’œ

  • errhandler β€” the new error handler for your communicator, also a handle. this is the whole point of the call, no cap.
  • ierror β€” Fortran only: error status, and it's an integer. πŸ€“

πŸ”₯ DESCRIPTION πŸ”₯

So MPI_Comm_set_errhandler attaches a new error handler to a communicator. that's it, that's the vibe. but bestie, hear me out on the fine print:

the error handler you pass in has to be either a predefined error handler or one you made yourself by calling MPI_Comm_create_errhandler. those are the only two options, don't get creative.

and listen β€” this call is identical to MPI_Errhandler_set, and using that one is deprecated. so like, use this one, mkay? 🫢


πŸ’€ ERRORS πŸ’€

ngl, almost every MPI routine returns an error value: C routines hand it back as the return result of the function, and Fortran routines put it in that last argument. iconic behavior.

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 counts as attached to MPI_COMM_SELF and it'll call the associated MPI error handler. And when MPI_COMM_SELF isn't initialized β€” meaning 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. 😭

that initial error handler can be changed by:

  • calling 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_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 other MPI functions. periodt.

Open MPI ships with three predefined error handlers you can use, slay:

  • MPI_ERRORS_ARE_FATAL β€” causes the program to abort all connected MPI processes. dramatic, but honest. πŸ’€
  • 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 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. and if called on a session, it aborts only the local process.
  • MPI_ERRORS_RETURN β€” returns an error code to the application. chillest of the three, honestly.

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

build-your-own error handler era, we love to see it. ✨

⚠️ Note that MPI does not guarantee that an MPI program can continue past an error. so like, don't count on it, bestie.

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_Comm_create_errhandler
  • MPI_Comm_get_errhandler

2003-2026, The Open MPI Community


and that's the whole page, bestie!! πŸŽ€ source is the Open MPI man page for MPI_COMM_SET_ERRHANDLER(3), dated Sep 10, 2026, and it was written by the Open MPI Community (2003-2026). go forth and set those error handlers. πŸ’…βœ¨πŸ¦‹

πŸ“¦ where this page comes from