thread-affinity-openmp
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| thread-affinity-openmp [June 11, 2026 at 09:20] – created - external edit 127.0.0.1 | thread-affinity-openmp [Unknown date] (current) – removed - external edit (Unknown date) 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | # Thread affinity (OpenMP) | ||
| - | On a laptop or single-socket desktop, every core reaches the same RAM at the same speed. On a multi-socket server, each socket has its own bank of RAM (NUMA, non-uniform memory access): accessing local memory is fast, but crossing the inter-socket interconnect to reach the other socket' | ||
| - | |||
| - | ```c | ||
| - | #pragma omp parallel proc_bind(spread) num_threads(8) | ||
| - | { | ||
| - | // threads are spread evenly across sockets; good for bandwidth-bound work | ||
| - | } | ||
| - | |||
| - | #pragma omp parallel proc_bind(close) | ||
| - | { | ||
| - | // threads are packed near the master thread; good for latency-sensitive work | ||
| - | // that shares a last-level cache | ||
| - | } | ||
| - | ``` | ||
| - | |||
| - | The `proc_bind` policies are: | ||
| - | |||
| - | - `spread` — distribute threads as evenly as possible across the available places (sockets or cores); maximises total memory bandwidth | ||
| - | - `close` — place threads as close together as possible relative to the master; maximises shared cache reuse | ||
| - | - `master` — place all threads on the same place as the master thread | ||
| - | |||
| - | `OMP_PLACES` defines what a " | ||
thread-affinity-openmp.1781169611.md.gz · Last modified: by 127.0.0.1
