What Slurm scripts are for

Slurm scripts are used to submit and manage jobs in a high-performance computing environment. The mirrored page described Slurm as a widely used open-source workload manager for resource allocation and job scheduling.

Example script for ASL-cpu

#!/bin/bash
#SBATCH --job-name=cpu_test
#SBATCH --output=%x_%j.out
#SBATCH --error=%x_%j.err
#SBATCH --partition=ASL-cpu
#SBATCH --nodes=1
#SBATCH --ntasks=1
#SBATCH --cpus-per-task=1
#SBATCH --mem=1G
#SBATCH --time=00:10:00

sleep 60
echo "Hello World"
echo "Hello Error" 1>&2

Example script for ASL-gpu

#!/bin/bash
#SBATCH --job-name=gpu_test
#SBATCH --output=%x_%j.out
#SBATCH --error=%x_%j.err
#SBATCH --partition=ASL-gpu
#SBATCH --nodes=1
#SBATCH --ntasks=1
#SBATCH --cpus-per-task=4
#SBATCH --gres=gpu:1
#SBATCH --time=00:30:00

python my_gpu_script.py

Explanation of key directives

  • #SBATCH: specifies options for job submission.
  • --job-name: assigns a custom job name.
  • --output and --error: set output and error logs.
  • --partition: chooses the queue such as ASL-cpu or ASL-gpu.
  • --nodes, --ntasks, --cpus-per-task, --gres, --time, and --mem define resources.

Submitting a Slurm script

sbatch my_job.slurm

Job array example

#!/bin/bash
#SBATCH --job-name=array_job
#SBATCH --time=2:00:00
#SBATCH --array=1-10
#SBATCH --ntasks=1
#SBATCH --partition=ASL-cpu

python my_script.py $SLURM_ARRAY_TASK_ID

The original explanation noted that this runs multiple jobs with different SLURM_ARRAY_TASK_ID values.