Skip to content

Instantly share code, notes, and snippets.

@lkluft
Last active September 21, 2021 13:40
Show Gist options
  • Save lkluft/ae8c4dedd4e1247f9c581338b5e25c6d to your computer and use it in GitHub Desktop.
Save lkluft/ae8c4dedd4e1247f9c581338b5e25c6d to your computer and use it in GitHub Desktop.
Minimal working example of SLURM Job Arrays
#!/bin/bash
# Normal job run (only one job and one task)
sbatch test.job
# Start 10 jobs at a time (create a log file each, but this can be tweaked).
# We will run 16 jobs (ID 1--16) but only four at a time. If you leave out the
# `%4` SLURM usually sets an upper limit per user (about 20 or so).
# More info: https://slurm.schedmd.com/job_array.html
job_id=$(sbatch --parsable --array=1-16%4 test.job)
# Start a "normal" job again, that will run after the last task in the array.
sbatch --dependency=afterok:$job_id test.job
squeue -u $USER # Check the SLURM queue
#! /bin/ksh
#SBATCH --account=highresmonsoon
#SBATCH --job-name=array-test
#SBATCH --partition=booster
#SBATCH --time=00:01:00
#SBATCH --gres=gpu:4
hostname
# The environment variable `SLURM_ARRAY_TASK_ID` is set to the current task id.
# It can be used to, for example, index a list or array.
echo $SLURM_ARRAY_TASK_ID
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment