Interactive Execution with srun
Form
srun [options] -- <command...>
What srun Does
srun runs a command in the foreground by default.
Behavior depends on whether you are already inside an allocation:
- inside an allocation:
- creates a step record
- runs the command directly in the foreground
- outside an allocation:
- creates an allocation-like top-level record
- waits for it to run
- creates a step record
- runs the command in the foreground
Only --no-wait submits a daemon-managed run job.
When --ntasks is greater than 1, foreground srun launches one local
process per task rank on the same host and exports task-local ranks through
SLURM_PROCID and SLURM_LOCALID.
Main Options
| Option | Meaning |
|---|---|
-J, --job-name <name> | Set the job name |
-p, --partition <partition> | Choose a partition |
-c, --cpus-per-task <n> | CPUs per task |
-n, --ntasks <n> | Number of concurrently launched local tasks |
--mem <size> | Requested memory |
-t, --time <time> | Time limit |
-G, --gpus <n> | Requested GPU slots |
-o, --output <path> | Foreground stdout path |
-e, --error <path> | Foreground stderr path |
-D, --chdir <path> | Working directory |
--immediate | Fail if resources are not available immediately |
--pty | Reserved for PTY support; currently rejected |
--constraint <feature> | Require matching local features |
--cpu-bind <mode> | Bind CPU affinity |
--label | Prefix output with <task_id>: |
--unbuffered | Flush forwarded output eagerly |
--no-wait | Submit a daemon-managed run job |
Output Behavior
Example:
srun --label --unbuffered -- echo hello
Typical output:
0: hello
CPU Binding
Supported values:
nonecoresmap_cpu:<id,id,...>
Example:
srun --cpu-bind map_cpu:0,2 -- python train.py
Immediate Mode
--immediate fails instead of waiting if resources are not available right away.
Example:
srun --immediate -p gpu -G 1 -- nvidia-smi
--no-wait
--no-wait submits a run job to the daemon instead of waiting in the foreground.
Typical output:
Submitted run job 12
Restrictions:
--labeland--unbufferedare not supported together with--no-wait--ptyis parsed for compatibility but currently exits with a clear “not implemented yet” error until a real PTY path exists