SLURM sbatch脚本中使用bash变量 [英] Use Bash variable within SLURM sbatch script

查看:2237
本文介绍了SLURM sbatch脚本中使用bash变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从另一个文件中的值和提交SLURM脚本中使用。不过,我得到的值为非数值,换句话说一个错误,它没有被取消引用。

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.

下面是脚本:

#!/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

当我运行这个作为一个正常的Bash shell脚本,它打印出正确特效的数量,使正确的的mpirun 电话。因此, AWK 命令解析出特效的数量正确,如预期的变量间接引用。

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.

然而,当我使用提交这SLURM:

However, when I submit this to SLURM using:

sbatch myScript.sh

我得到的错误:

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

任何人都可以在这方面帮助?

Can anyone help with this?

推荐答案

这是行不通的。当您运行会发生什么

This won't work. What happens when you run

sbatch myscript.sh

是SLURM解析为那些特殊#SBATCH行脚本,生成一个工作记录,某处存储批处理脚本。只是后来在作业运行时执行的批处理脚本。

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.

所以,你需要构建你在一个稍微不同的方式工作流程,并首先计算你提交作业之前,需要特效的数量。请注意,您可以使用类似

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

,则不需要自动生成的脚本(也的mpirun应该能够自动获取特效的数目中的分配,没有必要使用-np)。

, 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").

这篇关于SLURM sbatch脚本中使用bash变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆