17.2.478. OMPI_Affinity_str
OMPI_Affinity_str - 获取当前进程的处理器亲和性信息的格式化字符串
17.2.478.1. 语法
17.2.478.1.1. C语法
#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])
17.2.478.1.2. Fortran语法
该函数没有Fortran绑定。
17.2.478.1.3. Fortran 2008 语法
该函数没有Fortran 2008绑定。
17.2.478.1.4. C++ 语法
该函数没有C++绑定。
17.2.478.2. 输入参数
fmt_type: 一个枚举值,指示如何格式化返回的ompi_bound和current_binding字符串。OMPI_AFFINITY_RSRC_STRING_FMT将字符串返回为人类可读的资源名称,例如"插槽0,核心0"。OMPI_AFFINITY_LAYOUT_FMT returns ASCII art representing where this MPI: 进程相对于机器资源布局的绑定位置。例如"[. B][. .]"表示调用该例程的进程绑定在一个具有2个插槽(每个插槽包含2个核心)的系统中的插槽0、核心1上。查看 下方 获取 更多 输出 示例。:
17.2.478.3. 输出参数
ompi_bound: 一个描述Open MPI将此进程绑定到哪些处理器的格式化字符串,或表示Open MPI未绑定此进程的字符串。current_binding: 一个格式化的字符串,描述当前进程绑定到的处理器,或表示该进程绑定到所有可用处理器(因此被视为"未绑定")的字符串。exists: 一个格式化的字符串,描述该主机上可用的套接字和存在的套接字。
17.2.478.4. 描述
Open MPI 可以在进程启动时将进程绑定到特定的插槽和/或核心。这个非标准的 Open MPI 函数调用会返回关于以下三方面的格式化信息:
- Where Open MPI bound this process.
ompi_bound返回的字符串将指示Open MPI未将此进程绑定到任何内容,或者包含Open MPI绑定此进程的处理器详细描述。
- Where this process is currently bound.
无论Open MPI是否绑定了此进程,其他实体也可能已将其绑定。current_binding中返回的字符串将指示此进程的当前绑定状态,而无论Open MPI之前可能执行了什么操作。返回的字符串要么表示进程未绑定(意味着它绑定到所有可用处理器),要么包含当前进程绑定的套接字和核心的易读描述。
- What processors exist.
为了方便用户,exists字符串将包含该进程可见的套接字和核心的格式化描述(这通常是系统中的所有处理器)。
17.2.478.4.1. 示例
示例1: 使用资源字符串格式打印进程绑定信息。
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);
...
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
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
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);
...
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: [. . . .]
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: [. . . .]
另请参阅