https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126370

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
That is just bogus assumption.
The standard only requires reuse of threads with consecutive parallel regions
have the same number of threads (and non-nested; the requirement is through
guarantees on preserving threadprivate variables).
That is also the common case in the wild and something that should be
optimized.
Thread creation is expensive, sure, but keeping around hundreds or thousands of
useless threads for long running processes (especially if they use fully or
partially busy waiting because of OMP_WAIT_POLICY, GOMP_SPINCOUNT etc.) is even
worse.
If the library encounters
#pragma omp parallel num_threads(2048)
;
#pragma omp parallel num_threads(2)
;
it doesn't know if there will ever be another num_threads(2048).  libomp just
doesn't care and probably never destroys any threads it created.  In libgomp we
intentionally keep in the thread pool only threads which will be needed for the
next parallel with num_threads of the last one.

Reply via email to