Job Scripts

This page documents the basics of how to write job scripts for the Fox HPC cluster.

Job Script Basics

To run a job on the cluster involves creating a shell script called a job script. The job script is a plain-text file containing any number of commands, including your main computational task, i.e., it may copy or rename files, cd into the proper directory, etc., all before doing the "real" work. The lines in the script file are the commands to be executed, in the given order. Lines starting with a # are ignored as comments, except lines that start with #SBATCH, which are not executed, but contain special instructions to the queue system.

If you are not familiar with shell scripts, they are simply a set of commands that you could have typed at the command line. You can find more information about shell scripts here: Introduction to Bash shell scripts.

A job script consists of a couple of parts, in this order:

Parameters to the queue system may be specified on the sbatch command line and/or in #SBATCH lines in the job script. There can be as many #SBATCH lines as you want, and you can combine several parameters on the same line. If a parameter is specified both on the command line and in the job script, the parameter specified on the command line takes precedence. The #SBATCH lines must precede any commands in the script.

Which parameters are allowed or required depends the job type, but two parameters must be present in any job:

The other required parameters are described in Fox Job Scripts. More common parameters are discussed in Job Parameters.

It is recommended to start the commands to set up the environment with

set -o errexit  # Exit the script on any error
set -o nounset  # Treat any unset variables as an error

module --quiet purge  # Reset the modules to the system default

and will most likely include one or more

module load SomeProgram/SomeVersion

to set up environment variables like $PATH to get access to the specified programs. It is recommended to specify the explicit version in the module load command. We also recommend adding a

module list    # For easier debugging

after the module load commands. (See Software on Fox for more information about software modules.)

All in all, a generic job script might look like this:

#!/bin/bash

# Job name:
#SBATCH --job-name=YourJobname
#
# Project:
#SBATCH --account=ecXXX
#
# Wall time limit:
#SBATCH --time=DD-HH:MM:SS
#
# Other parameters:
#SBATCH ...

## Set up job environment:
set -o errexit  # Exit the script on any error
set -o nounset  # Treat any unset variables as an error

module --quiet purge  # Reset the modules to the system default
module load SomeProgram/SomeVersion
module list

## Do some work:
YourCommands

Further Topics

Footnotes

[^1]: Technically, any script language that uses # as a comment character can be used, but the recommended, and the only one you can expect to get help with, is bash.


CC Attribution: This page is maintained by the University of Oslo IT FFU-BT group. It has either been modified from, or is a derivative of, "Job Scripts" by NRIS under CC-BY-4.0. Changes: Rephrasing of sections "Wall Time Limit" and "The Slurm script does not have to be written in Bash". Remove download links to code snippets.