Skip to content

Native: Avoid nested OpenMP teams in Block-Jacobi with non-thread-safe sub-solvers - #15

Closed
hansec wants to merge 1 commit into
mainfrom
claude/superlu-dist-omp-hang-37ba97
Closed

hansec wants to merge 1 commit into
mainfrom
claude/superlu-dist-omp-hang-37ba97

Conversation

@hansec

@hansec hansec commented Nov 18, 2026

Copy link
Copy Markdown
Owner

Summary

bjprecond_apply now opens its OpenMP parallel region only when the sub-solver is thread safe. When it is not (superd, mumps), the local sub-solves run with no enclosing region at all, so OpenMP teams created inside those libraries are top-level rather than nested.

The per-part loop moved into a contained routine, apply_parts, that uses an orphaned !$omp do, so the same code runs inside or outside the region.

No API or input file changes.

Why

With SuperLU-DIST built with OpenMP (eg. by PETSc --with-openmp), the test_native_bjacobi.py::test_LU_*nlocal2*[2] tests hang at OMP_NUM_THREADS=2 on macOS with GCC 16. They pass with 1 thread or OMP_DYNAMIC=true. All PETSc versions 3.20–3.24 are affected.

The cause is a libgomp bug in the POSIX barrier implementation it uses on Darwin (no futex):

  • GOMP_task posts a wake-up token to the barrier semaphore for each task, whether or not a thread is waiting. SuperLU-DIST's pdgstrs2_omp, called from pdgstrf, creates tasks.
  • Nested teams get an extra teardown barrier: gomp_team_end waits with gomp_barrier_wait, and each worker with gomp_barrier_wait_last. On POSIX that barrier has no generation check, so a leftover task token lets the master leave early and free the team.
  • The next nested team is allocated at the same address while the old worker still waits on it. Later barriers then pair up out of phase: threads are released before the region body has run, and eventually the master's wake-up is stolen, which deadlocks.

The old !$omp parallel if(thread_safe) region was inactive for superd, but even an inactive region makes inner teams nested, which is enough to trigger this.

Nothing has been reported to GCC yet.

Testing

Scratch builds on macOS with gcc-16 and MPICH, running test_native_bjacobi.py and test_solver_xml.py with OMP_NUM_THREADS=2 and 1:

SuperLU-DIST build Before After
PETSc 3.24.6 (bundled 9.2.1, OpenMP) nlocal2 superd tests hang 35 passed, 36 skipped (all six test_LU_*nlocal2*[2] pass)
Standalone 9.2.1, OpenMP 4 nlocal2 [2] tests hang (ERRCODE -9) 31 passed, 40 skipped
Standalone 9.3.2, OpenMP 4 nlocal2 [2] tests hang (ERRCODE -9) 31 passed, 40 skipped

Skipped tests use solver packages that were not built. generate_stack.py -l is clean.

Notes for reviewers

  • Thread-safe sub-solvers behave as before: they still run in the parallel region with schedule(dynamic,1).
  • bjprecond_apply was the only if(thread_safe) region found. Any other code path that calls a SuperLU-DIST or MUMPS solve from inside a parallel region could still hit this libgomp bug.

🤖 Generated with Claude Code

…e sub-solvers

bjprecond_apply opened `!$omp parallel if(thread_safe)` around the local
sub-solves. With SuperLU-DIST (or MUMPS) the region is inactive, but it
still makes every OpenMP team created inside the library a nested team.

On targets where libgomp uses its POSIX barrier (eg. macOS), nested teams
that create explicit tasks (SuperLU-DIST pdgstrs2_omp) can leave stray
wake-ups that release the nested-team teardown barrier early. The freed
team is then reused while a worker is still waiting on it, which leads to
early thread release and eventually a deadlock. This caused the
test_LU_*nlocal2*[2] tests to hang with OMP_NUM_THREADS=2 when
SuperLU-DIST is built with OpenMP (eg. via PETSc --with-openmp).

Only open the parallel region when the sub-solver is thread safe. The
per-part loop moves to a contained routine with an orphaned work-sharing
loop so it runs the same either way. No API or input file changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@hansec

hansec commented Nov 18, 2026

Copy link
Copy Markdown
Owner Author

Opened against the upstream repository instead: OpenFUSIONToolkit#450

@hansec hansec closed this Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant