Micchaleq
Micchaleq

Reputation: 433

Insert system variables to SBATCH

I would like to ask you if is possible to pass global system variables to #SBATCH tags.

I would like to do somethink like that

SBATCH FILE

#!/bin/bash -l
ARG=64.dat
NODES=4
TASK_PER_NODE=8
NP=$((NODES*TASK_PER_NODE))

#SBATCH -J 'MPI'+'_'+$NODES+'_'+$TASK_PER_NODE
#SBATCH -N $NODES
#SBATCH --ntasks-per-node=$TASK_PER_NODE

It isn't workink so that is why I ask you.

Upvotes: 4

Views: 2257

Answers (1)

damienfrancois
damienfrancois

Reputation: 59320

Remember that SBATCH parameter lines are viewed by Bash as comments, so it will not try to interpret them at all.

Furthermore, the #SBATCH directives must be before any other Bash command for Slurm to handle them.

Alternatives include setting the parameters in the command line:

NODES=4 sbatch --nodes=$NODES ... submitscript.sh

or passing the submission script through stdin:

#!/bin/bash -l
ARG=64.dat
NODES=4
TASK_PER_NODE=8
NP=$((NODES*TASK_PER_NODE))

sbatch <<EOT
#SBATCH -J "MPI_$NODES_$TASK_PER_NODE"
#SBATCH -N $NODES
#SBATCH --ntasks-per-node=$TASK_PER_NODE

srun ...

EOT

In this later case, you will need to run the submission script rather than handing it to sbatch since it will run sbatch itself. Note also that string concatenation in Bash is not achieved with the + sign.

Upvotes: 8

Related Questions