
First Batch Job with Slurm
sbatch, squeue, sacct —
the submit-check-read-output loop
Resources
Section 3 — 25 min


Compute nodes are shared — the scheduler is how you ask for a slice
ssh into.
Shared by everyone. No heavy compute here.The loop we will practise: submit → check → read output. Repeat until you get what you want.
Shebang + #SBATCH directives + normal shell commands
#!/bin/bash
#SBATCH --job-name=hello_world
#SBATCH --output=hello_world.out
#SBATCH --ntasks=1
#SBATCH --cpus-per-task=1
#SBATCH --time=00:01:00
echo "Job ID: ${SLURM_JOB_ID}"
echo "Host: $(hostname)"
date
free -h
lscpu
env | sort > hello_world_${HOSTNAME}.env#SBATCH lines are comments to the shell,
directives to Slurm$PWD; put everything the job
needs inside the scriptThree commands you will use every day
watch -n 15 squeue --me polls every 15 seconds — do not
go lower. The scheduler is shared.
A shell on a compute node — fastest way to poke at something
Lands you on a compute node with a prompt. Run the same commands you would put in a batch script.
exit when you are done — do not idleThe point is not “never use interactive jobs” — it is use resources responsibly. Idle allocations block others. Batch is better when there is no human in the loop.
We have a reservation for today — add these flags to
sbatch and srun commands that should use the
reservation
Inspect the reservation and QOS before you use them:
On the command line:
Or inside your batch script (add these two
#SBATCH lines):
Gotchas:
sbatch: error: Batch job submission failed: Invalid qos specificationQOSMaxNodePerUserLimit (the
reservation caps per-user node count)~15 minutes — work in order, skip an exercise if it feels too easy
ex01_hello_world/ →
01-hello-world.md — first sbatch submissionex02_multi_task/ →
02-multi-task.md — ntasks + srun + sacctex03_interactive/ →
03-interactive.md — interactive shellex04_matmul/ →
04-matmul.md — compile + run (build first:
bash make.sh)Each .md has the commands to run, questions to think
about, and things to try if you finish early.
Out of scope for this section — defer to docs or later sections
Stay in scope
sbatch, squeue --me, scancel,
sacct--ntasks, --cpus-per-task,
--time, --outputsrun for fan-out, srun --pty bash for a
quick shellOut of scope
--mail-type=END and email notificationsWe cover debugging failed jobs properly in Section 6. If a job misbehaves, note it and bring it there.
Discussion
Did your first job run? Anything unexpected in the output? Anything you want to try next?