Batch Jobs

The primary way of using SLURM is by submitting batch jobs. Batch jobs allow users to specify what they need to run without care for which hosts are available or when.

Run-Scripts

In order to submit a job to slurm, you must first create a run-script. A run-script is just a regular interpreted-language script such as bash optionally with some SLURM directives. Here’s an example:

#!/bin/bash
# Lines starting with #SBATCH are SLURM directives.
# we use these to give constraints to what our allocation will be
#SBATCH --job-name=example_runscript
#SBATCH --nodes=1 # use a single node
#SBATCH --ntasks=4 # use a total of 4 tasks. 
# If using multiple nodes, this number will be spread between nodes.
#SBATCH --time=01:00:00 # maximum time alloted to job, format D-HR:MM:SS
#SBATCH --output=example_runscript.out # file where program output is stored
#SBATCH --account=<your_account> # account to charge to

# afterward, this is a regular bash script

commands ...

Submitting Jobs

Once you’re written your script, submit the job with the sbatch command

Terminal
sbatch example-runscript.sh

You can also pass directives directly without putting them in your script

Terminal
sbatch --nodes 2 --cpus-per-task 16 example-runscript.sh

Best Practices

  • Always specify resources

  • Use meaningful job names

  • Load LMOD modules explicitly

  • Request only what you need

  • Test with small jobs first