Skip to content

sbatch

The job scheduler consists of many programs to manage jobs. sbatch is the program to submit a job to the scheduler.

flowchart TD
  sbatch[sbatch: submit a job]
  scancel[scancel: cancel a running job]
  squeue[squeue: view the job queue]
  sbatch --> |Oops| scancel
  sbatch --> |Verify| squeue

After submitting a job, one can use squeue to verify the job is in the job queue. If there is an error in the sbatch command, one can cancel a job using scancel.

Minimal examples

There are two ways to demonstrate minimal use of sbatch:

These minimal examples use a run-time of a short, default time.

with command-line Slurm arguments

To let Slurm schedule a job, one uses sbatch.

For Bianca and Rackham, one uses sbatch like this:

sbatch -A [project_code] [script_filename]
sbatch -M snowy -A [project_code] [script_filename]

For Snowy, one uses sbatch like this:

sbatch -M snowy -A [project_code] [script_filename]

Where:

  • -A [project_code]: the project to use, for example sens2017625
  • [script_filename]: the name of a file that is a bash script, for example, my_script.sh
  • -M snowy: if you use the Snowy computational resources

Filling this all in, for Bianca and Rackham:

sbatch -A sens2017625 my_script.sh

Filling this all in, for Snowy:

sbatch -M snowy -A sens2017625 my_script.sh
What is my project?

See the UPPMAX documentation on projects.

How do I convert my project name to the project code I need to use here?

See the UPPMAX documentation on projects.

What is in the script file?

The script file my_script.sh is a minimal example script. Such a minimal example script could be:

#!/bin/bash
echo "Hello"

with Slurm parameters in the script

The minimal command to use sbatch with Slurm parameters in the script:

sbatch [script_filename]

where [script_filename] the name of a bash script, for example:

sbatch my_script.sh

For Bianca and Rackham, the script must contain at least the following lines:

#SBATCH -A [project_code]

For Snowy, the script must contain at least the following lines:

#SBATCH -A [project_code]
#SBATCH -M snowy

With:

  • [project_code]: the project code, for example uppmax2023-2-25
What is in the script file, for Bianca and Rackham?

A full example script would be:

#!/bin/bash
#SBATCH -A uppmax2023-2-25
echo "Hello"
What is in the script file, for Snowy?

A full example script would be:

#!/bin/bash
#SBATCH -A uppmax2023-2-25
#SBATCH -M snowy
echo "Hello"

More parameters

See the Slurm documentation on sbatch

Troubleshooting

See Slurm troubleshooting