How to deal with OpenMP thread pool contention
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 co开发者_如何学Pythonstliest 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?
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
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.
精彩评论