Destroy The Thread Pool

Destroy The Thread Pool


I am trying to destroy(shutdown) the threads created by parallel directive after exiting the parallel region. Right now, the threads are put to "sleep". 

Is there any way to do that? If not, could someone please help me to do it?



5 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Are you aware of KMP_BLOCKTIME and OMP_WAIT_POLICY ?

Yes but I am looking for something to shutdown all the threads. Not just let them wait.

Hi Ali,

You can slightly change __kmpc_end() function, - replace the call to __kmp_internal_end_thread(-1) with the call to __kmp_internal_end_library(-1) then compile the library.  After that you may set KMP_IGNORE_MPPEND environment variable to 0, and call __kmpc_end(NULL); in any place in your application to completely shutdown the OpenMP runtime library.  All threads will be destroyed.

Alternatively you can link with static OpenMP runtime (e.g. use -qopenmp-link=static compiler option on Linux), and similarly call __kmpc_end(NULL) in serial code of your application, - no need to change library code in this case. Of cause the KMP_IGNORE_MPPEND should be set to 0.


Thanks a lot Andrey. I really appreciate your help.

Leave a Comment

Please sign in to add a comment. Not a member? Join today