Section outline

  • Typing every flag on the command line gets old. Slurm reads #SBATCH comment lines at the top of a script as if they were command-line flags — the script becomes self-contained and reproducible.

    #!/bin/bash
    #SBATCH --account=nn9970k
    #SBATCH --time=01:00
    #SBATCH --mem=1G
    #SBATCH --job-name=hello
    #SBATCH --output=output-%j.txt
    #SBATCH --error=error-%j.txt
    
    ./example-job.sh

    Then just sbatch myscript.sh — the flags inside the script take effect. Anything passed on the command line still wins over an in-script directive, so you can override for one-off runs.

    Useful directive shortcuts:

    • %j in --output / --error filenames is replaced with the job ID.
    • --job-name= sets the name shown in squeue.
    • --mail-type=END,FAIL + --mail-user=… emails you when the job finishes or fails.

    The quiz for this topic asks you to fill in a SBATCH script — pay attention to the unit format (Slurm accepts both 1G and 1024M for memory, both 01:00 and 1:00 for time).

    Read the canonical section →

    • Fill in the SBATCH directives. This is the load-bearing exercise for this topic.