如何在节点上均匀分配 slurm 任务?

How to distribute slurm tasks evenly over the nodes?

我想在一个 sbatch 脚本中使用 s运行 命令 运行 集群上的脚本 ~200 次。由于执行脚本需要一些时间,因此最好将任务均匀分布在集群中的节点上。遗憾的是,我对此有疑问。

现在,我创建了一个示例脚本 ("hostname.sh") 来测试 sbatch 脚本中的不同参数:

echo `date +%s` `hostname`
sleep 10

这是我的 sbatch 脚本:

#SBATCH --ntasks=15
#SBATCH --cpus-per-task=16

for i in `seq 200`; do
    srun -n1 -N1 bash hostname.sh &
done

wait

我希望 hostname.sh 执行 200 次(for 循环),但同时只有 15 个任务 运行ning (--ntasks=15)。由于我最大的节点有 56 个核心,因此只有三个作业应该能够同时在该节点上 运行 (--cpus-per-task=16)。

从脚本的输出中我可以看到前九个任务分布在集群中的九个节点上,但所有其他任务(191!)同时在一个节点上执行。整个 sbatch 脚本执行只用了大约 15 秒。

我想我误解了一些 slurm 的参数,但查看官方文档并没有帮助我。

您需要在该上下文中使用 srun--exclusive 选项:

srun -n1 -N1 --exclusive bash hostname.sh &

来自srun manpage

By default, a job step has access to every CPU allocated to the job. To ensure that distinct CPUs are allocated to each job step, use the --exclusive option.

另请参阅上述文档中的最后一个示例。