1

I've written a sbatch script for array launching and I'd like to automatically add the number of jobs (without specifying it manually within the script).

I was thinking maybe as a variable, something like that:

sbatch myscript.sbs --n_jobs=30 (or sbatch --n_jobs=30 myscript.sbs)

... and this would be the ideal script (which, of course, it's not working):

#!/bin/bash

#SBATCH --job-name=test
#SBATCH --output=test.log
#SBATCH --mem=2G
#SBATCH --partition=short
#SBATCH --cpus-per-task=10

#SBATCH --array=1-${n_jobs}%5 # <<<--- adjust according number of files to process

<misc commands>
jgarces
  • 519
  • 5
  • 17
  • This seems like a duplicate. Does https://stackoverflow.com/questions/39186698/what-does-the-ntasks-or-n-tasks-does-in-slurm help at all? – tripleee Dec 22 '22 at 10:34

1 Answers1

1

Bash variables are not expanded in Bash comments so unfortunately the current version of Slurm does not allow what you are trying to do.

What would work, and is similar to your attempt sbatch --n_jobs=30 myscript.sbs would be

sbatch --array=1-30 myscript.sbs
damienfrancois
  • 52,978
  • 9
  • 96
  • 110