SLURM Parallelism

What is Parallelism?

Parallelism on computers refers to doing several calculations simultaneously, or in parallel. HPC clusters enable parallelism by providing access to many different nodes and many cores within each node (for more on that for each of OIT-RC's systems, visit this page). OIT-RC uses SLURM to manage the jobs on each cluster, and SLURM has a handful of ways to specify how to run each job.

Parallelism with SLURM

Here are some relevant options SLURM has to let users control how their job are run. These are best to be specified as part of an #SBATCH in a submission script. To get the best use out of the systems, check the systems page for the hardware specifics available to it.

Be aware that SLURM considers each Phi hyper-thread as a core.


SLURM Flags


Vocabulary

Examples

A lot of these options do sound extremely similar, but they will have different effects. Here are some examples. Any Python examples use a Virtual Environment to have access to mpi4py, and more information can be found here, but that is not the focus of this document.

It is recommended to use mpiexec instead of mpirun, they work extremely similarly but mpirun is the old version of mpiexec.


Allocating and using four tasks between two nodes with mpiexec

#!/bin/bash

#SBATCH --ntasks 4

#SBATCH --nodes 2

#SBATCH --output out.txt


module purge

module load Python/gcc/3.7.5/gcc-6.3.0

source ./mpiVirtualEnv/env/bin/activate


mpiexec -n 4 python3 ./helloMpi.py

This script will first allocate four tasks across two nodes and then fill all four available tasks with a process of helloMpi.py; in summary, helloMpi.py runs four times, using a minimum and maximum of two nodes. 


Allocating and using four tasks without mpiexec

#!/bin/bash

#SBATCH --ntasks 4

#SBATCH --output out.txt


module purge

module load Python/gcc/3.7.5/gcc-6.3.0

source ./mpiVirtualEnv/env/bin/activate


python3 ./calculationsExecutable 50 &

python3 ./calculationsExecutable 75 &

python3 ./calculationsExecutable 80 &

python3 ./calculationsExecutable 100 &

This sbatch script will first allocate four tasks and then fill those four allocated tasks with their own process calculationsExecutable with inputs of either 50, 75, 80, or 100 by sending them to the background (with the &). Since each process is sent to the background to fill its own task, the next process can be started immediately, assuming there is another task to fill. If someone finds themselves using something like this where they do the same calculations on different data, it is highly recommended to use a job array.

Since this sbatch script does not specify the number of nodes, the nodes the four different tasks can be on is determined by what is available in the medium partition (the default partition since it is unspecified).


Specifying tasks and tasks per node

#!/bin/bash

#SBATCH --ntasks 2

#SBATCH --ntasks-per-node 5

#SBATCH --output out.txt


module purge

module load Python/gcc/3.7.5/gcc-6.3.0

source ./mpiVirtualEnv/env/bin/activate


mpiexec -n 2 python3 helloMpi.py

This sbatch script will allocate two tasks, and limit the maximum tasks per node to five, and then create two processes of running helloMpi.py, one in each task. Since ntasks defaults to one task per node, each task will be on a different node.


Specifying nodes and tasks per node

#!/bin/bash

#SBATCH --ntasks-per-node 5

#SBATCH --nodes 2

#SBATCH --output out.txt


module purge

module load Python/gcc/3.7.5/gcc-6.3.0

source ./mpiVirtualEnv/env/bin/activate


mpiexec -n 10 python3 helloMpi.py

This sbatch script will allocate five tasks per node, and select two nodes to run on. This will allocate a total of ten tasks, which then each be filled by a process of running helloMpi.py on it. There is no way to know what the ratio of tasks on the first node to tasks on the second node.


Specifying nodes, tasks per node, and tasks

#!/bin/bash

#SBATCH --ntasks-per-node 5

#SBATCH --nodes 2

#SBATCH --ntasks 10

#SBATCH --output out.txt


module purge

module load Python/gcc/3.7.5/gcc-6.3.0

source ./mpiVirtualEnv/env/bin/activate


mpiexec -n 10 python3 helloMpi.py

This sbatch script will set the maximum tasks per node to five, and select two nodes to run on. This will allocate a total of ten tasks, and since there cannot be more than five tasks per node, both nodes must get five tasks each. Each task is then filled by a process of running helloMpi.py.


Multi-threading

#!/bin/bash

#SBATCH --ntasks 1

#SBATCH --cpus-per-task 16

This script will allocate a single task to have 16 cores to enable multi-threading. Generally, this is only done if the user desires multi-threading specifically.

How to verify that all of the selected cores are being used: