squeue -u $USER --format="%.18i %.9P %.30j %.8T %.10M %.6D %R"

SLURM &
HPC Toolkit

Job submission, queue monitoring, failure debugging, array jobs, dependency chains, and resource profiling. CPU-only and GPU clusters.

17 commands
6 phases
SLURM 22+, CPU, GPU
Phase 17 commands shown
Tool / CommandPhaseKey usageUse case
sbatch submit
sbatch job.sh sbatch --job-name=train --nodes=1 --ntasks=1 --cpus-per-task=8 --mem=32G --time=04:00:00 --partition=compute job.sh sbatch --output=logs/%j.out --error=logs/%j.err job.sh sbatch --requeue --signal=B:USR1@60 job.sh sbatch --parsable job.sh # --parsable returns only the job ID: pipe to downstream steps
Always set --mem and --time explicitly: defaults vary by cluster and silent OOM kills waste queue time. %j in output paths expands to job ID. --parsable emits just the job ID for scripting. --signal=B:USR1@60 sends a warning signal 60s before time limit: implement a checkpoint handler.
batch script headers submit
#!/bin/bash #SBATCH --job-name=mymodel #SBATCH --nodes=1 #SBATCH --ntasks=1 #SBATCH --cpus-per-task=16 #SBATCH --mem=64G #SBATCH --time=08:00:00 #SBATCH --partition=compute #SBATCH --output=logs/%j-%x.out #SBATCH --mail-type=FAIL #SBATCH --mail-user=you@example.com %x = job name, %j = job ID, %N = node name
Canonical header block. %x expands to job name in output paths: more readable than bare job IDs in log directories. --mail-type=FAIL only; NONE or FAIL are the only values worth using in practice. --ntasks=1 --cpus-per-task=N is the correct pattern for multithreaded single-process jobs.
srun submit
srun --pty --nodes=1 --cpus-per-task=4 --mem=16G --time=01:00:00 --partition=compute bash srun --pty --time=02:00:00 --mem=32G bash srun --nodes=1 --ntasks=1 python train.py # inside an sbatch script, srun steps inherit #SBATCH directives: srun python train.py
Interactive allocation with --pty: the correct way to get a shell on a compute node for debugging without bypassing the scheduler. Inside an sbatch script, srun creates a job step visible in squeue and sacct, which improves accounting granularity.
scancel submit
scancel <jobid> scancel --user=$USER scancel --state=PENDING --user=$USER scancel --name=mymodel scancel <jobid>_[3-7] # send signal without killing (e.g. checkpoint trigger): scancel --signal=USR1 <jobid>
Cancel by job ID, user, state, name, or array range. --signal without cancellation is how you trigger checkpoint saves in jobs that implement a USR1 handler: cleaner than killing and resubmitting from scratch.
squeue monitor
squeue -u $USER squeue -u $USER --format="%.10i %.9P %.30j %.8T %.12M %.6D %.R" squeue --partition=compute --states=RUNNING squeue --job <jobid> -o "%T %r %N" watch -n 30 'squeue -u $USER' squeue -u $USER --sort=+i --noheader | wc -l
%R in the format string shows the reason a job is pending: the first thing to check when a job doesn't start. Common reasons: Resources (waiting for allocation), Priority, QOSMaxJobsPerUser, Dependency. watch -n 30 is less aggressive than -n 5 on shared head nodes.
sinfo monitor
sinfo sinfo -p compute -o "%N %C %m %G %T" sinfo --Node --long sinfo -t idle sinfo -t down,drain sinfo -o "%n %C" | awk -F'/' '{print $1, ($2-$1)" free"}'
Cluster state: partition availability, node states, CPU/memory/GPU capacity. %C gives allocated/idle/other/total CPUs per node. -t down,drain surfaces unhealthy nodes. The awk one-liner computes free CPUs per node from the A/I/O/T string.
sacct monitor
sacct -j <jobid> --format=JobID,State,ExitCode,Elapsed,MaxRSS,MaxVMSize sacct -u $USER --starttime=2025-01-01 --format=JobID,JobName,State,Elapsed,MaxRSS sacct -j <jobid> --format=JobID,TRESUsageInMax%80 sacct -j <jobid>.batch --format=MaxRSS,MaxVMSize,CPUTime sacct -u $USER --state=FAILED --starttime=now-7days
Post-mortem accounting: actual memory used (MaxRSS), CPU time, exit codes. .batch suffix on the job ID queries the batch step specifically. --state=FAILED with a time window surfaces all failures quickly. Essential for right-sizing --mem on repeat jobs.
scontrol debug
scontrol show job <jobid> scontrol show job <jobid> | grep -E "Reason|NodeList|StartTime|TimeLimit" scontrol show node <nodename> scontrol show partition compute scontrol hold <jobid> scontrol release <jobid> scontrol update JobId=<jobid> TimeLimit=06:00:00
Full job and node detail: more verbose than squeue. Reason field explains pending state. hold/release pauses a job without losing queue position. update TimeLimit extends a running job's walltime if the partition allows it: ask before the job hits the limit.
job log inspection debug
tail -f logs/<jobid>.out ls -lt logs/ | head -5 grep -i "error\|oom\|killed\|signal" logs/<jobid>.out grep "slurmstepd" /var/log/slurmctld.log | grep <jobid> # OOM kill signature in log: # slurmstepd: error: Exceeded job memory limit at some point # or: Killed (signal 9); check dmesg on the node
First-line triage for failed jobs. OOM kills appear as signal 9 with no Python traceback: the only clue is the slurmstepd message or sacct showing OUT_OF_MEMORY state. dmesg | grep -i oom on the compute node confirms kernel-level OOM kills.
node-level debug debug
srun --pty --jobid=<jobid> bash ssh <nodename> # once on node: top -u $USER ps aux --sort=-%mem | head -20 cat /proc/<pid>/status | grep VmRSS ls /sys/fs/cgroup/memory/slurm/uid_*/job_<jobid>/memory.usage_in_bytes cat /sys/fs/cgroup/memory/slurm/uid_*/job_<jobid>/memory.max_usage_in_bytes
Live memory inspection on the compute node. cgroup memory files give real peak RSS for the job without waiting for sacct. Most clusters allow SSH to your own job's node. Check with scontrol show job <jobid> | grep NodeList first.
job arrays arrays
sbatch --array=0-99 job.sh sbatch --array=0-999%20 job.sh sbatch --array=1,3,7,42 job.sh sbatch --array=0-99:5 job.sh # inside job.sh. Use SLURM_ARRAY_TASK_ID: INPUT_FILE="data/sample_${SLURM_ARRAY_TASK_ID}.parquet" python process.py --input $INPUT_FILE --task-id $SLURM_ARRAY_TASK_ID squeue -u $USER --array
%N after the range caps concurrent tasks: 0-999%20 runs at most 20 simultaneously, protecting shared storage from thundering-herd I/O. :5 step runs tasks 0,5,10,... useful for strided parameter sweeps. SLURM_ARRAY_TASK_ID indexes into config files, input lists, or hyperparameter grids.
array task lookup pattern arrays
# params.txt: one config per line # lr=0.001 batch=32 # lr=0.01 batch=64 # lr=0.1 batch=128 PARAMS=$(sed -n "$((SLURM_ARRAY_TASK_ID + 1))p" params.txt) python train.py $PARAMS --seed $SLURM_ARRAY_TASK_ID # count lines to set array bound: wc -l params.txt sbatch --array=0-$(( $(wc -l < params.txt) - 1 )) job.sh
Canonical hyperparameter sweep pattern: one param set per line, task ID as line index. Dynamically computing the array bound from file length avoids off-by-one errors when the grid changes. Pass --seed $SLURM_ARRAY_TASK_ID for reproducible but distinct runs.
dependency chains dependencies
JID1=$(sbatch --parsable preprocess.sh) JID2=$(sbatch --parsable --dependency=afterok:$JID1 train.sh) JID3=$(sbatch --parsable --dependency=afterok:$JID2 evaluate.sh) sbatch --dependency=afterok:$JID2 --dependency=afterany:$JID3 report.sh sbatch --dependency=aftercorr:<array_jobid> downstream.sh sbatch --dependency=singleton --job-name=mymodel job.sh
afterok requires exit code 0; afterany runs regardless of exit code; aftercorr matches array task IDs: task N of the downstream job starts after task N of the upstream array completes. singleton prevents concurrent runs of the same job name: useful for protecting shared output directories.
pipeline script pattern dependencies
#!/bin/bash set -euo pipefail PREP=$(sbatch --parsable prep.sh) echo "prep: $PREP" TRAIN=$(sbatch --parsable --dependency=afterok:$PREP train.sh) echo "train: $TRAIN" EVAL=$(sbatch --parsable --dependency=afterok:$TRAIN eval.sh) echo "eval: $EVAL" squeue --jobs=$PREP,$TRAIN,$EVAL -o "%.10i %.30j %.8T %R"
Submit an entire pipeline in one script, capture each job ID, print them, then show the full chain in squeue. set -euo pipefail aborts on any sbatch failure so downstream jobs are never submitted with a bad upstream ID. Commit pipeline scripts to version control alongside model code.
right-sizing memory resources
sacct -j <jobid>.batch --format=MaxRSS,ReqMem,Elapsed --noheader # MaxRSS in KB: convert to GB: sacct -j <jobid>.batch --format=MaxRSS --noheader | awk '{printf "%.1f GB\n", $1/1024/1024}' # efficiency ratio: aim for >0.7: sacct -j <jobid> --format=JobID,ReqMem,MaxRSS,CPUTimeRAW,ElapsedRaw --noheader seff <jobid>
seff (SLURM efficiency) summarises memory and CPU efficiency in one line: most clusters have it. Over-requesting memory blocks other jobs and may lower your job's priority under fair-share scheduling. Target 70 to 85% utilisation; below 50% is wasteful, above 90% risks OOM on variance.
environment & modules resources
module avail module avail python module load python/3.12 gcc/13.2 module list module purge # in job script. Always purge then reload explicitly: module purge module load python/3.12 openmpi/4.1 module show python/3.12
Environment Modules control PATH, LD_LIBRARY_PATH, and compiler toolchain. Always module purge at the top of job scripts: inherited shell modules from the login node cause silent mismatches between interactive and batch environments. module show reveals what a module actually sets.
CPU affinity & threading resources
sbatch --cpus-per-task=8 --hint=nomultithread job.sh # in job script: bind threads to allocated CPUs: export OMP_NUM_THREADS=$SLURM_CPUS_PER_TASK export MKL_NUM_THREADS=$SLURM_CPUS_PER_TASK export OPENBLAS_NUM_THREADS=$SLURM_CPUS_PER_TASK export NUMEXPR_NUM_THREADS=$SLURM_CPUS_PER_TASK taskset -cp $$ # verify actual CPU affinity of the process
Without explicit thread binding, NumPy/PyTorch/MKL spawns as many threads as there are cores on the node, not just your allocation. This causes severe interference on shared nodes. Set all four thread-count env vars; different libraries read different ones. taskset confirms the kernel-level CPU affinity mask.
I/O best practices resources
# copy input data to local scratch before computation: cp -r $INPUT_DIR $TMPDIR/input/ # work entirely from local scratch: python train.py --data $TMPDIR/input/ --output $TMPDIR/output/ # copy results back at end of job: cp -r $TMPDIR/output/ $RESULTS_DIR/ # check I/O load on shared filesystem: lfs df -h /scratch lfs quota -u $USER /scratch
Shared Lustre/GPFS filesystems degrade under random small-file I/O from many concurrent jobs. Copy to $TMPDIR (local NVMe on most clusters) for the compute phase; write back only final outputs. lfs quota checks your scratch quota before a large job fills it mid-run.
No commands match this filter.