Affinity Mask

Affinity Mask

eyalk's picture

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

2 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.
Anton Pegushin (Intel)'s picture
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.

Login to leave a comment.