astrophobia
astrophobia

Reputation: 889

Is it possible to control the Openmp thread that is used to execute an openmp task in C++?

Is it possible to control the openmp thread that is used to execute a particular task? In other words say that we have the following three tasks:

#pragma omp parallel
#pragma omp single 
{
#pragma omp task
    block1();
#pragma omp task
    block2();
#pragma omp task
    block3();
}

Is it possible to control the set of openmp threads that the openmp scheduler chooses to execute each of these three tasks? The idea is that if I have used openmp's thread affinity mechanism to bind openmp threads to particular numa nodes, I want to make sure that each task is executed by the appropriate numa node core. Is this possible in Openmp 4.5? Is it possible in openmp 5.0?

Upvotes: 3

Views: 295

Answers (1)

Michael Klemm
Michael Klemm

Reputation: 2873

In a certain sense, this can be accomplished using the affinity clause that has been introduced with the OpenMP API version 5.0. What you can do is this:

float * a = ...
float * b = ...
float * c = ...

#pragma omp parallel
#pragma omp single 
{
#pragma omp task affinity(a)
    block1();
#pragma omp task affinity(b)
    block2();
#pragma omp task affinity(c)
    block3();
}

The OpenMP implementation would then determine where the data of a, b, and c has been allocated (so, in which NUMA domain of the system) and schedule the respective task for execution on a thread in that NUMA domain. Please note, that this is a mere hint to the OpenMP implementation and that it can ignore the affinity clause and still execute the on a different thread that is not close to the data.

Of course, you will have to use an OpenMP implementation that already supports the affinity clause and does more than simply ignore it.

Other than the above, there's no OpenMP conforming way to assign a specific task to a specific worker thread for execution.

Upvotes: 2

Related Questions