Processor Affinity
Each JUSUF compute node consists of two sockets, each with one CPU. Each CPU has 64 physical and 128 logical cores, so that one JUSUF compute node consists of 128 physical and 256 logical cores. Each CPU is split into four separate NUMA domains for a total of eight NUMA domains pre node.
Warning
This documentation page is currently out of date due to a Slurm upgrade to version 22.05 which can have a major impact on the performance of your application. We are working on an update.
Unless running on SMT is explicitly requested, we strongly recommend using the
--hint=nomultithread
option (which implies--threads-per-core=1
). If you want to use SMT we would recommend to set--distribution=block:cyclic:cyclic
.srun will no longer read in
SLURM_CPUS_PER_TASK
and will not inherit option--cpus-per-task
from sbatch! This means you will explicitly have to specify –cpus-per-task to your srun calls, or set the new SRUN_CPUS_PER_TASK env var. If you want to keep using –cpus-per-task with sbatch then you will have to add:export SRUN_CPUS_PER_TASK=${SLURM_CPUS_PER_TASK}
.Using the option
--cpus-per-task
in 22.05 does imply--exact
, which means that each step with--cpus-per-task
will now only get the minimum number of cores. The pinning will change (implication on the performance) and the tasks will fill the HW threads of same cores. If you don’t use SMT and want to keep old behavior as before where your threads run only on real cores then add this to srun:--threads-per-core=1
.If you have any questions, please contact SC support [sc@fz-juelich.de].
Pinning, the binding of a process or thread to a specific core, can improve the performance of your code by increasing the percentage of local memory accesses. Once your code runs and produces correct results on a system, the next step is performance improvement. For a code that uses multiple cores, the placement of processes and/or threads can play a significant role in performance.
In general, the Linux scheduler will periodically (re-)distribute all running processes across all available threads to ensure similar usage of the threads. This causes processes being moved from one thread, core, or socket to another within the compute node. Note that the allocated memory of a process does not necessarily move at the same time (or at all), possibly making access to memory much slower. To avoid such a potential performance loss by process migration, processes are usually pinned (or bound) to a logical core through the resource management system, SLURM in case of JUSUF. A pinned process (consisting of one or more threads) is bound to a specific set of cores and will only run on the cores in this set. The set can be a single or multiple logical cores that implicitly includes 1st and 2nd level caches and is defined with an affinity mask. Since the majority of applications benefit from strict pinning that prevents migration – unless explicitly prevented – all tasks in a job step are pinned to a set of cores by default. Further information about the default behaviour can be found below.
Note
Even though the default setting improves the performance of average applications over no process binding at all, specialised settings for your application can yield even better performance. Pay attention to maximizing data locality while minimizing latency and resource contention, and have a clear understanding of the characteristics of your own code and the machine that the code is running on.
Slurm options
Slurm allows users to modify the process affinity by means of the --cpu-bind
, --distribution
and --hint
options to srun
.
While the available options to srun
are standard across all Slurm installations, the implementation of process affinity is done in plugins and thus may differ between installations.
On JUSUF a custom pinning implementation by ParTec is used (psslurm).
In contrast to other options, the processor affinity options need to be directly passed to srun
and must not be given to sbatch
or salloc
.
In particular, the option cannot be specified in the header of a batch script.
Note
It is important to specify the correct --cpus-per-task
count to ensure a proper affinity mask for hybrid applications and set the environment variable OMP_NUM_THREADS
correspondingly.
However, the individual threads of each MPI rank can still be moved between the logical threads matching the affinity mask of this rank.
To also avoid this behaviour, there are diffenrent possibilities to pin the threads to specific logical cores within the mask, e.g., by the OpenMP runtime library: Intel: KMP_AFFINITY
, GNU: GOMP_AFFINITY
or with the API of sched_setaffinity
or kmp_set_affinity
among others.
Terminology
- thread
One CPU thread.
- task
Part of a job consisting of a number of requested CPU threads (specified by
-c, --cpus-per-task
). Usually this is a process.- core
One physical CPU core can run multiple CPU threads. The CPU threads sitting on the same physical core are sharing caches (traditional name of the second memory locality domain)
- socket
Consists of a number of CPU threads with the same memory locality (traditional name of the top most memory locality domain)
--cpu-bind
--cpu-bind=[{quiet,verbose},none|rank|map_cpu:<list>|mask_cpu:<list>|rank_ldom|map_ldom:<list>|mask_ldom:<list>|sockets|cores|threads|ldoms|boards]
Implicit types
|
Do not bind tasks to CPUs |
|
Each task is pinned to as many threads as it requests, just filling cores
consecutively. Spread the threads and tasks to as many cores as possible.
This type is not influenced by the second and third part of the |
|
Each task is pinned to as many threads as it requests. Which threads each process
gets is controlled by the |
|
Each task is pinned to as many threads as it requests, just filling the nodes
rank by rank cycling sockets and cores. This type is not influenced by the second
and third level of the –distribution option. The threads of a task are always
packed to as few cores as possible. This is the same as
|
|
In a first step the requested CPU threads of a task are assigned in exactly the
same way as with |
|
In a first step the requested CPU threads of a task are assigned in exactly the
same way as with |
|
This is the same as |
|
Currently not supported on systems with more than one board per node.
JUSUF has only one board: same behavivor as |
Explicit types
|
Explicit passing of maps or masks to pin the tasks to threads in a round-robin fashion. |
|
|
|
Explicit passing of maps or masks to pin the tasks to sockets in a round-robin fashion. |
|
--distribution
The string passed to --distribution/-m
can have up to four parts separated by colon and comma:
The first part controls the distribution of the task over the nodes.
The second part controls the distribution of tasks over sockets inside one node.
The third part controls the distribution of tasks over cores inside one node.
The fourth part is an additional information concerning the distribution of tasks over nodes.
--distribution/-m=<node_level>[:<socket_level>[:<core_level>[,Pack|NoPack]]]
First part (node_level
)
|
The default is |
|
Distribute tasks to a node such that consecutive tasks share a node |
|
Distribute tasks to a node such that consecutive tasks are distributed over consecutive nodes (in a round-robin fashion) |
|
|
|
Second part (socket_level
)
|
The default is |
|
Each socket is first filled with tasks before the next socket will be used. |
|
Each task will be assigned to the next socket(s) in a round-robin fashion. |
|
Each thread inside a task will be assigned to the next socket in a round-robin
fashion, spreading the task itself as much as possible over all sockets.
|
Third part (core_level
)
|
The default is |
|
Each core is first filled with tasks before the next core will be used. |
|
Each task will be assigned to the next core(s) in a round-robin fashion. The threads of a task will fill the cores. |
|
Each thread inside a task will be assigned to the next core in a round-robin
fashion, spreading the task itself as much as possible over all cores.
|
Fourth part
Optional control for task distribution over nodes.
|
Default is NoPack. See: https://slurm.schedmd.com/srun.html |
|
--hint
If the hint nomultithread
is given, the affinity will be set as if there were only one thread per core on the nodes and an error message will be thrown if the total amount of the threads you are trying to use per node is higher than available amount of physical hardware threads.
--hint=nomultithread
Note
The hints compute_bound
and memory_bound
are currently not supported.
Affinity examples
Visualization of the processor affinity in the following examples is done by the tool psslurmgetbind
which is also available on the login nodes of JUSUF.
The displayed scheme represents one node of JUSUF which has two sockets divided by the blank space in the middle.
Each column corresponds to one core; the first row shows the first (physical) thread of the corresponding core and the second row the SMT (logical thread) of the core.
The number (X
) followed by a :
in the line above the described scheme represents the MPI task number for which the affinity mask is shown in the scheme.
The number 1
in the scheme itself indicates that the task with its threads is scheduled on the corresponding hardware thread of the node.
Example: One MPI task with two threads:
For the purpose of presentation, ...
indicates that not all cores on a JUSUF node are shown.
![../_images/psslurmgetbind_jusuf.jpg](../_images/psslurmgetbind_jusuf.jpg)
Further examples with a colored representation can be found here Talk: Pinning with psslurm
.
Default processor affinity
The default processor affinity has changed at 12th May 2020 to the following setting:
--cpu-bind=threads --distribution=block:cyclic:fcyclic
The behavior of this combination is shown in the following examples for JUSUF.
Example 1: Pure MPI application filling only the first thread of a core on a node:
srun --nodes=1 --tasks-per-node=128 --cpus-per-task=1
$ psslurmgetbind 2 64 2 -h : -n 128 -c 1
0:
100000000000...000000000000 000000000000...000000000000
000000000000...000000000000 000000000000...000000000000
1:
000000000000...000000000000 100000000000...000000000000
000000000000...000000000000 000000000000...000000000000
...
126:
000000000000...000000000001 000000000000...000000000000
000000000000...000000000000 000000000000...000000000000
127:
000000000000...000000000000 000000000000...000000000001
000000000000...000000000000 000000000000...000000000000
Example 2: Pure MPI application filling all all threads on a node (including SMT):
srun --nodes=1 --tasks-per-node=256 --cpus-per-task=1
$ psslurmgetbind 2 64 2 -h : -n 256 -c 1
0:
100000000000...000000000000 000000000000...000000000000
000000000000...000000000000 000000000000...000000000000
1:
000000000000...000000000000 100000000000...000000000000
000000000000...000000000000 000000000000...000000000000
...
126:
000000000000...000000000001 000000000000...000000000000
000000000000...000000000000 000000000000...000000000000
127:
000000000000...000000000000 000000000000...000000000001
000000000000...000000000000 000000000000...000000000000
128:
000000000000...000000000000 000000000000...000000000000
100000000000...000000000000 000000000000...000000000000
129:
000000000000...000000000000 000000000000...000000000000
000000000000...000000000000 100000000000...000000000000
...
254:
000000000000...000000000000 000000000000...000000000000
000000000000...000000000001 000000000000...000000000000
255:
000000000000...000000000000 000000000000...000000000000
000000000000...000000000000 000000000000...000000000001
Example 3: Hybrid application (MPI + OpenMP) with 4 tasks per node and 36 Threads per task:
srun --nodes=1 --tasks-per-node=4 --cpus-per-task=36
$ psslurmgetbind 2 64 2 -h : -n 4 -c 36
0:
1111111111111111111111111111111111110000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000
1:
0000000000000000000000000000000000000000000000000000000000000000 1111111111111111111111111111111111110000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000
2:
0000000000000000000000000000000000001111111111111111111111111111 0000000000000000000000000000000000000000000000000000000000000000
1111111100000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000
3:
0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000001111111111111111111111111111
0000000000000000000000000000000000000000000000000000000000000000 1111111100000000000000000000000000000000000000000000000000000000
Example 4: Pure OpenMP application with 128 Threads:
srun --nodes=1 --cpus-per-task=128
$ psslurmgetbind 2 64 2 -h : -n 1 -c 128
0:
111111111111...111111111111 000000000000...000000000000
111111111111...111111111111 000000000000...000000000000
Further examples
Example 1: Hybrid application (MPI + OpenMP) with 4 tasks per node and 36 Threads per tasks using --distribution=*:*:cyclic
. Most of the hybrid applications using more than tasks-per-node * cpus-per-tasks > 128 per node on JUSUF should benefit from this setting:
srun --nodes=1 --tasks-per-node=4 --cpus-per-task=36 --distribution=*:*:cyclic
$ psslurmgetbind 2 64 2 -h : -n 4 -c 36 --distribution=*:*:cyclic
0:
1111111111111111110000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000
1111111111111111110000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000
1:
0000000000000000000000000000000000000000000000000000000000000000 1111111111111111110000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000 1111111111111111110000000000000000000000000000000000000000000000
2:
0000000000000000001111111111111111110000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000
0000000000000000001111111111111111110000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000
3:
0000000000000000000000000000000000000000000000000000000000000000 0000000000000000001111111111111111110000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000 0000000000000000001111111111111111110000000000000000000000000000
Example 2: Pure MPI application using only the first thread of a core on a node with --cpu-bind=rank
srun --nodes=1 --tasks-per-node=128 --cpus-per-task=1 --cpu-bind=rank
$ psslurmgetbind 2 64 2 -h : -n 128 -c 1 --cpu-bind=rank
0:
100000000000...000000000000 000000000000...000000000000
000000000000...000000000000 000000000000...000000000000
1:
010000000000...000000000000 000000000000...000000000000
000000000000...000000000000 000000000000...000000000000
...
126:
000000000000...000000000000 000000000000...000000000010
000000000000...000000000000 000000000000...000000000000
127:
000000000000...000000000000 000000000000...000000000001
000000000000...000000000000 000000000000...000000000000
Example 3: Pure MPI application filling all all threads on a node (including SMT) with --cpu-bind=rank
srun --nodes=1 --tasks-per-node=256 --cpus-per-task=1 --cpu-bind=rank
$ psslurmgetbind 2 64 2 -h : -n 256 -c 1 --cpu-bind=rank
0:
100000000000...000000000000 000000000000...000000000000
000000000000...000000000000 000000000000...000000000000
1:
010000000000...000000000000 000000000000...000000000000
000000000000...000000000000 000000000000...000000000000
...
126:
000000000000...000000000000 000000000000...000000000010
000000000000...000000000000 000000000000...000000000000
127:
000000000000...000000000000 000000000000...000000000001
000000000000...000000000000 000000000000...000000000000
128:
000000000000...000000000000 000000000000...000000000000
100000000000...000000000000 000000000000...000000000000
129:
000000000000...000000000000 000000000000...000000000000
010000000000...000000000000 000000000000...000000000000
...
254:
000000000000...000000000000 000000000000...000000000000
000000000000...000000000000 000000000000...000000000010
255:
000000000000...000000000000 000000000000...000000000000
000000000000...000000000000 000000000000...000000000001
Example 4: Hybrid application (MPI + OpenMP) with 4 tasks per node and 36 Threads per task --cpu-bind=rank
srun --nodes=1 --tasks-per-node=4 --cpus-per-task=36 --cpu-bind=rank
$ psslurmgetbind 2 64 2 -h : -n 4 -c 36 --cpu-bind=rank
0:
1111111111111111111111111111111111110000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000
1:
0000000000000000000000000000000000001111111111111111111111111111 1111111100000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000
2:
0000000000000000000000000000000000000000000000000000000000000000 0000000011111111111111111111111111111111111100000000000000000000
0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000
3:
0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000011111111111111111111
1111111111111111000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000
Examples for manual pinning
For advanced use cases it can be desirable to manually specify the binding masks or core sets for each task.
This is possible using the options --cpu-bind=map_cpu
and --cpu-bind=mask_cpu
.
For example,
srun -n 2 --cpu-bind=map_cpu:1,5
spawns two tasks pinned to core 1 and 5, respectively. The command
srun -n 2 --cpu-bind=mask_cpu:0x3,0xC
spawns two tasks pinned to cores 0 and 1 (0x3 = 3 = 2^0 + 2^1
) and cores 2 and 3 (0xC = 12 = 2^2 + 2^3
), respectively.
Affinity visualisation
You can use a web interface, available at https://apps.fz-juelich.de/jsc/llview/pinning, to test and visualise different SLURM affinity setups by yourself.
Differences to vanilla Slurm (19.05)
Auto binding is not supported in psslurm
--cpu-bind=boards
is not supportedThe option
--cpu-bind=rank
is implemented differently in psslurm, since it is redundant and makes no sense without auto-pin. Slurm completely ignores the--cpus-per-task
option here, psslurm does not.psslurm does NOT YET differentiate
ldoms
fromsockets
. This keywords are currently used equivalent.psslurm does not consider the values given to the options
--ntasks-per-core
and--ntasks-per-socket
. (As far as we could observe, Slurm does neither, even though it is described otherwise in the srun manpage.)The hints
compute_bound
andmemory_bound
are currently not supported.psslurm follows what is described at the srun manpage. (In many cases, Slurm does not.)