4. srun & salloc

SRUN & SALLOC

Interactive jobs can be run with srun or salloc.

Note that both of these commands take slurm directives as command line arguments rather than #SBATCH directives in a file.

Differences Between SBATCH and SRUN

Compare the following srun command to the sbatch script found on the sbatch page

srun -N 1 -n 4 -t 0-00:30 -C centos7 \
 -p sched_engaging_default --mem-per-cpu=4000 \
-o output_%j.txt -e error_%j.txt \
--mail-type=BEGIN,END --mail-user=test@test.com \
echo "Hello, World"

Generally we recommend running in batch mode when possible as your job will run even if your terminal session dies, but there are a few use cases for srun.

Using srun to get a shell on a compute node:

srun -N 1 -n 1 --pty /bin/bash

Running a job with X11 forwarding enabled

If you need to run an interactive job with X11 forwarding to open interactive GUI windows, such as Firefox or MATLAB, you can request a node with a command similar to the one below. This command allocates one node and one core, similar to the above example, but with X forwarding.

srun -N 1 -n 1 --x11 --pty bash 

Once the allocation has been granted, the command to launch the GUI application can be ran. On some systems, you may be able to launch X commands, such as xeyes or xclock, without having to request a shell on a node. Please note that not all Engaging systems have these X applications.

More information on srun is available from SchedMD:

Using SALLOC

salloc is generally used in the same interactive manner as srun.

A job can be sumitted interactively, with the output being returned to your terminal:

salloc -N 1 -n 1 echo "Hello, World"

Using salloc to get a shell on a compute node:

salloc -N 1 -n 1

Notice how the pseudo-teletype flag “–pty” followed by a shell are not required. If no command is specified at the end, salloc will run the users default shell.

Differences between SALLOC and SRUN

salloc (like sbatch) allocate resources to run a job, while srun launches parallel tasks across those resources. srun can be used to launch parallel tasks across some or all of the allocated resources. srun can be ran inside of an sbatch script to run tasks in parallel, in which it will inherit the pertinent arguments or options. In the above examples, srun can also be used on its own to request resources and launch tasks, where tasks will be spread across those resources as a single job.

More information on salloc is available from SchedMD:

If you have any questions about using srun, please email orcd-help-engaging@mit.edu