在SLURM sbatch脚本中使用Bash变量

时间:2022-04-26 23:52:49

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 $2}' ./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命令正确地解析了进程的数量,并按预期取消了变量的引用。

However, when I submit this to SLURM using:

但是,当我提交给思乐姆时,我使用:

sbatch myScript.sh

I get the error:

我得到了错误:

sbatch: error: Invalid numeric value "`$numProcs`" for number of tasks.

Can anyone help with this?

有人能帮忙吗?

1 个解决方案

#1


7  

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

因此,您需要以略微不同的方式构造您的工作流,并在提交作业之前首先计算您需要的procs数量。注意,您可以使用类似的东西

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”)。

#1


7  

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

因此,您需要以略微不同的方式构造您的工作流,并在提交作业之前首先计算您需要的procs数量。注意,您可以使用类似的东西

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”)。