在 SLURM sbatch 脚本中使用 Bash 变量
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24508040/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Use Bash variable within SLURM sbatch script
提问by Madeleine P. Vincent
I'm trying to obtain a value from another file and use this within a SLURM submission script. However, I get an error that the value is non-numerical, in other words, it is not being dereferenced.
我试图从另一个文件中获取一个值并在 SLURM 提交脚本中使用它。但是,我收到一个错误,该值是非数字的,换句话说,它没有被取消引用。
Here is the script:
这是脚本:
#!/bin/bash
# This reads out the number of procs based on the decomposeParDict
numProcs=`awk '/numberOfSubdomains/ {print }' ./meshModel/decomposeParDict`
echo "NumProcs = $numProcs"
#SBATCH --job-name=SnappyHexMesh
#SBATCH --output=./logs/SnappyHexMesh.log
#
#SBATCH --ntasks=`$numProcs`
#SBATCH --time=240:00
#SBATCH --mem-per-cpu=4000
#First run blockMesh
blockMesh
#Now decompose the mesh
decomposePar
#Now run snappy in parallel
mpirun -np $numProcs snappyHexMesh -parallel -overwrite
When I run this as a normal Bash shell script, it prints out the number of procs correctly and makes the correct mpirun
call. Thus the awk
command parses out the number of procs correctly and the variable is dereferenced as expected.
当我将它作为普通的 Bash shell 脚本运行时,它会正确打印出 proc 的数量并进行正确的mpirun
调用。因此,该awk
命令正确解析出 procs 的数量,并按预期取消引用该变量。
However, when I submit this to SLURM using:
但是,当我使用以下方法将其提交给 SLURM 时:
sbatch myScript.sh
I get the error:
我收到错误:
sbatch: error: Invalid numeric value "`$numProcs`" for number of tasks.
Can anyone help with this?
有人能帮忙吗?
采纳答案by janneb
This won't work. What happens when you run
这行不通。跑步时会发生什么
sbatch myscript.sh
sbatch myscript.sh
is that slurm parses the script for those special #SBATCH lines, generates a job record, stores the batch script somewhere. The batch script is executed only later when the job runs.
是 slurm 为那些特殊的 #SBATCH 行解析脚本,生成作业记录,将批处理脚本存储在某处。批处理脚本仅在作业运行时执行。
So you need to structure you workflow in a slightly different way, and first calculate the number of procs you need before submitting the job. Note that you can use something like
因此,您需要以稍微不同的方式构建您的工作流程,并在提交作业之前首先计算您需要的进程数。请注意,您可以使用类似
sbatch -n $numProcs myscript.sh
sbatch -n $numProcs myscript.sh
, you don't need to autogenerate the script (also, mpirun should be able to get the number of procs in your allocation automatically, no need to use "-np").
,您不需要自动生成脚本(此外,mpirun 应该能够自动获取分配中的 proc 数量,无需使用“-np”)。