Slurm User Guide

Slurm Job Arrays

What are Slurm Job Arrays?

Slurm job arrays are a mechanism for submitting and managing collections of similar jobs quickly and easily. Instead of submitting hundreds or thousands of individual jobs, you can use a job array to submit a single job script that will spawn multiple job tasks.

How to Use Job Arrays

To create a job array, you use the --array option in your Slurm batch script:

#SBATCH --array=1-100

This will create 100 job array tasks, numbered from 1 to 100.

More Complex Array Specifications:

Using the Array Task ID

Within your job script, you can use the $SLURM_ARRAY_TASK_ID environment variable to distinguish between tasks:

#!/bin/bash
#SBATCH --array=1-100

echo "Processing file_${SLURM_ARRAY_TASK_ID}.txt"
./my_program input_${SLURM_ARRAY_TASK_ID}.dat output_${SLURM_ARRAY_TASK_ID}.result

Why Use Job Arrays?

  1. Efficiency in Job Submission: Submit many similar jobs with a single script.
  2. Easier Management: Manage a group of related jobs as a single unit.
  3. Improved Scheduling: Slurm can schedule array tasks more efficiently than individual jobs.
  4. Reduced System Overhead: Less load on the scheduling system compared to submitting many individual jobs.
  5. Simplified Dependency Management: You can make other jobs depend on the entire array or specific tasks.

Best Practices and Tips

Example: Processing Multiple Datasets

#!/bin/bash
#SBATCH --job-name=data_process
#SBATCH --output=output_%A_%a.log
#SBATCH --error=error_%A_%a.log
#SBATCH --array=1-100
#SBATCH --time=01:00:00
#SBATCH --mem=4G

# List of datasets
datasets=(dataset1.csv dataset2.csv dataset3.csv ... dataset100.csv)

# Get the dataset for this task
dataset=${datasets[$SLURM_ARRAY_TASK_ID - 1]}

# Run the processing script
python process_data.py $dataset

Managing Job Arrays

When to Use Job Arrays

Job arrays are ideal for:

By using job arrays effectively, you can significantly streamline your workflow, especially when dealing with large numbers of similar computational tasks.