12.8. 在Open MPI中使用基于MPIR的工具

传统MPIR规范定义了一个接口规范,调试器和其他工具可以通过该接口获取每个MPI应用进程的PID、主机名和可执行文件名。

本规范已被OpenPMIx项目中的PMIx工具API所取代。

使用传统MPIR规范的调试器和工具可以继续通过本节描述的MPIR适配模块正常运行。

12.8.1. 获取应用程序进程映射信息

MPIR 适配模块是一个独立模块,可被仍使用传统 MPIR 接口的调试器和工具用来连接到并行 MPI 应用程序。调试器或工具会将该适配模块作为其与应用程序mpirun(1)命令之间的中间进程启动。

MPIR shim模块实现了MPIR_Breakpoint函数,作为调试器和工具设置断点的钩子,以便在可用时读取MPIR处理映射。

关于shim模块的使用说明,请参阅 https://github.com/hpc/mpir-to-pmix-guide/blob/master/README.md

在使用该shim模块之前,您可能需要先构建它。该模块的源代码可以从MPIR to PMIx Shim代码库下载。

在构建并安装好MPIR shim模块后,请按照调试器或工具自带的说明文档操作,告知其MPIR shim模块的存放位置。


12.8.2. 构建MPIR Shim模块

以下是一个构建MPIR shim模块的示例shell脚本——您可能需要根据具体环境进行定制:

#!/usr/bin/env bash

set -euxo pipefail

cd $HOME
mkdir -p git
cd git

git clone https://github.com/hpc/mpir-to-pmix-guide.git
cd mpir-to-pmix-guide

# PMIX_ROOT must be set to your PMIx install root directory
# (which may be the same as your Open MPI installation directory)
if test -z "$PMIX_ROOT" -o ! -d "$PMIX_ROOT"; then
    echo "Set the env variable PMIX_ROOT to the location of your PMIx installation"
    exit 1
fi

./autogen.sh
./configure --prefix=$HOME/MPIR --with-pmix=$PMIX_ROOT
make
make install

12.8.3. 使用Open MPI验证MPIR shim功能

安装完成后,您可能需要验证MPIR垫片是否正常运行。以下是一个构建并运行简单MPI应用程序的shell脚本示例,同时用它来测试MPIR垫片。与之前的shell脚本示例类似,此脚本可能需要根据您的环境进行调整。

#!/usr/bin/env bash

set -euxo pipefail

# This script assumes the same directories and locations as the
# prior script.
BUILD_DIR=$HOME/git/mpir-to-pmix-guide

# Add the previously-installed MPIR shim into PATH and
# LD_LIBRARY_PATH (we assume that all relevant Open MPI / PMIx /
# etc. values already exist in PATH and LD_LIBRARY_PATH)
export PATH=$HOME/MPIR/bin:$PATH
export LD_LIBRARY_PATH=$HOME/MPIR/lib:$LD_LIBRARY_PATH

cat > testprog.c <<EOF
#include <mpi.h>
#include <unistd.h>
int main(int argc, char **argv) {
    MPI_Init(&argc, &argv);
    sleep(60);
    MPI_Finalize();
    return 0;
}
EOF
mpicc -o testprog testprog.c

# Test the shim in proxy mode.
# Manually verify that displayed process mapping is correct.
$BUILD_DIR/test/mpirshim_test mpirun -n 2 ./testprog

# Launch mpirun for attach test and get its PID
mpirun -n 2 ./testprog &
PID=$!
# Test shim attach mode.
# Manually verify that displayed process mapping is correct.
$BUILD_DIR/test/mpirshim_test -c $PID