Skip to content

Your first script

The most common type of jobs are batch script jobs submitted to the scheduler using sbatch command. In this example we are submitting a script called "my_script.sh":

sbatch my_script.sh
SLURM will try to find the suitable resources for the job as defined in the file and than launch the execution on the selected nodes.

Creating batch scripts

A batch script is typically organized to the following sections:

  • the interpreter to use for the execution of the script: bash, python, ...
  • SLURM directives that define the job options: resources, run time, partitions, ...
  • preparation steps: setting up the environment, load modules, prepare input files, ...
  • job execution: run the application(s) with appropiate command
  • epilogue: post processing and cleaning the data, ...

As an example, let's look at this simple batch job script:

demovic@login02 first_blood > cat my_script.sh 
#!/bin/bash         
#SBATCH -J "slurm test"       #JOB NAME
#SBATCH -N 1                  #NUMBER OF NODES
#SBATCH --ntasks-per-node=16  #NUMBER OF TASKS PER NODE
#SBATCH -o test.%J.out        #STDOUT FILE, %J will be replaced by JOB_ID
#SBATCH -e test.%J.err        #STDERR FILE

module load intel             #LOAD THE MPI ENVIRONMENT

mpirun /bin/hostname          #RUN YOUR APP IN PARALLEL

exit

This script defines only a minimal job requirements, such as number of nodes and tasks, standard output and error files and then runs hostname command (which displays the server name) in parallel.


demovic@login02 first_blood > sbatch my_script.sh 
Submitted batch job 38678

demovic@login02 first_blood > ls -ltr
total 8
-rw-rw-r-- 1 demovic demovic 198 Sep 21 14:08 my_script.sh
-rw-rw-r-- 1 demovic demovic   0 Sep 21 14:08 test.38678.err
-rw-rw-r-- 1 demovic demovic  80 Sep 21 14:08 test.38678.out

demovic@login02 first_blood > cat test.38678.out 
n079
n079
n079
n079
n079
n079
n079
n079
n079
n079
n079
n079
n079
n079
n079
n079
demovic@login02 first_blood > 

As you can see, the job's ID was 38678 (displayed right after job submission). As expected, this number was also used in STDERR and STDOUT file names. Since we requested 16 tasks on one node, the output file contains 16 outputs of hostname command (and you can see the script was actually executed on n079). Obviously, this is just a demonstration script and if you want to use it for a real HPC application, you have to modify it accordingly. You can find more examples for specific applications in the "Software" section of userdocs portal.

Common SLURM script options

You can start with the following options in your batch scripts. And of course, you can find many more options in the manual pages, try man sbatch.

Basic job options

Option Description
--account=NAME Charge resources used by this job to the specified user project.
--partition=NAME Request a specific partition for your jobs.
--time=HH:MM:SS Set a limit on the total run time of the job allocation.
--exclusive Disable node sharing with other jobs.
--mem-per-cpu=?GB Set the specific memory requirements per task.

Task distribution options

Option Description
--nodes Number of nodes to be allocated to the job
--ntasks Set the maximum number of tasks (MPI ranks)
--ntasks-per-node Set the number of tasks per node
Created by: Filip Holka