Intel® oneAPI Threading Building Blocks
Ask questions and share information about adding parallelism to your applications when using this threading library.

Affinity Mask

eyalk
Beginner
315 Views

Hi,
In our application we have 2 separate parallel_fors running on different windows threads. We would like to use thread affinity mask so each one of them will run on different cores in a way they will not interfere each other. How can we do that? Should we use SetThreadAffinityMask function and if so, where should we use it?

Thanks

0 Kudos
1 Reply
Anton_Pegushin
New Contributor II
315 Views
Quoting - eyalk

Hi,
In our application we have 2 separate parallel_fors running on different windows threads. We would like to use thread affinity mask so each one of them will run on different cores in a way they will not interfere each other. How can we do that? Should we use SetThreadAffinityMask function and if so, where should we use it?

Thanks

Hi, from what I understand you're saying that you have two master threads each one starting a parallel_for. Correct? Then in reality in your application when TBB is initialized it creates (P-1) worker threads (P - is a number of processors) and each call to parallel_for submits tasks onto this thread pool. So for example on a 4 core machine your application would have two master threads (the ones initiating parallel_fors) and 3 worker threads. Since work distribution in TBB is done via task stealing from random victim thread, you can't predict if a given worker thread is executing a task from the first parallel_for or from the second one in a certain point in time (was this your understanding of how things were processed by the way?). So this generally means, that setting affinity masks for master threads (or even for master threads _and_ worker threads) does not guarantee optimal data locality. What you probably do want is to use affinity_partitioner for each of the parallel_fors.
0 Kudos
Reply