0

I tried to submit a job via the command line incorporating --wrap instead of submitting through a submission script. And for some reason none of the slurm_variables are initialized:

sbatch --job-name NVP --time 01:00:00 --nodes 1 --ntasks 1 --cpus-per-task 2 --wrap "echo "var1:" $SLURM_CPUS_PER_TASK "var2:" $SLURM_JOB_NAME"

In this case both $SLURM_CPUS_PER_TASK and $SLURM_JOB_NAME are empty. Once the exact same code is submitted via a script, the variables show up.

I could not figure out what is wrong with my command line submission.

MirrG
  • 406
  • 3
  • 10

1 Answers1

2

The problem is that you are not escaping the variable names and those get expanded by bash before submitting the job. Try using single quotes for the wrapped command like:

sbatch --job-name NVP --time 01:00:00 --nodes 1 --ntasks 1 --cpus-per-task 2 --wrap 'echo "var1:" $SLURM_CPUS_PER_TASK "var2:" $SLURM_JOB_NAME'

or if you need to use double quotes (for other variables expansion), just escape the variables with a \ like:

sbatch --job-name NVP --time 01:00:00 --nodes 1 --ntasks 1 --cpus-per-task 2 --wrap "echo "var1:" \$SLURM_CPUS_PER_TASK "var2:" \$SLURM_JOB_NAME"
Carles Fenoy
  • 4,740
  • 1
  • 26
  • 27