|
ADS
Algorithms and Data Structures
|
The placement of the threads on the processors, beyond the book. More...
Files | |
| file | ADS/parallel/Affinity.h |
| The placement of the threads on the processors, beyond the book: a worker of a parallel algorithm pinned to a processor of its own keeps its caches, its pages first touched near its memory on a machine of several sockets (the policy of the first touch of the NUMA systems), and its timings repeatable, while the scheduler of the system may move an unpinned thread at every switch. | |
Functions | |
| const std::vector< int > & | ADS::affinityCpus (void) |
| the processors on which the process may run, in increasing order, as the first call found them: those of its binding, or those that the topology allows where the system does not tell the binding (macOS); empty where hwloc does not give them | |
| unsigned | ADS::availableCpus (void) |
| the number of processors on which the process may run, that of affinityCpus() where it is not empty and std::thread::hardware_concurrency() otherwise (0 if not known) | |
| bool | ADS::pinThread (unsigned i) |
| binds the calling thread to the processor \( i \bmod c \) of affinityCpus(), \( c \) their number; true if the thread is bound, false where the placement does not exist or the system refuses it | |
| int | ADS::currentCpu (void) |
| the processor on which the calling thread runs now, \( -1 \) where it is not known | |
The placement of the threads on the processors, beyond the book.
The definitions, the invariants and the costs of the area are in Theory of parallelism.
|
inline |
the processors on which the process may run, in increasing order, as the first call found them: those of its binding, or those that the topology allows where the system does not tell the binding (macOS); empty where hwloc does not give them
|
inline |
the number of processors on which the process may run, that of affinityCpus() where it is not empty and std::thread::hardware_concurrency() otherwise (0 if not known)
|
inline |
the processor on which the calling thread runs now, \( -1 \) where it is not known
|
inline |
binds the calling thread to the processor \( i \bmod c \) of affinityCpus(), \( c \) their number; true if the thread is bound, false where the placement does not exist or the system refuses it
In pseudocode (beyond the book), \( C \) the processors of affinityCpus():
\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{pinThread}( i ) \cr 2 & \quad \textbf{if}\ C = \emptyset\ \textbf{then return} \ \textbf{false} \cr 3 & \quad \textbf{return}\ \text{whether the system binds the thread } \text{to } C[ i \bmod |C| ] \end{array}} \]