OMPI_AFFINITY_STR(3)
π OMPI_Affinity_str β the Open MPI page, bestie edition π
okay so you found the OMPI_AFFINITY_STR(3) page in the Open MPI manual, and honestly? you're about to find out exactly which CPU got stuck with your process. this is the one that gives you prettyprint strings of processor affinity information for this process. no cap, that's literally what it does: OMPI_Affinity_str β obtain prettyprint strings of processor affinity information for this process. πΈ
β¨ SYNTAX β¨
π§ C Syntax
#include <mpi.h>
#include <mpi-ext.h>
int OMPI_Affinity_str(ompi_affinity_fmt_type_t fmt_type,
char ompi_bound[OMPI_AFFINITY_STRING_MAX],
char current_binding[OMPI_AFFINITY_STRING_MAX],
char exists[OMPI_AFFINITY_STRING_MAX])
π Fortran Syntax
There is no Fortran binding for this function. bestie. i'm so sorry. π
π Fortran 2008 Syntax
There is no Fortran 2008 binding for this function. still no. π«Ά
π C++ Syntax
There is no C++ binding for this function. yeah. C only, i fear. π
π INPUT PARAMETERS π
fmt_typeβ an enum that tells the function how to format theompi_boundandcurrent_bindingstrings it hands back. and the options are lowkey cute:OMPI_AFFINITY_RSRC_STRING_FMTβ returns the string as human-readable resource names, like"socket 0, core 0". very demure, very mindful. β¨OMPI_AFFINITY_LAYOUT_FMTβ returns ASCII art showing where this MPI process is bound relative to the machine resource layout. for example,"[. B][. .]"means the process that called the routine is bound to socket 0, core 1, on a system with 2 sockets, each of which contains 2 cores. art. it's giving gallery. πΌοΈ- See below for more output examples. π
π OUTPUT PARAMETERS π
ompi_boundβ a prettyprint string describing what processor(s) Open MPI bound this process to β or a string telling you Open MPI did not bind this process at all. mixed signals but ok. πcurrent_bindingβ a prettyprint string describing what processor(s) this process is currently bound to β or a string saying the process is bound to all available processors (which means it's consideredβunboundβ). we love a free spirit. π¦existsβ a prettyprint string describing the available sockets and sockets on this host. (yes, it really says "sockets and sockets" β iconic typo energy, we're keeping it fr fr π)
π DESCRIPTION π
Open MPI may bind a process to specific sockets and/or cores at process launch time. this here is a non-standard Open MPI function call, and it returns prettyprint info about three things:
- Where Open MPI bound this process. the string that lands in
ompi_boundwill either say that Open MPI did not bind this process to anything, or it'll contain a prettyprint description of the processor(s) that Open MPI bound this process to. simple as that. β¨ - Where this process is currently bound. regardless of whether Open MPI bound this process or not β plot twist β another entity may have bound it. the string in
current_bindingtells you the current binding of this process, no matter what Open MPI did earlier. it'll either say the process is unbound (meaning it's bound to all available processors) or it'll hand you a prettyprint description of the sockets and cores this process is currently bound to. drama. π - What processors exist. as a lil convenience for you, the
existsstring contains a prettyprint description of the sockets and cores this process can see β which is usually all the processors in the system. the whole vibe. π
π EXAMPLES π
Example 1: Print out processes binding using resource string format. π
int rank;
char ompi_bound[OMPI_AFFINITY_STRING_MAX];
char current_binding[OMPI_AFFINITY_STRING_MAX];
char exists[OMPI_AFFINITY_STRING_MAX];
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
OMPI_Affinity_str(OMPI_AFFINITY_RSRC_STRING_FMT,
ompi_bound, current_binding, exists);
printf("rank %d: \n"
" ompi_bound: %s\n"
" current_binding: %s\n"
" exists: %s\n",
rank, ompi_bound, current_binding, exists);
...
Output of mpirun -n 2 -bind-to-core a.out:
rank 0:
ompi_bound: socket 0[core 0]
current_binding: socket 0[core 0]
exists: socket 0 has 4 cores
rank 1:
ompi_bound: socket 0[core 1]
current_binding: socket 0[core 1]
exists: socket 0 has 4 cores
Output of mpirun -n 2 -bind-to-socket a.out:
rank 0:
ompi_bound: socket 0[core 0-3]
current_binding: Not bound (or bound to all available processors)
exists: socket 0 has 4 cores
rank 1:
ompi_bound: socket 0[core 0-3]
current_binding: Not bound (or bound to all available processors)
exists: socket 0 has 4 cores
Example 2: Print out processes binding using layout string format. πΌοΈ
int rank;
char ompi_bound[OMPI_AFFINITY_STRING_MAX];
char current_binding[OMPI_AFFINITY_STRING_MAX];
char exists[OMPI_AFFINITY_STRING_MAX];
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
OMPI_Affinity_str(OMPI_AFFINITY_LAYOUT_FMT,
ompi_bound, current_binding, exists);
printf("rank %d: \n"
" ompi_bound: %s\n"
" current_binding: %s\n"
" exists: %s\n",
rank, ompi_bound, current_binding, exists);
...
Output of mpirun -n 2 -bind-to-core a.out:
rank 0:
ompi_bound: [B . . .]
current_binding: [B . . .]
exists: [. . . .]
rank 1:
ompi_bound: [. B . .]
current_binding: [. B . .]
exists: [. . . .]
Output of mpirun -n 2 -bind-to-socket a.out:
rank 0:
ompi_bound: [B B B B]
current_binding: [B B B B]
exists: [. . . .]
rank 1:
ompi_bound: [B B B B]
current_binding: [B B B B]
exists: [. . . .]
π¦ See also: π¦
mpirun(1)<#man1-mpirun>
ngl bestie, if you're here you probably want mpirun(1) too. go look. i'll wait. π
π Copyright π
2003-2026, The Open MPI Community
and that's the whole page, periodt. π this one comes to you from Open MPI, dated Sep 10, 2026, filed under OMPI_AFFINITY_STR(3) β go check your binding, main character. πβ¨π«Ά
π¦ 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