How to deal with OpenMP thread pool contention

拈花ヽ惹草 提交于 2019-12-24 17:02:30

问题


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.

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?


回答1:


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.

for more info try this link




回答2:


You may be able to do what you want by clever use of omp_get_num_threads, omp_set_num_threads, and if and num_threads clauses on parallel directives. OpenMP 3.0 also provides tasks which might be useful.



来源:https://stackoverflow.com/questions/2686693/how-to-deal-with-openmp-thread-pool-contention

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!