Repository navigation
Conversation
With OMP_DYNAMIC=true the OpenMP runtime may start fewer threads than exec_blas() queues jobs (libgomp subtracts the load average). The jobs of a threaded level-3 driver wait for each other, so a job that no thread runs blocks the others forever: dgemm hangs on a busy machine.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
In an OpenMP build with dynamic adjustment of the number of threads (
OMP_DYNAMIC=trueoromp_set_dynamic(1)), threaded level-3 calls can hang forever. The runtime may give the team inexec_blas()fewer threads than there are jobs; libgomp subtracts the load average. The jobs of a threaded level-3 driver wait for each other (inner_threadindriver/level3/level3_thread.c), so the jobs that no thread picks up leave the running ones spinning.utest/test_syrk_thread.calready avoids threaded cases whenomp_get_dynamic()is set for this reason.This is the same class of hang as #6291 (
OMP_THREAD_LIMIT), but it needs a different fix: the team size under dynamic adjustment is not known before the region starts.Reproducer
I ran it on a 16-thread Ryzen 7 5800HS (GCC 16.2.1 / libgomp, Linux) under a normal desktop load. It hangs with both the current
develop(93a2969,make USE_OPENMP=1) and the Fedora 45openblas-openmp0.3.34 package. A plain#pragma omp parallel num_threads(16)on the same machine got a team of 7 threads withOMP_DYNAMIC=true, and 16 afteromp_set_dynamic(0).Fix
exec_blas()indriver/others/blas_server_omp.cturns dynamic adjustment off for its own parallel region and restores the caller's setting afterwards.omp_set_dynamic()changes only the dyn-var of the calling task, so other OpenMP code in the process is not affected. The caller-managed path (openblas_threads_callback_) is unchanged.Test
utest/test_omp_dynamic.ccalls a 512×512dgemmwithomp_set_dynamic(1). It checks the result and thatomp_get_dynamic()is still set afterwards. Whether the runtime shrinks the team depends on the machine's load, so without the fix the test hangs only on a busy machine; on an idle CI runner it passes either way../openblas_utest omp_dynamichung in 3 of 3 runs (killed bytimeout 60; load average 1.5–2).make -C utest run_test(USE_OPENMP=1 NOFORTRAN=1): 179 + 1563 tests ok.OMP_DYNAMIC=true ./openblas_utest: 179 ok.make -C ctest: all pass.This PR and #6291 both add a test to the same lines of
utest/Makefileandutest/CMakeLists.txt. I will rebase whichever is merged second.