← Back to Pull requests

Raise an error when OpenMP starts fewer threads than ParallelFor2d needs #12854

Closed
unknown closed this pull request without merging on Nov 17, 2026 20:43 UTC
View on GitHub
unknown unknown commented on Nov 15, 2026 04:32 UTC
Author

Fixes #12853.

OpenMPExecutor::Execute2d splits the blocks into one chunk per requested thread, and each thread runs the chunk of its omp_get_thread_num(). OpenMP can start a num_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. In hist training that loses rows in CommonRowPartitioner::UpdatePosition: training stops with Check 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 existing OMPException path:

OpenMP started 3 of the 32 requested threads. The work is split by the requested count, so a smaller team would skip part of it. OMP_DYNAMIC=true, a thread limit or a nested parallel region can cause this; turn them off, or set nthread=1.

Every call site passes ctx->Threads(), which MaxNumWorkers caps at the thread limit and at 1 inside a parallel region, so from XGBoost's own calls only OMP_DYNAMIC or a runtime cap it can't see (such as libomp's KMP_DEVICE_THREAD_LIMIT) can still trigger the error. MaxNumWorkers now also returns 1 when OMP_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.FewerThreadsThanRequested calls ParallelFor2d with four threads inside an outer region with nesting off and expects the error, with no block run. GetNumThreads.NoActiveLevels checks the serial fallback with OMP_MAX_ACTIVE_LEVELS=0. ParallelFor2d.Coverage skips 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 with USE_OPENMP=OFF and USE_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.

Diff: 275 lines (+206 / -69) across 3 files Reviewer: trivialfis Review duration: 3851m
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
0.40
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
0.17
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
56%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
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
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 56.8% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 39.6% (MEDIUM) · Higher = larger blast radius
39.6%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 56.8% · Lower = rushed or shallow review
56.8%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 17.1% · Safe to merge
17.1%
Repository