Get the current thread pool opmp pool

Is there a way to determine at runtime what the current OpenMP thread pool size is?

By this I mean the actual number of threads spawned by OpenMP and not received, not the maximum number of threads allowed ( omp_get_num_procs

), as well as the number of threads that will be used by default in the new parallel scope ( omp_get_num_threads

).

Motivation: I have a Python library that creates forks subprocesses for certain computations, including some that use OpenMP under the hood via plugins. If someone calls any OpenMP based function before forking, the process stops. This is because OpenMP is not file safe : the process will hang if usedfork

"after using OpenMP functions." I would like this forking library to automatically detect if a fork is too late since OpenMP features have already been used. On such detection, it will throw an exception instead of going on and hanging. The best approach that comes to mind is to determine if the OpenMP thread pool is running, and it is not clear what is the best way to do this. Truncating before pstack

and clearing stack traces for libgomp.so

seems too careless and I don't know if this will work well for other OpenMP implementations like Intel.

+3


source to share





All Articles