Array jobs

An array job lets you submit the same job dozens or even hundreds of times with different inputs. This is a lot quicker than manually submitting the job multiple times.

In this example the openMP job mycode.exe will be submitted 10 times. Each task still requests 64 processor cores, but 10 instances will be run. The sbatch option for creating an array job is --array:

#SBATCH --array=1-10

Each instance of the job gets a job ID as usual, but also an array task ID. This is available within the environment variable SLURM_ARRAY_TASK_ID, and can be used within the script or program code to derive input values for the jobs.

A sample submission script based on the above is given below.

#!/bin/bash --login

#SBATCH -J your_job_name
#SBATCH -o output_file_name%j
#SBATCH -e error_file_name%j
#SBATCH -p partition_name
#SBATCH -A account_name
#SBATCH --nodes=1
#SBATCH --ntasks-per-node=1
#SBATCH --cpus-per-task=64
#SBATCH -t 00:30:00

# 16 jobs will run in this array at the same time
#SBATCH --array=1-10

module purge
module load gcc/10.3.0

# each job will see a different ${SLURM_ARRAY_TASK_ID}
echo "now processing task id:: " ${SLURM_ARRAY_TASK_ID}

export OMP_NUM_THREADS=${SLURM_CPUS_PER_TASK}

# Execute your serial job code
/path_to_my_code.exe > output_${SLURM_ARRAY_TASK_ID}