Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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

OptionMeaning
-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
--immediateFail if resources are not available immediately
--ptyReserved for PTY support; currently rejected
--constraint <feature>Require matching local features
--cpu-bind <mode>Bind CPU affinity
--labelPrefix output with <task_id>:
--unbufferedFlush forwarded output eagerly
--no-waitSubmit a daemon-managed run job

Output Behavior

Example:

srun --label --unbuffered -- echo hello

Typical output:

0: hello

CPU Binding

Supported values:

  • none
  • cores
  • map_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:

  • --label and --unbuffered are not supported together with --no-wait
  • --pty is parsed for compatibility but currently exits with a clear “not implemented yet” error until a real PTY path exists