Skip to content

Instantly share code, notes, and snippets.

@MillironX
Created March 9, 2022 19:45
Show Gist options
  • Select an option

  • Save MillironX/d817e01eee693d831a2dd25fbd3be0ce to your computer and use it in GitHub Desktop.

Select an option

Save MillironX/d817e01eee693d831a2dd25fbd3be0ce to your computer and use it in GitHub Desktop.
KSUMNGS Slurm Basics

SLURM Basics

Before you start, outline the following three things for your computational task:

  1. How many threads (CPUs) you need
    • Will often be passed to a --threads option or similar
    • Using more than 32 in most cases will lead to slower execution times
    • We'll call this quanity $CPUS
  2. How much memory (RAM) you need
    • Try to convert this into megabytes (MB)
    • 32000 is a good starting place if you don't have a better estimate
    • We'll call this quantity $MEM
  3. How much time it will take
    • Reformat this amount into the form d-hh:mm:ss
    • Can't be longer than 2 weeks
    • We'll call this quantity $TIME

Interactive running

On the server, run

screen

to ensure a network glitch or power off doesn't interupt your work.

With the above in mind, run

salloc --cpus-per-task $CPUS --mem $MEM --time $TIME

Congrats! If there are no error messages, then you are now in a SLURM shell. You can do anything here just like a regular shell, but you will be kicked out if you use more resources than you specified above. This allows you to run interative commands without interupting other people's intensive tasks.

If things are running for a long time, to leave, press CTRL+A and D. To go back later run

screen -r

Batch running

If you have a script file to do your task for you, then you should use batch mode. Edit the script file and add the following to the top of it.

#!/bin/bash
#SBATCH --cpus-per-task=$CPUS
#SBATCH --mem=$MEM
#SBATCH --time=$TIME

Now go to the command line and run

sbatch /path/to/script/file.sh

Somewhere in-between

For interactivity while running script files, use srun with the same flags as salloc with a script like sbatch. Yeah, this one has its uses, but isn't really useful for most of our uses.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment