Hello everyone !
I am facing a small issue when using both OpenMP and TBB in the same application, when this application uses the thread-binding feature of OpenMP, which is enabled by setting the OMP_PROC_BIND environment variable to "true" (more details here http://gcc.gnu.org/onlinedocs/libgomp/OMP_005fPROC_005fBIND.html).
In the GNU implementation, when this environment variable is set, the function "gomp_init_affinity" is called, which, among other things, will set the process' affinity to only one CPU (this happens line 101 here http://gcc.gnu.org/viewcvs/trunk/libgomp/config/linux/affinity.c?view=ma... ).
The issue is, as it can be understood here http://software.intel.com/en-us/blogs/2010/12/28/tbb-30-and-processor-af... , that TBB will hence only create 1 worker thread, as only one CPU is bound to the current process (result of GNU OpenMP's gomp_init_affinity). And this happens even if a "tbb::task_scheduler_init" object is created with a given number of threads.
Please find attached a small example that shows the issue. You may need to adapt the Makefile to match your system.
What then could be interesting is to ask TBB not to restrict itself to only bound CPUs (even if that's an intersting feature in the first place). I tried to search on TBB's source code, but I think I didn't find anyhting interesting in tbb/governor.cpp (which at first glance looks like where to look for such a thing). I think I need a little help on where to start ;)
One temporary hack is to set an affinity on all CPU for the main process, then call tbb::task_scheduler_init and then set back the original affinity, but this is not optimal...
Any other ideas are welcomed :)
You can find attached sample programs that shows the issue and an implementation of the given hack !
The system used is the following:
- Linux Debian testing
- gcc (Debian 4.7.2-5) 4.7.2
- GNU OpenMP implementation (with gcc 4.7.2)
- tbb 4.1 20120718