MPI_COMM_COMPARE(3)

πŸ’… MPI_COMM_COMPARE(3) β€” Open MPI, bestie edition πŸŽ€

okay so listen β€” this is the MPI_COMM_COMPARE(3) page from Open MPI, and it's literally just "are these two communicators the same, kinda the same, or not even close." tiny function, huge glow-up. let's get into it ✨


✨ NAME ✨

MPI_Comm_compare β€” compares two communicators. that's it. that's the whole vibe check πŸ¦‹


🌸 SYNTAX 🌸

C Syntax

#include <mpi.h>

int MPI_Comm_compare(MPI_Comm comm1, MPI_Comm comm2, int *result)

Fortran Syntax

USE MPI
! or the older form: INCLUDE 'mpif.h'

MPI_COMM_COMPARE(COMM1, COMM2, RESULT, IERROR)
    INTEGER COMM1, COMM2, RESULT, IERROR

Fortran 2008 Syntax

USE mpi_f08

MPI_Comm_compare(comm1, comm2, result, ierror)
    TYPE(MPI_Comm), INTENT(IN) :: comm1, comm2
    INTEGER, INTENT(OUT) :: result
    INTEGER, OPTIONAL, INTENT(OUT) :: ierror

🫢 INPUT PARAMETERS 🫢

  • comm1 β€” comm1, and it's a handle. that's the whole assignment bestie πŸ’–
  • comm2 β€” comm2. also a handle. yes we're comparing them, keep up 😌

⭐ OUTPUT PARAMETERS ⭐

  • result β€” the result of the comparison, an integer. this is where the drama lands, iykyk πŸ”₯
  • ierror β€” Fortran only, the error status (integer). Fortran girlies get their own lil slot for it πŸ™ˆ

πŸ‘‘ DESCRIPTION πŸ‘‘

okay this is the part where it gets good, so pay attention ✨ here's the ranking, from "literally the same" to "who even are you":

  • MPI_IDENT β€” drops if and only if comm1 and comm2 are handles for the same object. like, identical groups and the same contexts. same same. no cap πŸ’…
  • MPI_CONGRUENT β€” happens when the underlying groups are identical in constituents and rank order, and the only thing different is the context. so they're twinsies who just got assigned different lockers πŸŽ€
  • MPI_SIMILAR β€” the group members of both communicators are the same, but the rank order differs. same squad, different seating chart 😭
  • MPI_UNEQUAL β€” results otherwise. aka not it. different vibes entirely πŸ’€
so yeah β€” groups same + context same = MPI_IDENT, groups same + context different = MPI_CONGRUENT, same members + different ordering = MPI_SIMILAR, anything else = MPI_UNEQUAL. the more you know 🌈

πŸ’€ ERRORS πŸ’€

okay so errors, strap in, this is the long part but it's all important, don't skip 🫢

almost all MPI routines return an error value. C routines hand it back as the return result of the function, and Fortran routines put it in the last argument.

before that error value is even returned, the current MPI error handler associated with the communication object (think: communicator, window, file β€” the whole little family) gets called. and if there's no communication object associated with the MPI call? then the call gets treated as attached to MPI_COMM_SELF, and it'll call the associated MPI error handler. and when MPI_COMM_SELF is not initialized β€” like 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 that 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
  • via an info key to MPI_Comm_spawn/MPI_Comm_spawn_multiple.

if no other appropriate error handler has been set, then MPI_ERRORS_RETURN gets called for MPI I/O functions, and MPI_ERRORS_ABORT gets called for all other MPI functions. yes, ALL the others. choices were made πŸ’…

🧚 the three predefined error handlers Open MPI ships with 🧚

  • MPI_ERRORS_ARE_FATAL β€” causes the program to abort all connected MPI processes. dramatic, but make it cluster-wide πŸ’€
  • 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 if MPI_Abort was called on that communicator. if it's 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 it's called on a session, it aborts only the local process. situational awareness, we love to see it ✨
  • MPI_ERRORS_RETURN β€” returns an error code to the application. polite. respectful. hands you the L gently πŸŽ€

🌸 roll your own error handlers 🌸

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
note that MPI does not guarantee that an MPI program can continue past an error. so like... don't bank on it, 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 🌟


2003-2026, The Open MPI Community β€” and that's the whole bit, no cap πŸ‘‘


aaaand that's the page!! mwah, go compare some communicators πŸ’– this has been MPI_COMM_COMPARE(3) out of Open MPI, dated Sep 11, 2026 β€” see you in the next man page, bestie πŸ¦‹βœ¨πŸŽ€

πŸ“¦ where this page comes from