MPI_GROUP_DIFFERENCE(3)

πŸ¦‹ MPI_Group_difference(3) β€” an Open MPI glow-up πŸ¦‹

okay bestie, welcome to the MPI_Group_difference(3) page from Open MPI β€” this is the group-math one and it's honestly kind of iconic. let's get into it πŸ’–


🌸 NAME 🌸

MPI_Group_difference β€” makes a new group out of the difference of two groups. set math but make it parallel πŸ’…


✨ SYNTAX ✨

πŸŽ€ C Syntax

#include <mpi.h>

int MPI_Group_difference(MPI_Group group1, MPI_Group group2,
    MPI_Group *newgroup)

πŸŽ€ Fortran Syntax

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

MPI_GROUP_DIFFERENCE(GROUP1, GROUP2, NEWGROUP, IERROR)
    INTEGER GROUP1, GROUP2, NEWGROUP, IERROR

πŸŽ€ Fortran 2008 Syntax

USE mpi_f08

MPI_Group_difference(group1, group2, newgroup, ierror)
    TYPE(MPI_Group), INTENT(IN) :: group1, group2
    TYPE(MPI_Group), INTENT(OUT) :: newgroup
    INTEGER, OPTIONAL, INTENT(OUT) :: ierror

πŸ’œ INPUT PARAMETERS πŸ’œ

  • group1 : the first group, a handle. the main character of this operation ngl 🫢
  • group2 : the second group, also a handle.

πŸ“ OUTPUT PARAMETERS πŸ“

  • newgroup : the difference group (handle). this is the new baby that gets born ✨
  • ierror : Fortran only β€” error status (integer). C girlies get their error as the return value instead, iykyk.

🌈 DESCRIPTION 🌈

the set-like operations are defined like this, periodt:

  • union β€” all elements of the first group (group1), followed by all elements of the second group (group2) that are not in the first group
  • intersect β€” all elements of the first group that are also in the second group, ordered as in the first group
  • difference β€” all elements of the first group that are not in the second group, ordered as in the first group
lowkey important: for all these operations, the order of processes in the output group is decided primarily by order in the first group (if that's possible), and then, if it's necessary, by order in the second group. so first group stays winning πŸ‘‘

and like, neither union nor intersection is commutative β€” but both are associative, and that's just the vibe. fr fr.

the new group can totally be empty, i.e. equal to MPI_GROUP_EMPTY. it's giving minimalist πŸ’€


πŸ’€ ERRORS πŸ’€

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

before that error value comes back, the current MPI error handler associated with the communication object (e.g. communicator, window, file) gets called. if there's no communication object associated with the MPI call, then the call counts as being attached to MPI_COMM_SELF and will 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 using the Sessions Model exclusively) the error raises the initial error handler. you can change that initial error handler by calling MPI_Comm_set_errhandler on MPI_COMM_SELF when you're using the World model, or with 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 MPI_ERRORS_RETURN gets called for MPI I/O functions, and MPI_ERRORS_ABORT gets called for all the other MPI functions. them's the rules 🧚

Open MPI ships three predefined error handlers you can use:

  • MPI_ERRORS_ARE_FATAL β€” causes the program to abort all connected MPI processes. dramatic much? πŸ’€
  • 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. context matters bestie ✨
  • MPI_ERRORS_RETURN β€” returns an error code to the application. polite king behavior πŸ‘‘

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… no cap, don't 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. yes it's a real section, go read it, it's good for you 🫢


πŸ”₯ SEE ALSO πŸ”₯

MPI_Group_free


copyright 2003-2026, The Open MPI Community β€” all theirs, not mine πŸ’–


and that's the page bestie!! written up in the Open MPI docs, dated Sep 11, 2026 (yes, the future, she's ahead of her time ⭐). go forth and difference some groups, you absolute icon πŸŒˆπŸ’…

πŸ“¦ where this page comes from