Foundations to Frontier
Tests
C. Programming, Tools and HPC › C5 High-Performance Computing

Job Schedulers: Slurm and PBS

On a shared cluster you don't run programs directly: you describe the resources a job needs (nodes, tasks, CPUs, GPUs, memory, walltime) in a batch script and a scheduler such as Slurm or PBS decides when and where it runs. This topic covers batch scripts and their directives, partitions and QoS, interactive and array jobs, the resource model (nodes, tasks, cores, GPUs) and how it maps to MPI and threads, monitoring and accounting (squeue, sacct, core- and GPU-hours), job dependencies, and how schedulers decide what runs next: priorities, fair share, and backfilling, which relies on your walltime requests. In the exercises you parse #SBATCH directives and Slurm time formats, compute resources and core-hours, expand job arrays and translate a job to PBS; then you simulate a 64-node cluster to measure how EASY backfilling compares with first-come-first-served, and what padded walltime requests cost.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Booking time on a shared machine

A supercomputer is shared by hundreds of people, like a laboratory with expensive instruments. You can’t just walk in and start: you fill in a booking form (“I need 4 machines with 8 GPUs for 6 hours”) and a scheduler fits everyone’s bookings into the calendar as tightly as it can. Small, short bookings can slip into gaps between big ones, as long as they don’t delay anyone. Asking for far more time than you need makes that harder for everyone.

Scheduling jobs on an 8-node cluster
requested walltime =
n0n1n2n3n4n5n6n7024681012141618202224111122333333334456666778999999101111121212hours →
all jobs done at 16 h
utilization 77%
mean wait 6.3 h
Dashed outlines mark backfilled jobs. Job 3 needs all 8 nodes: under FCFS everything submitted after it waits, and nodes sit idle. Backfilling fills the gaps with small jobs that are guaranteed (by their requested walltime) not to delay job 3. Padding the requests makes those guarantees harder to give, so fewer jobs backfill: ask for realistic walltimes.
Why engineers care

Climate and CFD simulations, trajectory Monte Carlo campaigns and large model training run on schedulers at national labs, universities and space agencies. Writing correct batch scripts, sizing requests, using job arrays and reading accounting data decide how much science you get from an allocation.

📝 Quick check (Level 0)
0/3 answered
  1. 1. On a cluster, a scheduler…
  2. 2. Why ask for a realistic run time?
  3. 3. In the demo, under FCFS, what happens while the 8-node job waits?

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

A batch script

#!/bin/bash
#SBATCH --job-name=orbit-sweep
#SBATCH --nodes=2                    # machines
#SBATCH --ntasks-per-node=4          # MPI ranks per node
#SBATCH --cpus-per-task=8            # threads per rank (OMP_NUM_THREADS)
#SBATCH --gres=gpu:a100:4            # GPUs per node
#SBATCH --mem=256G                   # memory per node
#SBATCH --time=1-12:00:00            # walltime limit (D-HH:MM:SS); the job is killed when it runs out
#SBATCH --partition=gpu
#SBATCH --output=logs/%x_%j.out      # %x job name, %j job id
module load cuda/12.4
export OMP_NUM_THREADS=$SLURM_CPUS_PER_TASK
srun python simulate.py
sbatch job.sh              # submit; prints the job id
squeue -u $USER            # your queued and running jobs
scancel 123456             # cancel
sacct -j 123456 --format=JobID,Elapsed,MaxRSS,State,ExitCode    # accounting after the fact
salloc -N1 --gres=gpu:1 -t 1:00:00                               # interactive allocation

#SBATCH lines are read only up to the first command. PBS Pro and Torque use #PBS with qsub, qstat, qdel; resources are written as -l select=2:ncpus=32:mpiprocs=4:ngpus=4,walltime=36:00:00.

📝 Quick check (Level 1)
0/3 answered
  1. 1. Which command submits a batch script in Slurm?
  2. 2. What happens when a job exceeds its --time?
  3. 3. #SBATCH lines after the first command are…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 35 minUndergraduate students and practising engineers.

The resource model

  • Node: a machine. Task: a process (usually an MPI rank) started by srun. CPUs per task: cores for its threads. GRES: generic resources such as GPUs.
  • Total cores = tasks × cpus-per-task; for a hybrid MPI + OpenMP code, ranks × threads should match the cores you request, and srun binds them.
  • Memory: --mem per node or --mem-per-cpu; exceeding it gets the job killed by the cgroup (exit 137, C4.3).
  • Job arrays: --array=0-99%10 runs 100 independent tasks, at most 10 at a time; $SLURM_ARRAY_TASK_ID selects the parameter set. Ideal for parameter sweeps and Monte Carlo batches.
  • Dependencies: sbatch --dependency=afterok:123456 post.sh chains pre-processing, simulation and analysis.
  • Accounting: allocations are charged in core-hours or GPU-hours (requested resources × elapsed time), whether or not you use them.
🐍 Exercise 1: reading and translating batch scripts
Parse #SBATCH directives (long and short forms, inline comments, stopping at the first command); parse Slurm time formats and memory sizes; compute nodes, tasks, cores, GPUs, core-hours and GPU-hours; expand job-array specifications with steps and concurrency limits; fill output-file patterns; and translate the request into PBS Pro directives.
📝 Quick check (Level 2)
0/3 answered
  1. 1. 2 nodes × 4 tasks per node × 8 CPUs per task = how many cores?
  2. 2. --array=0-99%10 means…
  3. 3. Slurm time '1-12' is…

Level 3: Advanced

★★★★☆ Advanced⏱ 30 minGraduate level, with full derivations and proofs.

How the scheduler decides

Priority combines age (time waiting), fair share (groups that used less recently get more), job size, partition and QoS. Strict priority order alone (FCFS) wastes resources: when the highest-priority job needs many nodes, nodes sit idle until enough are free. Backfilling fixes this: EASY backfilling gives the first queued job a reservation (the earliest time enough nodes will be free, from running jobs’ requested end times) and lets later jobs start now if they fit and either finish before that reservation or use only nodes the reservation doesn’t need. Conservative backfilling gives every queued job a reservation.

Consequences for users: request realistic walltimes (padded requests block backfilling), split long work into checkpointed shorter jobs, use arrays instead of hundreds of separate submissions, and don’t request whole nodes for single-core jobs.

📝 Quick check (Level 3)
0/3 answered
  1. 1. EASY backfilling computes the head job's reservation from…
  2. 2. A 1-hour job that requests 48 hours…
  3. 3. Fair share raises priority for groups that…

Level 4: Expert

★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.

Scheduling, measured

Exercise 1. The sample script parses to 2 nodes × 4 ranks × 8 threads with 4 A100s per node and 256 GB per node for 1-12:00:00 = 36 h; an #SBATCH --time after module load is correctly ignored. Each array task costs 2304 core-hours and 288 GPU-hours. --array=0-15:4,20%2 expands to tasks 0, 4, 8, 12, 20 with at most 2 running, logs/%x_%A_%a.out becomes logs/orbit-sweep_770_12.out, and the PBS translation is select=2:ncpus=32:mpiprocs=4:ngpus=4:mem=256gb with walltime 36:00:00.

Exercise 2: FCFS versus EASY backfilling. An event-driven simulation of a 64-node cluster, 400 jobs per workload (power-of-two sizes from 1 to 64 nodes, lognormal runtimes around 1 hour, Poisson arrivals at an offered load of 0.9), averaged over 5 workloads:

Policy utilization mean wait mean bounded slowdown
FCFS 52% 52 h 82
EASY backfilling, exact requests 80% 5.2 h 7.6
EASY backfilling, requests 3× runtime 78% 5.4 h 8.2

Under FCFS, wide jobs at the head of the queue leave nodes idle, the queue grows faster than it drains and waits explode. Backfilling raises utilization from 52% to 80% and cuts waits 10×. Padding every request threefold makes reservations pessimistic and backfilling more conservative, costing a little utilization and wait; the scheduler literature finds this effect varies by workload (sometimes padding even helps), but realistic requests are never worse for the job itself.

🐍 Exercise 2 (research): FCFS versus EASY backfilling
Generate synthetic workloads (job sizes, lognormal runtimes, Poisson arrivals at a target load, optional padding of requested walltimes); simulate a cluster with FCFS and with EASY backfilling (reservation for the head job from requested end times); measure utilization, mean wait and bounded slowdown, averaged over several workloads, with exact and padded requests.

Schedulers in AI, robotics and aerospace

  • Parameter sweeps and Monte Carlo (launch dispersions, sensitivity studies) as job arrays.
  • Large-model training as multi-node GPU jobs with checkpointing to survive walltime limits and node failures (C6).
  • Pipelines of pre-processing, simulation and post-processing chained with dependencies (or workflow tools such as Snakemake and Nextflow on top of Slurm).
  • Cloud HPC: the same Slurm scripts run on cloud clusters (AWS ParallelCluster, Google Cloud HPC Toolkit) with autoscaling node pools.

References

  1. A. B. Yoo, M. A. Jette, M. Grondona (2003). “SLURM: Simple Linux Utility for Resource Management.” JSSPP Workshop, LNCS 2862.
  2. D. A. Lifka (1995). “The ANL/IBM SP scheduling system.” JSSPP Workshop, LNCS 949 (origin of EASY backfilling).
  3. A. W. Mu’alem, D. G. Feitelson (2001). “Utilization, predictability, workloads, and user runtime estimates in scheduling the IBM SP2 with backfilling.” IEEE TPDS, 12(6).
  4. D. G. Feitelson (2015). Workload Modeling for Computer Systems Performance Evaluation. Cambridge University Press.
  5. SchedMD. Slurm documentation (slurm.schedmd.com): sbatch, srun, job arrays, sacct; Altair PBS Professional User’s Guide.