OpenMP is parallel for region-specific thread affinity

Let's say I have the following OpenMP scope:

omp_set_num_threads(3);
#pragma omp parallel for
{
 //start
 ...
 //somewhere in the middle
 ...
 //end
}

      

Let's say I have an 8-core system. For example, after "start" let's say that thread 0 runs on core 4, thread 1 runs on core 5, and thread 2 runs on core 6. Is it possible "somewhere in the middle" to the "end" that threads migrate from their corresponding kernels, which they were assigned after the "start"? That is, is it possible that threads 0-2 are assigned to cores 4-5 after the "start", and "somewhere in the middle" threads say that the transition to cores 5-7, respectively? And would it even be possible that threads could be just before the "end" on cores 0-2? Thank.

+2


source to share


1 answer


As far as I know, the OpenMP 3.1 specs do not provide any means for re-binding threads.

In fact, the only way to have some control over the binding of streams is through an environment variable OMP_PROC_BIND

:

The OMP_PROC_BIND environment variable sets the value of the global ICV-bind-var. The value of this environment variable must be true or false . If the environment variable is set to true , the runtime should not move OpenMP threads between processors. If the environment variable is set to false , the runtime can move OpenMP threads between processors. The behavior of the program is implementation-defined if OMP_PROC_BIND is neither true nor false .



The OpenMP 4.0 project expands the possible values OMP_PROC_BIND

and adds an environment variable OMP_PLACES

that allows you to choose how threads are bound to resources. However, there is no standard way to rebind threads.

If absolutely necessary for you, you can consider using the hwloc library , specifically the processor binding part .

+3


source







All Articles