Anna Syme

Click name ↑ to return to homepage

Slurm

Summary

Basic structure of a slurm script is:

#!/bin/bash 
#SBATCH e.g. job name
#SBATCH e.g. request 16 threads
#SBATCH e.g. request 4GB memory
dothing.py input.txt   #commands

Yes, those hashes are meant to be there! Slurm doesn’t mind.

Write slurm script with job info

nano slurm.txt

In the script, add this:

#!/bin/bash 
 
## name the job
## Note that in a bash script, lines starting with a hash (#) are usually ignored. 
## However, if they start with #SBATCH, slurm will read them. 
#SBATCH --job-name="canu-run1"
 
## set number of tasks - leave as 1
#SBATCH --ntasks=1 

## set number of cores/threads
## e.g. out of max 124 available
#SBATCH --cpus-per-task=24
 
## set number of gigabytes 
## this is the total requested, not number per cpu
## e.g. out of 1024 GB available
#SBATCH --mem=4 
 
## set wall time
## e.g. I need this to run in ten hours or not at all
## this is max time (waiting time + running time)
## job is cancelled after this time
## format is days-hours:minutes:seconds
#SBATCH --time=0-10:0:00 
 
## leave this bit in
if [ "x$SLURM_JOB_ID" == "x" ]; then 
  echo "You need to submit your job to the queuing system with sbatch" 
  exit 1 
fi 
 
## now for the actual commands
seqkit stats myassembly.fasta

# note: the tool seqkit should be installed
# note: the file myassembly.fasta should be available in the same directory that this slurm script was run. 

## if my tool is in a conda environment called bioinfo
## activate that env before the other commands:
source activate bioinfo # use "source" not "conda"
biotool.py R1.fastq # the other commands

## if I have a very long list of commands
# split the line of commands \
# with a backslash

Save and exit.

Run

Move slurm.txt into the directory where you want it to run.

Submit job:

sbatch slurm.txt

Check how it’s going

top #q to exit
htop #q to exit
jobs
squeue

Cancel it if you change your mind

See what job number (=job ID) it is:

squeue

Cancel that job ID 12132:

scancel 12132

See job outputs

When finished, this directory will contain: