Running Multi-threading Jobs
Multi-threading is a type of execution model that allows multiple threads to exist within the context of a process. Simply speaking, a Slurm multi-threading job is a single process, multi-core job. Many application can belong to this category, e.g.
- OpenMP programs,
- Matlab programs with (Parallel Computing Toolbox) enabled,
- Custom propgrams that use a threading library
An example Slurm Multi-threading job script
#!/bin/bash
#SBATCH --job-name=MyJob
... ...
#SBATCH --ntasks=1
#SBATCH --cpus-per-task=8
./myprog.exe
This script tells Slurm this is a multi-threading job. It has only 1 process, but that process needs 8 CPU cores to execute. You will need to tell your program how many cores you have. This depends on the program - they may do this different ways.
- a command line option e.g.
myprog.exe --cpus=8
- a shell environment variable e.g.
export OMP_NUM_THREADS=8
- the program may try and deduce it itself
A sample openMP program
This is an example of running a OpenMP job using Slurm. OpenMP is a parallel technology built into most compilers. It uses multiple threads in a single Linux process, i.e. an OpenMP program can not span multiple computers, but must be run on a single server.
To compile your code with OpenMP:
Compiler | Option To Use When Compiling |
---|---|
gcc | -fopenmp |
icc | -openmp |
To submit to Slurm
#!/bin/env bash
#SBATCH --nodes=1
#SBATCH --ntasks=1
#SBATCH --cpus-per-task=8
#SBATCH --ntasks-per-socket=1
export OMP_NUM_THREADS=8
./openmp_program.exe
Please note:
- Set OMP_NUM_THREADS to the same value as --cpus-per-task
- Your script can become more robust if you use a Slurm environment variables. Note that this variable is only set when the job is running in a Slurm environment
export OMP_NUM_THREADS=$SLURM_JOB_CPUS_PER_NODE
./openmp_program.exe
There are more examples of using openMP with Slurm here