带有奇点的 slurm srun 没有正确编号 MPI 等级

问题描述

我有一个简单的 Fortran 程序,它可以在屏幕上为 MPI 程序中的每个处理器打印等级数和等级

   program hello
   include 'mpif.h'
   integer rank,size,ierror,tag,status(MPI_STATUS_SIZE)
   
   call MPI_INIT(ierror)
   call MPI_COMM_SIZE(MPI_COMM_WORLD,ierror)
   call MPI_COMM_RANK(MPI_COMM_WORLD,rank,ierror)
   print*,'Hello from rank','of ',size
   call MPI_FINALIZE(ierror)
   end

当我用 srun (slurm 20.11.3) 运行这个程序时,它按我的预期工作

> srun -n 2 -N 2 ./h.x
 Hello from rank           0 of            2
 Hello from rank           1 of            2

我在一个 docker 容器中编译了程序,并在我的 HPC 系统上使用了奇点(版本 3.6.1-1)来尝试在我的容器中运行相同的程序

> singularity pull docker://thomasrobinson/hello:latest
> srun -n 2 -N 2 singularity exec hello_latest.sif /opt/hello/hello.x
 Hello from rank           0 of            1
 Hello from rank           0 of            1

宿主系统和容器都有 mpich-falvor MPI。如果我将容器制作为单点而不是 docker,我会遇到同样的问题。如果我在没有 srun -n 2 的情况下执行 -N 2,我会遇到同样的问题。我注意到,如果我使用 mpirun --bootstrap ssh 而不是 srun ,那么我会得到预期的行为(与在我的主机系统上运行程序相同),但会影响性能。我在其他版本的奇点和 slurm 中遇到过这个问题。

我需要做什么才能使用 srun 运行我的容器?

解决方法

MPI 奇点的处理方式与正常情况略有不同。 Singularity MPI documentation 使用 sbatch,所以我会先用它进行测试,但我相信它也适用于 srun。

$ cat my_job.sh
#!/bin/bash
#SBATCH --job-name singularity-mpi
#SBATCH -N 2 # total number of nodes
#SBATCH --time=00:05:00 # Max execution time

mpirun -n 2 singularity exec hello_latest.sif /opt/hello/hello.x
$ sbatch my_job.sh

您可能还需要做一些额外的配置,但上面链接的文档中有很多关于如何最好地做到这一点的详细信息。