HOME
| OPENMP API Specification: Version 5.0 November 2018

2.6.2  Controlling OpenMP Thread Affinity

When a thread encounters a parallel directive without a proc_bind clause, the bind-var ICV is used to determine the policy for assigning OpenMP threads to places within the current place partition, that is, within the places listed in the place-partition-var ICV for the implicit task of the encountering thread. If the parallel directive has a proc_bind clause then the binding policy specified by the proc_bind clause overrides the policy specified by the first element of the bind-var ICV. Once a thread in the team is assigned to a place, the OpenMP implementation should not move it to another place.

The master thread affinity policy instructs the execution environment to assign every thread in the team to the same place as the master thread. The place partition is not changed by this policy, and each implicit task inherits the place-partition-var ICV of the parent implicit task.

The close thread affinity policy instructs the execution environment to assign the threads in the team to places close to the place of the parent thread. The place partition is not changed by this policy, and each implicit task inherits the place-partition-var ICV of the parent implicit task. If T is the number of threads in the team, and P is the number of places in the parent’s place partition, then the assignment of threads in the team to places is as follows:

The purpose of the spread thread affinity policy is to create a sparse distribution for a team of T threads among the P places of the parent’s place partition. A sparse distribution is achieved by first subdividing the parent partition into T subpartitions if T P , or P subpartitions if T > P . Then one thread (T P ) or a set of threads (T > P ) is assigned to each subpartition. The place-partition-var ICV of each implicit task is set to its subpartition. The subpartitioning is not only a mechanism for achieving a sparse distribution, it also defines a subset of places for a thread to use when creating a nested parallel region. The assignment of threads to places is as follows:

The determination of whether the affinity request can be fulfilled is implementation defined. If the affinity request cannot be fulfilled, then the affinity of threads in the team is implementation defined.

SVG-Viewer needed.

Note – Wrap around is needed if the end of a place partition is reached before all thread assignments are done. For example, wrap around may be needed in the case of close and T P , if the master thread is assigned to a place other than the first place in the place partition. In this case, thread 1 is assigned to the place after the place of the master place, thread 2 is assigned to the place after that, and so on. The end of the place partition may be reached before all threads are assigned. In this case, assignment of threads is resumed with the first place in the place partition.

SVG-Viewer needed.