如何为目录中的不同 $arg 并行运行相同的 python 脚本

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

我必须为大约 10'000 个对象运行一系列 python 脚本。每个对象都由我的目录中的一行参数来表征。 在我的计算机上,为了测试脚本,我只是使用了 bash 文件,例如:

totrow=`wc -l < catalogue.txt`

for (( i =1; i <=  ${totrow}; i++ )); do

    
    arg1=$(awk 'NR=='${i}' ' catalogue.txt)   
    
    arg2=$(awk 'NR=='${i}'' catalogue.txt)    
    
    arg3=$(awk 'NR=='${i}'' catalogue.txt)
        
    python3 script1.py  ${arg1} ${arg2} ${arg3} 

done    

为目录的每一行运行脚本。 现在我想在超级计算机上运行所有内容(带有 slurm 系统)。 我想做的,它正在运行,例如20 个对象同时在 20 个 cpu 上(因此同时有 20 行),并以这种方式对整个目录进行操作。

有什么建议吗? 谢谢!

python bash slurm sbatch
1个回答
1
投票

您可以将其设置为数组作业。将循环的内部部分放入

something.slurm
文件中,并将
i
设置为等于该文件顶部的数组元素 ID (
$SLURM_ARRAY_TASK_ID
)(.slurm 文件只是带有作业信息的普通 shell 脚本编码在注释中)。然后使用
sbatch array=1-$totrow something.slurm
启动作业。

这会将每个 Python 调用安排为单独的任务,并将其编号从 1 到

$totrow
。 SLURM 将在下一个可用的 CPU 上运行它们中的每一个,可能全部同时运行。

© www.soinside.com 2019 - 2024. All rights reserved.