How does one modify the thread scheduling behavior when using Threading Building Blocks (TBB)?

StackOverflow https://stackoverflow.com/questions/2405849

  •  18-09-2019
  •  | 
  •  

Question

Does anyone know how to modify the thread scheduling (specifically affinity) when using TBB? Doing a high level analysis on a simple parallel-for application, it seems like TBB is specifying the underlying threads' affinity in a way that reduces performance. Specifically, the cores I'm running on have hyper-threading enabled, and it looks like TBB is affinitizing threads to the same core even if there is a different core left completely unloaded.

FWIW, I realize it's likely that TBB is doing the "right thing" and that changing the threads' affinity will only reduce performance. I'd just like to experiment with it to see if that's really the case.

Was it helpful?

Solution

TBB 2.1 added an affinity partitioner which assigns tasks to threads based on cache affinity. Using this partitioner instead of the default one might help out. You can also dive into individual tasks and use tbb::task::set_affinity (documentation here). The scheduler can notify you if the task happens to run on a thread other than the one indicated by its affinity if your subclass of tbb::task implements the note_affinity() callback.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top