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 βtruemeans yes,falsemeans 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 = 4index = 2, 3, 4, 6edges = 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_errhandleronMPI_COMM_SELFwhen you're using the World model, or - the
mpi_initial_errhandlerCLI argument tompiexec, 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 ifMPI_Abortwas called on that communicator. if it's 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. 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_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: 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
π Copyright π
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
- ubuntu stonking: openmpi-doc 5.0.10-6 Β· other
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms