使用线程构建块 (TBB) 时如何修改线程调度行为?
有谁知道使用TBB时如何修改线程调度(特别是亲和力)?对简单的并行应用程序进行高级分析后,TBB 似乎以降低性能的方式指定底层线程的关联性。具体来说,我运行的核心启用了超线程,并且看起来 TBB 正在将线程关联到同一核心,即使有一个完全卸载的不同核心。
FWIW,我意识到 TBB 可能正在做“正确的事情”,并且更改线程的关联性只会降低性能。我只是想尝试一下,看看是否真的如此。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
TBB 2.1 添加了一个关联分区器,它根据缓存关联将任务分配给线程。使用此分区程序而不是默认分区程序可能会有所帮助。您还可以深入研究各个任务并使用
tbb::task::set_affinity
(文档 此处)。如果您的tbb::task
子类实现了note_affinity()
回调,那么如果任务碰巧在其亲和力指示的线程以外的线程上运行,调度程序可以通知您。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 oftbb::task
implements thenote_affinity()
callback.