Getting started
This document should help you get started with logging in to the cluster and running a "Hello world" script as a slurm job.
Running code on slurm is always an asynchronous process. In other words you submit a job to the queue, Slurm schedules the job for execution when relevant resources are available, and any output from your job is recorded in a file.
Preparing your script
Write the following code into a file named hello-slurm.sh
#!/bin/bash
#SBATCH --job-name=testjob
#SBATCH --partition=cpu
echo "Hello $HOSTNAME"
The initial #SBATCH comments are special commands read by Slurm, passing instructions about how to execute your job. Here we only choose a name for the job and which partition to run it on. An incomplete list of useful sbatch arguments is available here.
$HOSTNAME is an environment variable that contains the name of the server the code is running on.
Submitting your job
Once you have saved your script, you queue it for execution by running the following command:
sbatch hello-slurm.sh
You should see output similar to this:
Submitted batch job 1928Since the script does very little work it will probably execute immediately, but if it doesn't you can see its place in the queue by running the command squeue. You can also see details about your job by running scontrol show job NN, where NN is the job ID that was printed (1928 in this example).
Reading job output
Since the job is run asynchronously, the output from your job will not be printed to your terminal as usual but written to a file. We don't specify a filename to use, so slurm will use the default name. The default name is slurm-NN.out, where NN is the job ID.
You can read the resulting file with any tool that can read text files, such as cat:
erth9960@slurm-login:~$ cat slurm-1928.out
Hello slurm-node-cpu-01
Here you can see that the code executed on slurm-node-cpu-01, as opposed to slurm-login which is where your terminal session is running.