MPI_Session_create_errhandler(3)

πŸ’– MPI_Session_create_errhandler πŸ’–

okay bestie, so this one lives in the MPI manual (yes, that MPI, the Message Passing Interface one, the ✨iconic✨ one), and it's literally just: make me a custom error handler for my session. that's it. that's the whole vibe. you bring the function, MPI brings the handle. slay. πŸŽ€

🌸 NAME 🌸

MPI_Session_create_errhandler β€” create an error handler for use with an MPI session, bestie. it's giving "custom error handling, but make it ✨yours✨". πŸ’…


✨ SYNOPSIS ✨

int MPI_Session_create_errhandler(MPI_Session_errhandler_function *session_errhandler_fn,
MPI_Errhandler *errhandler)

πŸ¦‹ INPUT PARAMETERS πŸ¦‹

  • session_errhandler_fn β€” your very own user-defined error handling procedure (a function, bestie, you write it, you own it, main character energy fr fr πŸ‘‘)

πŸ“ OUTPUT PARAMETERS πŸ“

  • errhandler β€” the MPI error handler (a handle). this is what you get back, and it's literally the whole point. πŸ’–

🧚 THREAD AND INTERRUPT SAFETY 🧚

okay so good news and then a lil caveat, don't panic:

  • βœ… this routine is thread-safe. that means multiple threads can use it at the same time, no cap, and you do not need to bring your own thread locks. no pthread_mutex girlie, put it away. 🫢
  • ⚠️ but β€” and this is the important bit β€” the routine is not interrupt safe. why? typically it's because of memory allocation routines like malloc, or other non-MPICH runtime routines, which are themselves not interrupt-safe. so like, the interrupt-safety vibe check is failed, and it's not even this routine's fault, it's the allocator's. πŸ’€
not me being thread-safe but not interrupt safe... the duality. πŸ™ˆ

πŸŽ€ NOTES FOR FORTRAN πŸŽ€

for my Fortran besties, some house rules:

  • every MPI routine in Fortran (except MPI_WTIME and MPI_WTICK β€” they're the special little exceptions, periodt) gets an extra argument called ierr tacked onto the end of the argument list. like a lil bonus parameter. ✨
  • ierr is an integer, and it means exactly the same thing as the return value of the routine in C. same energy, different language. πŸ’œ
  • in Fortran, MPI routines are subroutines, and you invoke them with the call statement. yes, call. that's the move. πŸ•Ί
  • all MPI objects (e.g., MPI_Datatype, MPI_Comm) are of type INTEGER in Fortran. every single one. ain't no structs here bestie. 🌈

πŸ’€ ERRORS πŸ’€

okay so, real talk. all MPI routines (except MPI_Wtime and MPI_Wtick, the eternal exceptions, we love them) return an error value. in C it's the value of the function, and in Fortran it's that last argument we just talked about. before the value comes back to you, the current MPI error handler gets called. πŸ”₯

by default? that error handler aborts the MPI job. like, full stop, entire job, gone, bye. 😭

you can change the error handler with:

  • MPI_Comm_set_errhandler (for communicators)
  • MPI_File_set_errhandler (for files)
  • MPI_Win_set_errhandler (for RMA windows)

the MPI-1 routine MPI_Errhandler_set may be used, but its use is deprecated β€” so like, it works but it's giving ancient. maybe don't. πŸ™ˆ

if you want error values to just be returned to you instead of nuking everything, use the predefined error handler MPI_ERRORS_RETURN. πŸ’–

important caveat, and I need you to actually read this one: MPI does not guarantee that an MPI program can continue past an error. however, MPI implementations will attempt to continue whenever possible. so it's a try, not a promise. no cap. ⚠️

the actual error codes:

  • MPI_SUCCESS β€” no error; MPI routine completed successfully. we love a clean run. ✨
  • MPI_ERR_ARG β€” invalid argument. some argument is invalid and is not identified by a specific error class (e.g., MPI_ERR_RANK). one of your args is sus, but we can't tell you which one exactly. πŸ’€
  • MPI_ERR_OTHER β€” other error; use MPI_Error_string to get more information about this error code. the "miscellaneous" bucket, bestie. go ask MPI_Error_string for the tea. πŸ“

🌸 that's the whole page! this was the MPI manual, and it's dated 4/10/2026 β€” go forth and handle your errors custom-style. you're gonna eat. πŸ’…βœ¨πŸ‘‘

πŸ“¦ where this page comes from