How to use array jobs in SLURM: Difference between revisions

From RCSWiki
Jump to navigation Jump to search
Line 1: Line 1:
= General =
= Array jobs =


Job arrays in SLURM allow you to run many jobs using '''one and same''' job script.
Job arrays in SLURM allow you to run many jobs using '''one and same''' job script.
Line 5: Line 5:
Like this:
Like this:
  $ sbatch array_job.slurm
  $ sbatch array_job.slurm
This may be a convenient alternative to generating many separate job scripts for each data file and submitting them one by one.





Revision as of 18:29, 22 July 2022

Array jobs

Job arrays in SLURM allow you to run many jobs using one and same job script. The job script you submit with the sbatch command does not accept any parameters. Like this:

$ sbatch array_job.slurm

This may be a convenient alternative to generating many separate job scripts for each data file and submitting them one by one.


An array job script example, array_job.slurm:

#!/bin/bash
# ============================================
#SBATCH --job-name=my_array_job
#SBATCH --nodes=1
#SBATCH --ntasks=1
#SBATCH --cpus-per-task=1
#SBATCH --mem=4gb
#SBATCH --time=0-01:00:00

#SBATCH --array=1-10

# ============================================
./myapplication $SLURM_ARRAY_TASK_ID

This job script will create on auxiliary job in the queue which will generate 10 element jobs of the array from 1 to 10. The job scripts for each element job of the array will be exactly the same. The difference comes from the value of the environmental variable $SLURM_ARRAY_TASK_ID which is set to the number of this element job in the array (index).

That is the first job of the array will execute command line:

 ./myapplication 1

and the 8th element job will run

 ./myapplication 8

and so on.