DEPRECATED

Check Julia 2 documentation instead!

Job Examples

SLURM supports two different kinds of jobs: Batch jobs and interactive jobs.

Batch jobs are the primary mode of operation. Here, a job script is submitted to the queue and will run without user interaction as soon as it is eligible in terms of available resources and job priority.

Interactive jobs are run with user interaction and require the user being present at the same time as the resources. Use this only if a batch job is insufficient.

The following examples each submit a job via SLURM and return the hostname of the compute node where the job was executed.

Batch Jobs

Single-Task Batch Jobs

Start by setting up a job file. This is usually a simple shell script. Let's assume we have an example script called myjob.sh which reads:

#!/bin/bash

#SBATCH -J MyFirstJob
#SBATCH -c 2
#SBATCH --mail-type=ALL
#SBATCH --mail-user=noreply@uni-wuerzburg.de

srun hostname

The lines 3 to 6 starting with #SBATCH set up your job environment.

  • -J: Your job name which helps you to identify your job instead of some number
  • -c: The number of CPUs that your job (task, to be precise, but we'll assume for now that they're the same thing) uses
  • You can tell SLURM to send you an email when the job starts and ends by using --mail-type=ALL and giving your email address by --mail-user=<address> (replace <address> with your own).

Warning

For technical reasons, only jobs with an even number of CPUs are allowed! So make sure to set -c to an even number unless you have a more advanced job involving mulitple tasks and/or parallelization.

Then use the srun command (line 8) to run your programs. srun hostname, for example, will run the hostname command on the executing cluster node.

Submit the job

Now you can submit your job script to SLURM. Use the sbatch command for this:

$ sbatch myjob.sh
Submitted batch job 23

SLURM will then report an job id, in this case 23. After your job is finished, SLURM will write the console output of your program to a file slurm-<ID>.out, where <ID> is your job id. This example job will therefore create a file named slurm-23.out. In that file you will find the output of the hostname command.

You can also give sbatch options on the command line instead of inside the job script file. To run the job on the test partition, you can submit it with the command

$ sbatch -p test myjob.sh

When an option is given on the command line and in the job script, the command line takes precendence.

Info

All #SBATCH lines in the job script must appear before the first executable command.

Multiple-Task Batch Jobs

Let's alter the abovementioned job script and add a line with the sbatch option -n:

#!/bin/bash

#SBATCH -J MyFirstJob
#SBATCH -n 4
#SBATCH --mail-type=ALL
#SBATCH --mail-user=noreply@uni-wuerzburg.de

srun hostname

This option sets the number of tasks, in this case to 4. When the option is omitted, it is set to 1 by default.

Tasks are multiple instances of the same binary running in parallel. The expected output of this job is therefore four lines containing the host name of the compute node.

It may seem odd at this point, but becomes useful when the individual instances of the binary communicate with each other, for example in MPI Jobs.

Interactive jobs

Interactive jobs are needed, if you

  • have to compile your software on specific hardware (e.g. GPU or Infiniband)
  • want to debug your software inside the SLURM environment

To get a shell running inside the SLURM environment, run srun directly:

$ srun --pty bash

srun supports the same options as sbatch, the additional --pty option here connects the input and output streams of the job's shell with your control shell.

SSH Connection to a Compute Node

Users can SSH to a compute node if and only if they have a running job on the node. In other cases, the access is denied. The SSH session is terminated when the job ends.

Info

The SSH session is subject to the same resource limits as the job.