MPI_QUERY_THREAD(3)

πŸŽ€ MPI_Query_thread: returns the current level of thread support πŸŽ€

hiii bestie, welcome to the Open MPI manual πŸ’– this one's a lil cutie β€” it's all about asking MPI "hey, how threaded are we actually allowed to be rn?" no cap, it's a vibe check for your thread support level ✨


🌸 SYNTAX 🌸

πŸ’œ C Syntax

#include <mpi.h>

int MPI_Query_thread(int *provided)

πŸ’œ Fortran Syntax

USE MPI
! or the older form: INCLUDE 'mpif.h'
MPI_QUERY_THREAD(PROVIDED, IERROR)
     INTEGER PROVIDED, IERROR

πŸ’œ Fortran 2008 Syntax

USE mpi_f08
MPI_Query_thread(provided, ierror)
     INTEGER, INTENT(OUT) :: provided
     INTEGER, OPTIONAL, INTENT(OUT) :: ierror

πŸ¦‹ OUTPUT PARAMETERS πŸ¦‹

  • provided β€” C/Fortran only 🫢 this is where the level of thread support lands. it's an integer, bestie.
  • ierror β€” Fortran only πŸ’… the error status, also an integer.

✨ DESCRIPTION ✨

okay so this routine returns, in provided, the current level of thread support. simple as that πŸ’…

and here's the tea: if MPI was initialized by a call to MPI_Init_thread, then provided will have the exact same value that MPI_Init_thread returned. periodt. no surprises, no plot twists πŸŽ€

the possible values of provided are these lil icons:

  • MPI_THREAD_SINGLE β€” only one thread may execute. it's giving solo era πŸ™ˆ
  • MPI_THREAD_FUNNELED β€” if the process is multithreaded, only the thread that called MPI_Init[_thread] may make MPI calls. one main character only πŸ‘‘
  • MPI_THREAD_SERIALIZED β€” if the process is multithreaded, only one thread may make MPI library calls at one time. take turns, besties, we're not animals πŸ’–
  • MPI_THREAD_MULTIPLE β€” if the process is multithreaded, multiple threads may call MPI at once with no restrictions. absolute chaos, slay πŸ”₯

πŸ’€ NOTES πŸ’€

so in Open MPI, here's the lowkey important bit: provided is always MPI_THREAD_SINGLE β€” unless your program has been linked with the multithreaded library, in which case provided is MPI_THREAD_MULTIPLE. that's it, that's the whole spectrum. iykyk πŸ€·β€β™€οΈ


😭 ERRORS 😭

almost all MPI routines return an error value, bestie. 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 comes back, the current MPI error handler associated with the communication object (like a communicator, window, or file, you know the vibe) gets called. if no communication object is associated with the MPI call, then the call is treated as attached to MPI_COMM_SELF and it'll call the associated MPI error handler instead. 🫢

and when MPI_COMM_SELF is not 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. the initial error handler can be changed 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. πŸ™ˆ

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. πŸŽ€

Open MPI includes three predefined error handlers that can be used:

  • MPI_ERRORS_ARE_FATAL β€” causes the program to abort all connected MPI processes. dramatic, but make it fatal πŸ’€
  • 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 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. if called on a session, it aborts only the local process. πŸ’…
  • MPI_ERRORS_RETURN β€” returns an error code to the application. polite, respectful, iconic ✨

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
no cap, note that MPI does not guarantee that an MPI program can continue past an error. 😭 so don't be out here assuming you can just keep vibing after one.

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_Init
  • MPI_Init_thread

2003-2026, The Open MPI Community


and that's the whole page, bestie 🫢 this lil manual page came from the Open MPI crew, dated Sep 10, 2026, and yeah β€” MPI_QUERY_THREAD(3). now go forth and thread responsibly πŸ’…βœ¨πŸŒΈ

πŸ“¦ where this page comes from