在多个节点上运行 python 脚本的 Slurm 参数

问题描述 投票:0回答:0

我正在尝试在集群上并行运行 python 脚本,但我发现 slurm 非常混乱。

我可以访问不允许我在单个节点上运行我的脚本的 HPC 集群,我必须保留至少四个(完整)节点。每个节点有 128 个 CPU,我的脚本使用一个输入文件和指令来执行一些分析。它基本上读取输入的 txt 文件,每一行都有 3 个参数,这些参数被传递给运行程序的函数。默认情况下,该程序使用它找到的所有可用 CPU,但如果我愿意,我可以将此数量限制为 16。

我正在尝试使用 mpirun 在每个节点上运行我的脚本的一份副本,其中包含四个不同的输入文件。每次运行都是独立的,不需要来自其他运行的数据。目前我的 sbatch 脚本看起来像这样:

#!/bin/bash

#SBATCH --time=0-0:15:00
#SBATCH --partition=normal

## Set number of nodes
#SBATCH --nodes=4
#SBATCH --ntasks-per-node=1
#SBATCH --exclusive

## Recommended safety settings:
set -o errexit # Make bash exit on any error
set -o nounset # Treat unset variables as errors

## Load module required for mpirun
module load foss/2020a

DOCK_OUT=/dock_out
INPUT_FILES=/4_input_files

## The following lines will extract the name of nodes assigned by slurm and
## save those names in <nodes> files
## Add one line for each node you are allocating for this job
scontrol show hostname $SLURM_JOB_NODELIST | perl -ne 'chomb; print "$_"x1'> hosts
split -l1 --numeric-suffix=1 --suffix-length=1 hosts host
mkdir -p $DOCK_OUT
#exit

mpirun -np 1 -hostfile host1 --map-by node python run_docking.py $INPUT_FILES/input1.txt > $DOCK_OUT/node1.out &
pid1=$!
mpirun -np 1 -hostfile host2 --map-by node python run_docking.py $INPUT_FILES/input2.txt > $DOCK_OUT/node2.out &
pid2=$!
mpirun 1 -np 1 -hostfile host3 --map-by node python run_docking.py $INPUT_FILES/input3.txt > $DOCK_OUT/node3.out &
pid3=$!
mpirun -np 1 -hostfile host4 --map-by node python run_docking.py $INPUT_FILES/input4.txt > $DOCK_OUT/node4.out &
pid4=$!

wait $pid1 $pid2 $pid3 $pid4

我不明白如何设置 slurm(和 mpirun)选项,以便每个节点在所有 128 个 CPU 上运行我的脚本的一个副本。我试过设置:

  1. --ntaskspernode:1 或 128
  2. -np:1 或 128

还有许多其他选项,但我仍然无法按照自己的意愿运行它。 问题是当我使用 -np=128 时,所有 128 个 CPU 都被使用但我用完了许可证(我的脚本运行一个程序并且我们有有限数量的可用许可证)。据我所知,-np 表示程序 mpirun 将启动多少个副本。因此我试图将它设置为 1,但只有 1 个 CPU 工作,其他 127 个是空的。

最初的想法是在每个节点上运行此脚本 8 次,每个节点有 16 个 CPU 以最有效的方式拆分工作,总共 32 次并行运行(具有 32 个不同的输入文件)。 我不得不放弃这个想法,因为事情太复杂了,而且 slurm 的定义对我来说非常复杂和混乱。

你们中有人知道如何去做吗?理想的解决方案是 4 个节点,每个节点运行 8 次,每次运行 16 个 CPU。但每个节点运行 1 次也足以在合理的时间内运行我的工作。

bash parallel-processing slurm hpc openmpi
© www.soinside.com 2019 - 2024. All rights reserved.