12 Batch Jobs with sbatch

Overview

Teaching: 10 min
Exercises: 0 min
Questions
  • What are the advantages of sbatch over srun?

  • How do I run a sbatch job?

  • Where can I find example headers?

  • How do I format sbatch headers?

  • How do I capture the jobid?

Objectives
  • Know how to format a sbatch script.

  • Know how to run a sbatch job.

  • Know how to capture the jobid.

  • Understand the usefulness of slurm arrays.

sbatch basics

The Slurm sbatch header

#!/bin/bash

#SBATCH --job-name=MY_JOB    # Set job name
#SBATCH --partition=dev      # Set the partition 
#SBATCH --qos=dev            # Set the QoS
#SBATCH --nodes=1            # Do not change unless you know what your doing (it set the nodes (do not change for non-mpi jobs))
#SBATCH --ntasks=1           # Do not change unless you know what your doing (it sets the number of tasks (do not change for non-mpi jobs))
#SBATCH --cpus-per-task=4    # Set the number of CPUs for task (change to number of CPU/threads utilized) [-p dev -q dev limited to 30 CPUs per node]
#SBATCH --mem=24GB           # Set to a value ~10-20% greater than max amount of memory the job will use (or ~6 GB per core, for dev) (limited to 180 GB per node on dev partition)
#SBATCH --time=8:00:00       # Set the max time limit (dev partition/QoS has 8 hr limit)

###-----load modules if needed-------###
module load singularity

###-----run script below this line-------###



Example

Arrays are a useful extension to sbatch jobs

NEWVAR=$(sed -n -e "${SLURM_ARRAY_TASK_ID} p" /home/${USER}/my_important_list.txt)

Array examples

Key Points

  • sbatch allows you to schedule jobs that will execute as soon as the requested resources are available.

  • Example headers can be found at https://github.com/TheJacksonLaboratory/slurm-templates

  • Common slurm batch file extensions include .sh and .slurm

  • Save the job ID into a file with output redirect