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: .
A job script consists of a couple of parts, in this order:
- The first line, which is always
#!/bin/bash
(see footnote [*]) - Parameters to the queue system
- Commands to set up the execution environment
- The actual commands you want to be run
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:
--account
, which specifies the project the job will run in. On Fox, this will beecN
, where N is a number.--time
, which specifies how long a job should be allowed to run. If it has not finished within that time, it will be cancelled. The most used formats for the time specification isDD-HH:MM:SS
andHH:MM:SS
, where DD is days, HH hours, MM minutes and SS seconds.
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
- How to specify the different job types on Fox
- Environment variables available in job scripts
- Job Files and Work Directories
- Array Jobs
- More Job Parameters
- Running scientific software
Footnotes
[*]: 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 探花精选 IT FFU-BT group. It has either been modified from, or is a derivative of, "" by NRIS under . 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.