MPI_IS_THREAD_MAIN(3)
π MPI_IS_THREAD_MAIN π
okay bestie, so this one lives in Open MPI section 3, and it's literally the "am I the main character?" detector for threads. No cap. Let's get into it π«Ά
β¨ 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β the moment of truth: it's true when the calling thread is the main thread (a boolean, so literally just yes/no energy).ierrorβ Fortran only, bestie: the error status (integer).
π DESCRIPTION π
So MPI_Is_thread_main gets called by a thread to figure out whether the caller is the main thread β and by "main thread" we mean the thread that called MPI_Init or MPI_Init_thread. It's giving "am I the one who started all of this, or am I just a side character?" energy, and honestly, valid question. π¦
π ERRORS π
Almost every MPI routine hands back an error value β C routines give it to you as the return result of the function, and Fortran routines put it in the last argument. Set your expectations accordingly, bestie.
Before that error value even makes it 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 attached to the MPI call, then the call is treated as attached to MPI_COMM_SELF and it'll call the associated MPI error handler. And when MPI_COMM_SELF isn't initialized β i.e., 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 swap that initial error handler out by calling MPI_Comm_set_errhandler on MPI_COMM_SELF when you're on the World model, or via the mpi_initial_errhandler CLI argument to mpiexec, or via 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 gets called for MPI I/O functions, and the MPI_ERRORS_ABORT error handler gets called for all other MPI functions. Periodt.
Open MPI ships with three predefined error handlers you can use:
MPI_ERRORS_ARE_FATALβ causes the program to abort all connected MPI processes. dramatic much? yes. but that's the point. π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 ifMPI_Abortwas called on that communicator. 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. Called on a session? It aborts only the local process.MPI_ERRORS_RETURNβ returns an error code back to the application. polite king behavior π
MPI applications can also cook up their own error handlers by calling:
MPI_Comm_create_errhandlerand thenMPI_Comm_set_errhandlerMPI_File_create_errhandlerand thenMPI_File_set_errhandlerMPI_Session_create_errhandlerand thenMPI_Session_set_errhandler, or atMPI_Session_initMPI_Win_create_errhandlerand thenMPI_Win_set_errhandler
β οΈ heads up bestie: MPI does not guarantee that an MPI program can continue past an error. so likeβ¦ don't count on it. π
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_InitMPI_Init_thread
π Copyright π
2003-2026, The Open MPI Community
okay that's the whole page, bestie β the Open MPI crew gave us this one on Sep 10, 2026, and it's literally filed under MPI_IS_THREAD_MAIN(3). go find out if you're the main thread, you probably are πβ¨π
π¦ where this page comes from
- ubuntu stonking: openmpi-doc 5.0.10-6 Β· other
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms