Skip to main content
v2026.11,772 entries · CC-BY 4.0

Direct comparison

srun vs sbatch vs salloc: Slurm Commands

Compare srun, sbatch, and salloc: when to submit a batch job, run interactively, or allocate resources for interactive HPC work on Slurm.

Written and maintained by CASRAI Editorial Board

Last updated

Ask CASRAI · included with Regulatory Radar

Ask about srun vs sbatch vs salloc: Slurm Commands

Ask CASRAI answers research-administration questions and cites the passages behind every claim — and says so when the corpus does not cover something, instead of guessing. It comes with a Regulatory Radar subscription at $29 a month, alongside the daily digest of regulatory changes and the dashboard of what changed.

150 questions a day, on this site, over the API, or inside your own tools through the CASRAI MCP server.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays free to read, with no account and no card.

How do sbatch, srun, salloc compare side by side?

The table below compares sbatch, srun, salloc across 8 procurement-relevant dimensions, from what it does through common flags.

Side-by-side comparison

Dimensionsbatchsrunsalloc
What it doesSubmits a batch script to the Slurm scheduler for non-interactive execution later, when resources are available.Runs a command directly under Slurm — either as its own job (standalone) or as a parallel job step inside an existing allocation.Requests a resource allocation and starts an interactive shell (or runs a specified command) within it.
Execution modeNon-interactive, asynchronous.Interactive/blocking — waits for the command to finish and streams output to your terminal.Interactive — you get a live shell running inside the allocation.
Returns controlImmediately, with a job ID. Your terminal is free right away.Only after the launched command finishes.As soon as the allocation is granted, dropping you into a shell.
Typical use caseProduction runs: long simulations, pipelines, anything unattended.Launching parallel/MPI tasks inside a batch script, or a quick one-off interactive command.Interactive debugging and development directly on compute resources before writing a batch script.
Can it run inside an existing allocation?No — sbatch always requests a new job allocation; it cannot be nested inside salloc or another sbatch job.Yes — this is its dual role. Standalone it creates its own allocation; inside sbatch/salloc it runs as a job step using the parent allocation's resources.N/A — salloc creates the allocation that srun commands then run inside.
Output handlingStdout/stderr go to a file (slurm-<jobid>.out by default) unless --output/--error is set.Streams directly to the terminal (standalone) or to the batch script's own output stream (inside sbatch).Whatever you run inside the shell behaves normally — output goes to your terminal.
Ends when…The script finishes (or hits its time limit / is cancelled).The launched command completes.You exit the shell (or run scancel), releasing the allocation.
Common flags--job-name, --partition, --time, --nodes, --ntasks, --cpus-per-task, --mem, --output, --array--ntasks, --cpus-per-task, --nodes, --pty, --exact--nodes, --ntasks, --time, --partition

Common questions

Common questions about sbatch vs srun vs salloc

Can I run srun without sbatch or salloc first?

+

Yes. Run standalone, srun requests its own resource allocation from Slurm and then executes the command, blocking your terminal until it finishes. That's fine for a quick interactive test, but for a session with several commands, salloc is usually the better starting point because it keeps the allocation open.

What does srun actually do inside an sbatch script?

+

It launches a job step that runs within the allocation sbatch already obtained — it doesn't request new resources. By default a step launched this way can use all the non-GRES resources in that allocation unless you constrain it with flags like --exact, --ntasks, or --cpus-per-task.

Does salloc run my program for me?

+

No. salloc only creates the allocation and starts an interactive shell (or runs a specified command once, if you give it one). To actually launch work across the allocated nodes and tasks, you still call srun from inside that shell.

Which one should I use for interactive debugging on a cluster?

+

salloc, for a session where you'll run several commands, or srun --pty bash for a single one-off interactive shell. sbatch is the wrong tool for debugging — it's built for unattended runs where nobody is watching the output live.

Why does my sbatch job show up as one job in the queue no matter how many srun steps it runs?

+

Because sbatch creates a single job allocation, and every srun call inside its script runs as a step within that same job — steps share the job ID (shown as <jobid>.<stepid>), they do not create separate queued jobs.

Do the default resource limits differ between the three commands?

+

Slurm doesn't fix universal default values — time limits, memory per CPU, and partition access are set by each cluster's own configuration. Check your cluster's documentation, or run scontrol show partition, rather than assuming a default that applies everywhere.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →

Regulatory Radar

Stop finding out after the fact

$29/month, cancel anytime. Daily digest updates from our analysis, a dashboard holding the same items, and a cited assistant for everything they raise.

  • Federal Register, Federal Register+, Grants.gov, Regulations.gov, NSF News, UKRI, plus CASRAI’s own published content.
  • 72,264 indexed passages, and every answer cites the ones it drew on.