-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Description
Explain what you would like to see improved and how.
ROOT's use of their own tbb::task_arena (from #14807) can cause the main thread of a program to be left with no work to do.
The issue is the following. CMS creates its own tbb::task_arena in the main thread (to control the number of threads the application is allowed to use). Then in that arena, we do a tbb::task::wait until the application has finished all work. That means the main thread is part of CMS's arena. Now say we call a ROOT API (e.g. TTree::Fill) which behind the scenes makes use of tbb concurrency. For simplicity, let us say the application is using 2 threads. If the ROOT API happens to be called from the main thread (a 50/50 chance) then ROOT's arena temporarily takes control of the main thread and the ROOT API makes use of both the main thread and the one TBB worker thread in the job. On the other hand, if the ROOT API is called from the TBB worker thread, that worker thread becomes part of the ROOT arena but the main thread does not. This means the ROOT API only has access to 1 thread and the main thread will remain idle.
We have seen this issue in real world applications.
We understand that for the non-framework user's use the EnableImplicitMT(<number of threads>) API needs the ability to set the number of of threads to use and that does require the use of a tbb::task_arena. However, for an application that is controlling the threads directly via TBB already (like the CMS framework) we request that a different API (either passing a special value to EnableImplicitMT or a new function entirely) which will cause ROOT to use the tbb::task_arena already in use by the calling thread. This can even still work with
root/core/imt/src/RTaskArena.cxx
Line 93 in 9b8ed94
| RTaskArenaWrapper::RTaskArenaWrapper(unsigned maxConcurrency) : fTBBArena(new ROpaqueTaskArena{}) |
by being able to pass oneapi::tbb::attach to the constructor of ROpaqueTaskArena.
E.g.
RTaskArenaWrapper::RTaskArenaWrapper(unsigned maxConcurrency) :
fTBBArena(maxConcurrency == RTaskArenaWrapper::Attach? new ROpaqueTaskArena{oneapi::tbb::attach} : new ROpaqueTaskArena{})Where RTaskArenaWrapper::Attach == std::numeric_limits<unsigned>::max()
ROOT version
6.32 and beyond
Installation method
build from source
Operating system
linux
Additional context
No response