MPI_IS_THREAD_MAIN(3)
π MPI_IS_THREAD_MAIN(3) β the Open MPI glow-up π¦
okay bestie, so you know how Open MPI has its own little corner of the man-page universe? yeah, this is one of those β it's from Open MPI, and it's about the cutest lil identity check in the whole MPI roster. let's get into it β¨
πΈ NAME πΈ
MPI_Is_thread_main β literally just answers the question "is THIS thread the main character?" i.e. determines if the thread called MPI_Init π
π SYNTAX π
β¨ C Syntax β¨
#include <mpi.h>
int MPI_Is_thread_main(int *flag)
π§ Fortran Syntax π§
USE MPI
! or the older form: INCLUDE 'mpif.h'
MPI_IS_THREAD_MAIN(FLAG, IERROR)
LOGICAL FLAG
INTEGER IERROR
π¦ Fortran 2008 Syntax π¦
USE mpi_f08
MPI_Is_thread_main(flag, ierror)
LOGICAL, INTENT(OUT) :: flag
INTEGER, OPTIONAL, INTENT(OUT) :: ierror
π OUTPUT PARAMETERS π
flagβ TRUE if the calling thread is the main thread (it's a boolean, bestie, so like... yes/no energy). πierrorβ Fortran only: the error status, as an integer. π
π DESCRIPTION π
So MPI_Is_thread_main is the function a thread calls to find out whether the caller is the main thread β and by "main thread" we mean the icon, the legend, the moment: the actual thread that called MPI_Init or MPI_Init_thread βπ₯
like, it's a vibe check for threads. that's the whole thing. and it ate. π
π ERRORS π
ngl, almost all MPI routines return an error value β C routines hand it back as the return result of the function, and Fortran routines stash it in that last argument. π¬
Before the error value even comes back to you, the current MPI error handler associated with the communication object (think: communicator, window, file) gets called. And 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. π
When MPI_COMM_SELF is not 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. And you can change that initial error handler by calling MPI_Comm_set_errhandler on MPI_COMM_SELF when 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. π οΈ
And 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 Open MPI ships with π
MPI_ERRORS_ARE_FATALβ causes the program to abort all connected MPI processes. yeah. everybody. π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 ifMPI_Abortwas called on that communicator. If called on a window or file, it acts as ifMPI_Abortwas 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. πMPI_ERRORS_RETURNβ returns an error code to the application. polite. respectful. π«Ά
π§ making your own error handler (yes, you can) π§
MPI applications can also implement their own error handlers by calling:
MPI_Comm_create_errhandlerthenMPI_Comm_set_errhandlerMPI_File_create_errhandlerthenMPI_File_set_errhandlerMPI_Session_create_errhandlerthenMPI_Session_set_errhandleror atMPI_Session_initMPI_Win_create_errhandlerthenMPI_Win_set_errhandler
β οΈ note that MPI does not guarantee that an MPI program can continue past an error. like, no promises, 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_InitMPI_Init_thread
π COPYRIGHT π
2003-2026, The Open MPI Community
π that's the whole page, bestie! source + version: Open MPI, dated Sep 11, 2026 β go forth and know which thread you are π β¨π¦
π¦ where this page comes from
- arch rolling: openmpi 5.0.11-1 Β· BSD-3-Clause AND LicenseRef-MPICH
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms