第 24 章 在 HPC 环境中使用 Podman
您可以使用带有 Open MPI(消息传递接口)的 Podman ,来在高性能计算(HPC)环境中运行容器。
24.1. 使用带有 MPI 的 Podman 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
这个例子基于 Open MPI 的 ring.c 程序。在这个例子中, 一个值被所有进程以类似环形的方式传递。每次消息通过 rank 0 时,其值就会减少。当每个进程收到 0 信息时,它会把它传递给下一个进程,然后退出。通过先传递 0,每一个进程都会得到 0 信息,并可以正常退出。
先决条件
-
container-tools元数据包已安装。
流程
安装 Open MPI:
# dnf install openmpi要激活环境模块,请输入:
$ . /etc/profile.d/modules.sh加载
mpi/openmpi-x86_64模块:$ module load mpi/openmpi-x86_64另外,要自动载入
MPI/openmpi-x86_64模块,请将此行添加到.bashrc文件中:$ echo "module load mpi/openmpi-x86_64" >> .bashrc要将
mpirun与podman相结合,请使用以下定义创建一个容器:$ cat Containerfile FROM registry.access.redhat.com/ubi9/ubi RUN dnf -y install openmpi-devel wget && \ dnf clean all RUN wget https://raw.githubusercontent.com/open-mpi/ompi/master/test/simple/ring.c && \ /usr/lib64/openmpi/bin/mpicc ring.c -o /home/ring && \ rm -f ring.c构建容器:
$ podman build --tag=mpi-ring .启动容器。在有 4 个 CPU 的系统上,这个命令会启动 4 个容器:
$ mpirun \ --mca orte_tmpdir_base /tmp/podman-mpirun \ podman run --env-host \ -v /tmp/podman-mpirun:/tmp/podman-mpirun \ --userns=keep-id \ --net=host --pid=host --ipc=host \ mpi-ring /home/ring Rank 2 has cleared MPI_Init Rank 2 has completed ring Rank 2 has completed MPI_Barrier Rank 3 has cleared MPI_Init Rank 3 has completed ring Rank 3 has completed MPI_Barrier Rank 1 has cleared MPI_Init Rank 1 has completed ring Rank 1 has completed MPI_Barrier Rank 0 has cleared MPI_Init Rank 0 has completed ring Rank 0 has completed MPI_Barriermpirun会启动 4 个 Podman 容器,每个容器都运行一个ring二进制的实例。所有 4 个进程都通过 MPI 进行沟通。