MPI_COMM_SIZE(3)
π NAME
MPI_Comm_size β returns the size of the group associated with a communicator. yes bestie that's literally it, it's the "how many of us are in here" function π
(this page is from the Open MPI manual, welcome to the group chat)
β¨ SYNTAX β¨
πΈ C Syntax
#include <mpi.h>
int MPI_Comm_size(MPI_Comm comm, int *size)
π¦ Fortran Syntax
USE MPI
! or the older form: INCLUDE 'mpif.h'
MPI_COMM_SIZE(COMM, SIZE, IERROR)
INTEGER COMM, SIZE, IERROR
π§ Fortran 2008 Syntax
USE mpi_f08
MPI_Comm_size(comm, size, ierror)
TYPE(MPI_Comm), INTENT(IN) :: comm
INTEGER, INTENT(OUT) :: size
INTEGER, OPTIONAL, INTENT(OUT) :: ierror
π«Ά INPUT PARAMETER
commβ the communicator (handle). that's the whole input, she's low maintenance π
π OUTPUT PARAMETERS
sizeβ number of processes in the group ofcomm(integer). like, the headcount πierrorβ Fortran only: error status (integer).
π DESCRIPTION
okay so this function tells you the number of processes involved in a communicator. if you pass it MPI_COMM_WORLD, it hands you the total number of processes available. periodt.
it's exactly equivalent to grabbing the communicator's group with MPI_Comm_group, computing the size using MPI_Group_size, and then freeing that temporary group via MPI_Group_free. same energy, way less typing β¨
plot twist though: if the communicator is an inter-communicator (the kind that enables communication between two groups), this function returns the size of the local group. if you want the size of the remote group, you gotta use the MPI_Comm_remote_size function instead. different function, different vibe, iykyk.
this call is often used with MPI_Comm_rank to figure out how much concurrency is actually available for a specific library or program. MPI_Comm_rank tells you the rank of the process that calls it, in the range from 0 . . π₯
π NOTE
MPI_COMM_NULL is not considered a valid argument to this function. not me warning you about it, but like, i'm warning you about it π
π₯ ERRORS
almost all MPI routines return an error value β C routines as the return result of the function, and Fortran routines in the last argument. no cap.
before the error value is returned, the current MPI error handler associated with the communication object (e.g., communicator, window, file) is called. if no communication object is 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 (i.e., before MPI_Init/MPI_Init_thread, after MPI_Finalize, or when using the Sessions Model exclusively) the error raises the initial error handler. that initial error handler can be changed by calling MPI_Comm_set_errhandler on MPI_COMM_SELF when using the World model, or the mpi_initial_errhandler CLI argument to mpiexec or 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. she's thorough π
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 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. multitasking queen πMPI_ERRORS_RETURNβ returns an error code to the application. the polite one π«Ά
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, fr fr, do not assume you can just keep going π
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_Comm_groupMPI_Comm_rankMPI_Comm_compare
π COPYRIGHT
2003-2026, The Open MPI Community
and that's the whole page bestie π«Ά brought to you by the Open MPI girlies, dated Sep 11, 2026 β go forth and count your processes, you're gonna slay β¨ππ
π¦ 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