如何处理OpenMP线程池争用 [英] How to deal with OpenMP thread pool contention

查看:155
本文介绍了如何处理OpenMP线程池争用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用同时使用粗粒度和细粒度多线程的应用程序.也就是说,我们手动管理线程池中大型工作单元的调度,然后在这些工作单元中,某些功能利用OpenMP进行更精细的多线程处理.

I'm working on an application that uses both coarse and fine grained multi-threading. That is, we manage scheduling of large work units on a pool of threads manually, and then within those work units certain functions utilize OpenMP for finer grain multithreading.

我们已经通过在最昂贵的循环中选择性使用OpenMP来实现收益,但是在将OpenMP块添加到更便宜的循环中时,我们担心会为OpenMP工作池争用.有没有一种方法可以向OpenMP发出信号,如果有代码块,则应该使用该池;如果没有,则应该串行处理该循环?

We have realized gains by selectively using OpenMP in our costliest loops, but are concerned about creating contention for the OpenMP worker pool as we add OpenMP blocks to cheaper loops. Is there a way to signal to OpenMP that a block of code should use the pool if it is available, and if not it should process the loop serially?

推荐答案

您可以使用omp_set_num_threads(int)设置编号.池中的线程数.然后,如果可能,编译器将尝试创建线程池并计划它们.如果无法创建池,则它将创建尽可能多的线程并以串行方式运行其他线程.

you can use omp_set_num_threads(int) to set no. of threads inside a pool. Then the compiler will try to create a pool of threads if possible and schedule them. if it is not possible to create pool, then it will create as many threads as possible and run others in serial fashion.

更多信息,请尝试此链接

这篇关于如何处理OpenMP线程池争用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆