Search code examples
bashparallel-processingjobsslurmsbatch

Values in a sbatch --array command different from the job task IDs, each of them run in a different job


Is it possible to feed a script some values in the sbatch --array command line different from the job task IDs, and each of them be run in a different job?

sbatch --array=1-2 script.sh 4 6

with script.sh being

#!/bin/bash

VALUE=$"$SLURM_ARRAY_TASK_ID"

echo $VALUE

then, after they have run,

cat slurm*

returns

1
2

But I wonder whether it is possible to make the 2 jobs return instead the "4 6" values fed in the sbatch --array command, one apiece:

4
6

Solution

  • You can use indirect variable expansion:

    #!/bin/bash
    
    VALUE=${!SLURM_ARRAY_TASK_ID}
    
    echo $VALUE
    

    Note the exclamation mark. After

    sbatch --array=1-2 script.sh 4 6
    

    you should have two output files, one with 4 and one with 6.