Batch System Slurm¶
ZIH uses the batch system Slurm for resource management and job scheduling. Compute nodes are not accessed directly, but addressed through Slurm. You specify the needed resources (cores, memory, GPU, time, ...) and Slurm will schedule your job for execution.
When logging in to ZIH systems, you are placed on a login node. There, you can manage your data life cycle, setup experiments, and edit and prepare jobs. The login nodes are not suited for computational work! From the login nodes, you can interact with the batch system, e.g., submit and monitor your jobs.
The batch system is the central organ of every HPC system users interact with its compute resources. The batch system finds an adequate compute system (partition) for your compute jobs. It organizes the queueing and messaging, if all resources are in use. If resources are available for your job, the batch system allocates and connects to these resources, transfers runtime environment, and starts the job.
A workflow could look like this:
sequenceDiagram user ->>+ login node: run programm login node ->> login node: kill after 5 min login node ->>- user: Killed! user ->> login node: salloc [...] login node ->> Slurm: Request resources Slurm ->> user: resources user ->>+ allocated resources: srun [options] [command] allocated resources ->> allocated resources: run command (on allocated nodes) allocated resources ->>- user: program finished user ->>+ allocated resources: srun [options] [further_command] allocated resources ->> allocated resources: run further command allocated resources ->>- user: program finished user ->>+ allocated resources: srun [options] [further_command] allocated resources ->> allocated resources: run further command Slurm ->> allocated resources: Job limit reached/exceeded allocated resources ->>- user: Job limit reached
At HPC systems, computational work and resource requirements are encapsulated into so-called jobs. In order to allow the batch system an efficient job placement it needs these specifications:
- requirements: number of nodes and cores, memory per core, additional resources (GPU)
- maximum run-time
- HPC project for accounting
- who gets an email on which occasion
Moreover, the runtime environment as well as the executable and certain command-line arguments have to be specified to run the computational work.
This page provides a brief overview on
- Slurm options to specify resource requirements,
- how to submit interactive and batch jobs,
- how to write job files,
- how to manage and control your jobs.
If you are are already familiar with Slurm, you might be more interested in our collection of job examples. There is also a ton of external resources regarding Slurm. We recommend these links for detailed information:
- slurm.schedmd.com provides the official documentation comprising manual pages, tutorials, examples, etc.
- Comparison with other batch systems
There are three basic Slurm commands for job submission and execution:
srun: Run a parallel application (and, if necessary, allocate resources first).
sbatch: Submit a batch script to Slurm for later execution.
salloc: Obtain a Slurm job allocation (i.e., resources like CPUs, nodes and GPUs) for interactive use. Release the allocation when finished.
Executing a program with
srun directly on the shell will be blocking and launch an
interactive job. Apart from short test runs, it is recommended to submit your
jobs to Slurm for later execution by using batch jobs. For that, you can conveniently
put the parameters in a job file, which you can submit using
[options] <job file>.
After submission, your job gets a unique job ID, which is stored in the environment variable
SLURM_JOB_ID at job runtime. The command
sbatch outputs the job ID to stderr. Furthermore, you
can find it via
squeue --me. The job ID allows you to
manage and control your jobs.
srun vs. mpirun
On ZIH systems,
srun is used to run your parallel application. The use of
mpirun is provenly
broken on partitions
alpha for jobs requiring more than one node. Especially when
using code from github projects, double-check its configuration by looking for a line like
'submit command mpirun -n $ranks ./app' and replace it with 'srun ./app'.
Otherwise, this may lead to wrong resource distribution and thus job failure, or tremendous slowdowns of your application.
The following table contains the most important options for
salloc to specify
resource requirements and control communication.
Options Table (see
||Total number of (MPI) tasks (default: 1)|
||Number of compute nodes|
||Number of tasks per allocated node to start (default: 1)|
||Number of CPUs per task; needed for multithreaded (e.g. OpenMP) jobs; typically
||Type of nodes where you want to execute your job (refer to partitions)|
||Memory need per allocated CPU in MB|
||Maximum runtime of the job|
||Get updates about the status of the jobs|
||For what type of events you want to get a mail; valid options:
||Name of the job shown in the queue and in mails (cut after 24 chars)|
||Disable requeueing of the job in case of node failure (default: enabled)|
||Exclusive usage of compute nodes; you will be charged for all CPUs/cores on the node|
||Charge resources used by this job to the specified project|
||File to save all normal output (stdout) (default:
||File to save all error output (stderr) (default:
||Submit an array job (examples)|
||Restrict job to run on specific nodes only|
||Exclude specific nodes from job|
||Retrieve estimated start time of a job considering the job queue; does not actually submit the job nor run the application|
Output and Error Files
When redirecting stderr and stderr into a file using
--stderr=<filename>, make sure the target path is writeable on the
compute nodes, i.e., it may not point to a read-only mounted
No free lunch
Runtime and memory limits are enforced. Please refer to the section on partitions and limits for a detailed overview.
If you want to place your job onto specific nodes, there are two options for doing this. Either use
-p, --partition=<name> to specify a host group aka. partition that fits
your needs. Or, use
-w, --nodelist=<host1,host2,..> with a list of hosts that will work for you.
Interactive activities like editing, compiling, preparing experiments etc. are normally limited to
the login nodes. For longer interactive sessions, you can allocate cores on the compute node with
salloc. It takes the same options as
sbatch to specify the required resources.
salloc returns a new shell on the node where you submitted the job. You need to use the command
srun in front of the following commands to have these commands executed on the allocated
resources. If you allocate more than one task, please be aware that
srun will run the command on
each allocated task by default! To release the allocated resources, invoke the command
marie@login$ salloc --nodes=2 salloc: Pending job allocation 27410653 salloc: job 27410653 queued and waiting for resources salloc: job 27410653 has been allocated resources salloc: Granted job allocation 27410653 salloc: Waiting for resource configuration salloc: Nodes taurusi[6603-6604] are ready for job marie@login$ hostname tauruslogin5.taurus.hrsk.tu-dresden.de marie@login$ srun hostname taurusi6604.taurus.hrsk.tu-dresden.de taurusi6603.taurus.hrsk.tu-dresden.de marie@login$ exit # ending the resource allocation
srun also creates an allocation, if it is running outside any
marie@login$ srun --pty --ntasks=1 --cpus-per-task=4 --time=1:00:00 --mem-per-cpu=1700 bash -l srun: job 13598400 queued and waiting for resources srun: job 13598400 has been allocated resources marie@compute$ # Now, you can start interactive work with e.g. 4 cores
Since Slurm 20.11
--exclusive is the default for
srun as a step, that means you have to
--overlap, if you want to run
srun within a
marie@login$ srun --pty bash -l srun: job 27410688 queued and waiting for resources srun: job 27410688 has been allocated resources marie@compute$ srun --overlap hostname taurusi6604.taurus.hrsk.tu-dresden.de
module commands in interactive mode
The module commands are made available by sourcing the files
~/.bashrc. This is done automatically by passing the parameter
-l to your
shell, as shown in the example above. If you missed adding
-l at submitting the interactive
session, no worry, you can source this files also later on manually (
A dedicated partition
interactive is reserved for short jobs (< 8h) with no more than one job
per user. An interactive partition is available for every regular partition, e.g.
alpha. Please check the availability of nodes there with
sinfo |grep 'interactive\|AVAIL' |less
Interactive X11/GUI Jobs¶
Slurm will forward your X11 credentials to the first (or even all) node for a job with the
marie@login$ srun --ntasks=1 --pty --x11=first xeyes
If you are getting the error:
srun: error: x11: unable to connect node taurusiXXXX
that probably means you still have an old host key for the target node in your
~.ssh/known_hosts file (e.g. from pre-SCS5). This can be solved either by removing the entry
known_hosts or by simply deleting the
known_hosts file altogether if you don't have
important other entries in it.
Working interactively using
salloc is a good starting point for testing and compiling.
But, as soon as you leave the testing stage, we highly recommend to use batch jobs.
Batch jobs are encapsulated within job files and submitted to the batch system using
sbatch for later execution. A job file is basically a script holding the resource requirements,
environment settings and the commands for executing the application. Using batch jobs and job files
has multiple advantages*:
- You can reproduce your experiments and work, because all steps are saved in a file.
- You can easily share your settings and experimental setup with colleagues.
*) If job files are version controlled or environment
env is saved along with Slurm output.
Syntax: Submitting a batch job
marie@login$ sbatch [options] <job_file>
Job files have to be written with the following structure.
#!/bin/bash # ^Batch script starts with shebang line #SBATCH --ntasks=24 # #SBATCH lines request resources and #SBATCH --time=01:00:00 # specify Slurm options #SBATCH --account=<KTR> # #SBATCH --job-name=fancyExp # All #SBATCH lines have to follow uninterrupted #SBATCH --output=simulation-%j.out # after the shebang line #SBATCH --error=simulation-%j.err # Comments start with # and do not count as interruptions module purge # Set up environment, e.g., clean/switch modules environment module load <module1 module2> # and load necessary modules srun ./application [options] # Execute parallel application with srun
The following two examples show the basic resource specifications for a pure OpenMP application and a pure MPI application, respectively. Within the section Job Examples, we provide a comprehensive collection of job examples.
Job file OpenMP
#!/bin/bash #SBATCH --nodes=1 #SBATCH --tasks-per-node=1 #SBATCH --cpus-per-task=64 #SBATCH --time=01:00:00 #SBATCH --account=<account> module purge module load <modules> export OMP_NUM_THREADS=$SLURM_CPUS_PER_TASK srun ./path/to/openmp_application
marie@login$ sbatch batch_script.sh
- Run with fewer CPUs:
marie@login$ sbatch --cpus-per-task=14 batch_script.sh
Job file MPI
#!/bin/bash #SBATCH --ntasks=64 #SBATCH --time=01:00:00 #SBATCH --account=<account> module purge module load <modules> srun ./path/to/mpi_application
marie@login$ sbatch batch_script.sh
- Run with fewer MPI tasks:
marie@login$ sbatch --ntasks=14 batch_script.sh
A heterogeneous job consists of several job components, all of which can have individual job options. In particular, different components can use resources from different Slurm partitions. One example for this setting is an MPI application consisting of a master process with a huge memory footprint and worker processes requiring GPU support.
srun commands can all be used to submit heterogeneous jobs. Resource
specifications for each component of the heterogeneous job should be separated with ":" character.
Running a job step on a specific component is supported by the option
marie@login$ salloc --ntasks=1 --cpus-per-task=4 --partition <partition> --mem=200G : \ --ntasks=8 --cpus-per-task=1 --gres=gpu:8 --mem=80G --partition <partition> [...] marie@login$ srun ./my_application <args for master tasks> : ./my_application <args for worker tasks>
Heterogeneous jobs can also be defined in job files. There, it is required to separate multiple
components by a line containing the directive
#!/bin/bash #SBATCH --ntasks=1 #SBATCH --cpus-per-task=4 #SBATCH --partition=<partition> #SBATCH --mem=200G #SBATCH hetjob # required to separate groups #SBATCH --ntasks=8 #SBATCH --cpus-per-task=1 #SBATCH --gres=gpu:8 #SBATCH --mem=80G #SBATCH --partition=<partition> srun ./my_application <args for master tasks> : ./my_application <args for worker tasks> # or as an alternative srun ./my_application <args for master tasks> & srun --het-group=1 ./my_application <args for worker tasks> & wait
Due to the way scheduling algorithm works it is required that each component has to be allocated on a different node. Furthermore, job arrays of heterogeneous jobs are not supported.
Manage and Control Jobs¶
Job and Slurm Monitoring¶
On the command line, use
squeue to watch the scheduling queue.
Show your jobs
squeue --me to list only your jobs.
In its last column, the
squeue command will also tell why a job is not running.
Possible reasons and their detailed descriptions are listed in the following table.
More information about job parameters can be obtained with
scontrol -d show
||This job is waiting for a dependent job to complete.|
||No reason is set for this job.|
||The partition required by this job is in a down state.|
||The number of nodes required by this job is outside of its partitions current limits. Can also indicate that required nodes are down or drained.|
||The jobs time limit exceeds its partitions current time limit.|
||One or higher priority jobs exist for this partition.|
||The job is waiting for resources to become available.|
||A node required by the job is down.|
||The jobs constraints can not be satisfied.|
||Failure of the Slurm system, a filesystem, the network, etc.|
||The job could not be launched. This may be due to a filesystem problem, invalid program name, etc.|
||The job terminated with a non-zero exit code.|
||The job exhausted its time limit.|
||The job reached the system inactive limit.|
For detailed information on why your submitted job has not started yet, you can use the command
marie@login$ whypending <jobid>
Jobs that have not yet started can be altered. By using
scontrol update timelimit=4:00:00
jobid=<jobid>, it is for example possible to modify the maximum runtime.
many different options, please take a look at the
scontrol documentation for more details.
scancel <jobid> kills a single job and removes it from the queue. By using
<username>, you can send a canceling signal to all of your jobs at once.
The Slurm command
sacct provides job statistics like memory usage, CPU time, energy usage etc.
as table-formatted output on the command line.
The job monitor PIKA provides web-based graphical performance statistics at no extra cost.
Learn from old jobs
We highly encourage you to inspect your previous jobs in order to better estimate the requirements, e.g., runtime, for future jobs. With PIKA, it is e.g. easy to check whether a job is hanging, idling, or making good use of the resources.
Using sacct (see also
sacct outputs the following fields by default.
# show all own jobs contained in the accounting database marie@login$ sacct JobID JobName Partition Account AllocCPUS State ExitCode ------------ ---------- ---------- ---------- ---------- ---------- -------- [...]
We'd like to point your attention to the following options to gain insight in your jobs.
Show specific job
marie@login$ sacct --jobs=<JOBID>
Show all fields for a specific job
marie@login$ sacct --jobs=<JOBID> --format=All
Show specific fields
marie@login$ sacct --jobs=<JOBID> --format=JobName,MaxRSS,MaxVMSize,CPUTime,ConsumedEnergy
The manual page (
man sacct) and the sacct online reference
provide a comprehensive documentation regarding available fields and formats.
sacct only shows data of the last day. If you want to look further into the past
without specifying an explicit job id, you need to provide a start date via the option
--starttime (or short:
-S). A certain end date is also possible via
Show all jobs since the beginning of year 2021
marie@login$ sacct --starttime 2021-01-01 [--endtime now]
Jobs at Reservations¶
Within a reservation, you have privileged access to HPC resources. How to ask for a reservation is described in the section reservations. After we agreed with your requirements, we will send you an e-mail with your reservation name. Then, you could see more information about your reservation with the following command:
marie@login$ scontrol show res=<reservation name> # e.g. scontrol show res=hpcsupport_123
If you want to use your reservation, you have to add the parameter
--reservation=<reservation name> either in your job script or to your
Node Features for Selective Job Submission¶
The nodes in our HPC system are becoming more diverse in multiple aspects, e.g, hardware, mounted storage, software. The system administrators can describe the set of properties and it is up to you as user to specify the requirements. These features should be thought of as changing over time (e.g., a filesystem get stuck on a certain node).
A feature can be used with the Slurm option
-C, --constraint=<ARG> like
srun --constraint="fs_lustre_scratch2" [...] with
Multiple features can also be combined using AND, OR, matching OR, resource count etc.
--constraint="fs_beegfs|fs_lustre_ssd" requests for nodes with at least one of the
fs_lustre_ssd. For a detailed description of the possible
constraints, please refer to the Slurm documentation.
A feature is checked only for scheduling. Running jobs are not affected by changing features.
fs_* is active if a certain filesystem is mounted and available on a node. Access to
these filesystems are tested every few minutes on each node and the Slurm features are set accordingly.
For certain projects, specific filesystems are provided. For those,
additional features are available, like