MPI_ADD_ERROR_CODE(3)

✨ MPI_Add_error_code πŸ’…

okay so bestie, you're reading the MPI_ADD_ERROR_CODE(3) page from the Open MPI manual ✨ congrats, you're in the right place. This one's a lil cutie β€” it Creates a new error code associated with errorclass. That's the whole vibe. Let's get into it πŸŽ€


πŸ“œ SYNTAX

🩡 C Syntax

#include <mpi.h>

int MPI_Add_error_code(int errorclass, int *errorcode)

πŸ’œ Fortran Syntax

USE MPI
! or the older form: INCLUDE 'mpif.h'
MPI_ADD_ERROR_CODE(ERRORCLASS, ERRORCODE, IERROR)
     INTEGER  ERRORCLASS, ERRORCODE, IERROR

πŸ¦‹ Fortran 2008 Syntax

USE mpi_f08
MPI_Add_error_code(errorclass, errorcode, ierror)
     INTEGER, INTENT(IN) :: errorclass
     INTEGER, INTENT(OUT) :: errorcode
     INTEGER, OPTIONAL, INTENT(OUT) :: ierror

🌸 INPUT PARAMETER

  • errorclass β€” an MPI error class, and it's an integer. That's the thing you're hitching your shiny new error code to 🫢

πŸŽ€ OUTPUT PARAMETERS

  • errorcode β€” the error code that an MPI routine returns, or an MPI error class (integer). This is where your brand-new code lands ✨
  • ierror β€” Fortran only, bestie: the error status, also an integer πŸ’…

πŸ’– DESCRIPTION

So what it does: it creates a new error code that's associated with errorclass, and hands you its value back in errorcode. That's it, that's the whole function. Lowkey elegant, highkey useful πŸ”₯


⭐ NOTES

  • There's literally no function provided to free error codes, because nobody expects an application to be out here creating them in significant numbers. So don't stress about cleanup β€” it's not that kind of party πŸ™ˆ
  • the value it gives you back is always greater than or equal to MPI_ERR_LASTCODE. no cap, always ⬆️

πŸ’€ ERRORS

Almost all MPI routines return an error value, jsyk β€” 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 makes its way back to you, the current MPI error handler associated with the communication object (think communicator, window, file) gets called. If there's no communication object associated with the MPI call, then the call is considered attached to MPI_COMM_SELF and it'll call the associated MPI error handler instead. And when MPI_COMM_SELF isn't initialized β€” that's 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. 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. 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 with three predefined error handlers you can use, and they are:

  • MPI_ERRORS_ARE_FATAL β€” Causes the program to abort all connected MPI processes. dramatic but make it effective πŸ’€
  • 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 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. If it's called on a session, it aborts only the local process.
  • MPI_ERRORS_RETURN β€” Returns an error code to the application. the chill one 🧚

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
⚠️ note that MPI does not guarantee that an MPI program can continue past an error. 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 info πŸ“š


🌈 SEE ALSO

  • MPI_Add_error_class
  • MPI_Error_class

2003-2026, The Open MPI Community πŸ’–


and that's the page, bestie πŸŽ€ written by the Open MPI girlies, dated Sep 11, 2026 β€” go forth and make your error codes iconic βœ¨πŸ’…πŸ¦‹

πŸ“¦ where this page comes from