MPI_GRAPH_CREATE(3)

πŸ’– MPI_Graph_create πŸ’–

okay bestie, welcome to the Open MPI manual page for MPI_Graph_create β€” no cap, this one's a banger. It makes you a brand new communicator with topology info attached. slay. πŸ¦‹


✨ SYNOPSIS ✨

🌸 C Syntax

#include <mpi.h>

int MPI_Graph_create(MPI_Comm comm_old, int nnodes, const int index[],
    const int edges[], int reorder, MPI_Comm *comm_graph)

🌸 Fortran Syntax

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

MPI_GRAPH_CREATE(COMM_OLD, NNODES, INDEX, EDGES, REORDER,
        COMM_GRAPH, IERROR)
    INTEGER COMM_OLD, NNODES, INDEX(*), EDGES(*)
    INTEGER COMM_GRAPH, IERROR
    LOGICAL   REORDER

🌸 Fortran 2008 Syntax

USE mpi_f08

MPI_Graph_create(comm_old, nnodes, index, edges, reorder, comm_graph,
        ierror)
    TYPE(MPI_Comm), INTENT(IN) :: comm_old
    INTEGER, INTENT(IN) :: nnodes, index(nnodes), edges(*)
    LOGICAL, INTENT(IN) :: reorder
    TYPE(MPI_Comm), INTENT(OUT) :: comm_graph
    INTEGER, OPTIONAL, INTENT(OUT) :: ierror

🌈 INPUT PARAMETERS 🌈

here's what you're handing over, bestie:

  • comm_old : the input communicator, and it has no topology on it (it's a handle).
  • nnodes : how many nodes are in the graph (integer, periodt).
  • index : an array of integers describing the node degrees (full explanation is down below, keep reading πŸ’…).
  • edges : an array of integers describing the graph edges (also explained below, iykyk).
  • reorder : whether the ranking may get reordered β€” true means yes, false means nope (logical).

πŸŽ€ OUTPUT PARAMETERS πŸŽ€

what you get back, and it's giving main character energy:

  • comm_graph : your new communicator with the graph topology added on (handle).
  • ierror : Fortran only β€” the error status (integer).

πŸ‘‘ DESCRIPTION πŸ‘‘

MPI_Graph_create hands you back a handle to a new communicator, and the graph topology info is attached to it. so cute. πŸ’–

if reorder = false, then every process keeps the exact same rank in the new group as it had in the old group. but if it's not false, the function is allowed to reorder the processes β€” it may shuffle y'all around. πŸŒͺ️

and here's the tea: if the size of the graph, nnodes, is smaller than the size of the group of comm_old, then some processes get returned MPI_COMM_NULL. it's exactly in analogy to MPI_Cart_create and MPI_Comm_split, fr fr.

⚠️ heads up bestie: the call is erroneous if the graph it specifies is larger than the group size of the input communicator. don't do that. πŸ’€

the three parameters nnodes, index, and edges together define the graph structure. nnodes is the number of nodes in the graph, and the nodes are numbered from 0 to nnodes-1.

the ith entry of the array index stores the total number of neighbors of the first i graph nodes. and the lists of neighbors of nodes 0, 1, …, nnodes-1 are stored in consecutive locations in the array edges. so edges is basically a flattened representation of the edge lists β€” like when you flatten a croissant but it's a graph. πŸ₯

the total number of entries in index is nnodes, and the total number of entries in edges is equal to the number of graph edges.

πŸ¦‹ The Example πŸ¦‹

the definitions of the arguments nnodes, index, and edges are illustrated with the following simple example.

say there are four processes 0, 1, 2, 3 with this adjacency matrix:

β€”β€”- β€”β€”β€”
Process Neighbors
β€”β€”- β€”β€”β€”
0       1, 3
1       0
2       3
3       0, 2
β€”β€”- β€”β€”β€”

then the input arguments are:

  • nodes = 4
  • index = 2, 3, 4, 6
  • edges = 1, 3, 0, 3, 0, 2

so here's how indexing works, and this part is important so don't scroll past it πŸ™ˆ

In C: index[0] is the degree of node zero, and index[i] - index[i-1] is the degree of node i, where i=1, … , nnodes-1. the list of neighbors of node zero lives in edges[j], for 0 <= j <= index[0] - 1, and the list of neighbors of node i, i > 0, lives in edges[j], index[i-1] <= j <= index[i] - 1.

In Fortran: index(1) is the degree of node zero, and index(i+1) - index(i) is the degree of node i, where i=1, … , nnodes-1. the list of neighbors of node zero lives in edges(j), for 1 <= j <= index(1), and the list of neighbors of node i, i > 0, lives in edges(j), index(i) + 1 <= j <= index(i + 1).

see? 1-indexed vs 0-indexed, the eternal struggle. 😭


πŸ’… ERRORS πŸ’…

almost all MPI routines return an error value, bestie. for C routines it comes back as the return result of the function, and for Fortran routines it lands in the last argument.

before that error value gets returned, the current MPI error handler associated with the communication object (think: communicator, window, file) gets called. and if there's no communication object associated with the MPI call, then the call is considered attached to MPI_COMM_SELF and it'll 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 you're using the Sessions Model exclusively), the error raises the initial error handler instead.

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
  • 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 the MPI_ERRORS_RETURN error handler gets called for MPI I/O functions, while the MPI_ERRORS_ABORT error handler gets called for all other MPI functions.

⭐ The Three Predefined Error Handlers ⭐

Open MPI ships with three of these cuties, ready to go:

  • MPI_ERRORS_ARE_FATAL β€” causes the program to abort all connected MPI processes. yeah. all of them. 😭
  • MPI_ERRORS_ABORT β€” an error handler you can invoke 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. and if it's called on a session, it aborts only the local process.
  • MPI_ERRORS_RETURN β€” returns an error code to the application. polite king. 🫢

🧚 DIY 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: 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, bestie.

see the Error Handling section of the MPI-3.1 standard for more information.

🌟 See also:

MPI_Graph_get


2003-2026, The Open MPI Community


and that's the whole page, bestie!! 🌈✨ this was the Open MPI MPI_Graph_create(3) man page, dated Sep 10, 2026 πŸ’– go forth and build your graphs, you absolute icon. periodt. πŸ’…πŸŽ€

πŸ“¦ where this page comes from