0

Our school uses SLURM as the queueing system, where one has to specify some "preambles" before other commands. Hence, a shell script in this case usually starts with

#!/bin/bash

#SBATCH -n 10               # Number of cores requested
#SBATCH -N 1                # Ensure that all cores are on one machine
#SBATCH -p general          # Partition to submit to
#SBATCH --mem-per-cpu=20000 # Memory per cpu in MB (see also --mem)
#SBATCH -o out              # Standard out goes to this file 

Now, I wish to make my core number as a constant, which facilitates modifications. I did

#!/bin/bash

ZEROTH_PORT=50000
NO_CORES=10

#SBATCH -n $((NO_CORES))    # Number of cores requested
#SBATCH -N 1                # Ensure that all cores are on one machine
#SBATCH -p general          # Partition to submit to
#SBATCH --mem-per-cpu=20000 # Memory per cpu in MB (see also --mem)
#SBATCH -o out              # Standard out goes to this file 

It fails at #SBATCH -n $((NO_CORES)). As a complete newbie in shell script, I have no idea why $((NO_CORES)) here returns the value of NO_CORES.

4

1 回答 1

0

$(( … ))是算术评估上下文。由于NO_CORES是一个整数,并且在语法中没有对其进行任何其他操作,因此结果是 的扩展值NO_CORES。但是如果你知道参数是一个整数,你可以使用一个正常的扩展:

NO_CORES=10
SBATCH -n $NO_CORES # -> SBATCH -n 10
于 2014-07-04T01:34:56.343 回答