Intel® C++ Compiler 16.0 User and Reference Guide
The affinity type balanced is particularly useful on the Intel® MIC Architecture. It is supported on the CPU only for single socket systems.
The OpenMP* environment variable OMP_PROC_BIND=spread is similar to KMP_AFFINITY=balanced and is available on all platforms, including multi-socket CPU systems.
Under this setting, the OpenMP* runtime places threads on separate cores until all cores have at least one thread, similar to the scatter type. However, when the runtime must use multiple hardware thread contexts on the same core, the balanced type ensures that the OpenMP* thread numbers are close to each other, which scatter does not do.
The following diagrams illustrate the allocation of six OpenMP* threads across a 3-core system with the compact, scatter, and balanced affinity types.
On the Intel® MIC Architecture, it is normally beneficial to use cores before threads, so the compact affinity type is unlikely to yield the best results, because it leaves cores unused.
The thread allocation under scatter is likely to be better than compact, because it uses cores before threads. However, scatter allocates thread IDs such that threads with IDs in close numerical proximity are on different cores, and therefore do not share caches. Because threads with neighboring IDs often operate on closely related data, placing them on different cores is unlikely to be the best way to allocate them.
The thread allocation under balanced is balanced over the cores and the threads allocated to a core are neighbors of each other. Therefore, cache utilization should be efficient if the threads access data that is near in store.
Tuning affinity is a complicated and machine specific process. Using the balanced affinity type is a reasonable starting point on Intel® MIC Architecture.
The balanced affinity type is also recognized and supported by the OpenMP* runtime on the CPU, but only for single socket systems.
Using the balanced type with the environment variable KMP_AFFINITY propagates to the coprocessor when MIC_ENV_PREFIX is not set. However, this may generate the following runtime warning on a multi-socket CPU:
OMP: Warning #230: KMP_AFFINITY: Affinity balanced is not available.
To set the balanced affinity type for only the Intel® MIC Architecture environment, assign a specific prefix using the MIC_ENV_PREFIX=prefix and then set prefix_KMP_AFFINITY with balanced.