Raise an error when OpenMP starts fewer threads than ParallelFor2d needs #12854
All Vouch review confidence checks passed
Residual risk 0.17 = Change Risk (0.40) × (1 − Review Confidence (0.57)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.40 · 275 lines diff across 3 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.336
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #12854"
general
weight: 0.35
trivialfis
Fixes #12853.
OpenMPExecutor::Execute2dsplits the blocks into one chunk per requested thread, and each thread runs the chunk of itsomp_get_thread_num(). OpenMP can start anum_threads(n)region with fewer threads (OMP_DYNAMIC=true, a thread limit, a nested region with nesting off), and then the remaining chunks never run. Inhisttraining that loses rows inCommonRowPartitioner::UpdatePosition: training stops withCheck failed: n_left + n_right == e.Size()or segfaults.As suggested in review, this PR doesn't try to support a smaller team. Each thread checks
omp_get_num_threads()inside the region; if it differs from the requested count, no chunk runs and thread 0 raises through the existingOMPExceptionpath:Every call site passes
ctx->Threads(), whichMaxNumWorkerscaps at the thread limit and at 1 inside a parallel region, so from XGBoost's own calls onlyOMP_DYNAMICor a runtime cap it can't see (such as libomp'sKMP_DEVICE_THREAD_LIMIT) can still trigger the error.MaxNumWorkersnow also returns 1 whenOMP_MAX_ACTIVE_LEVELS=0, where every region gets one thread, so training runs serially there instead of raising. With a full team nothing changes.Tests:
ParallelFor2d.FewerThreadsThanRequestedcallsParallelFor2dwith four threads inside an outer region with nesting off and expects the error, with no block run.GetNumThreads.NoActiveLevelschecks the serial fallback withOMP_MAX_ACTIVE_LEVELS=0.ParallelFor2d.Coverageskips instead of failing when the runtime can't start a full team, and fails if the error appears with a full team. All CPU gtests pass with clang and LLVM libomp and with GCC 16 and libgomp on macOS (817 tests each); the threading tests also pass withUSE_OPENMP=OFFandUSE_THREADPOOL=ON.Risk: low; only runs that used to skip blocks change, and they now stop with a clear message. Revert:
src/common/openmp_exec.h.Authored by AI, reviewed by a Human.