Skip to content

[FIX] ProSE: parallelize the calibration scoring pass (OpenMP) - #9639

Merged
timosachsenberg merged 1 commit into
OpenMS:developfrom
timosachsenberg:perf/prose-parallel-calibration
Jun 20, 2026
Merged

timosachsenberg merged 1 commit into
OpenMS:developfrom
timosachsenberg:perf/prose-parallel-calibration

Conversation

@timosachsenberg

@timosachsenberg timosachsenberg commented Jun 20, 2026 •

Copy link
Copy Markdown
Contributor

Problem

The optional mass-recalibration pass (Search:calibration:enabled) scored its spectrum subset in a fully serial loop, while the main search scores in parallel (#pragma omp parallel for). On a many-core machine, the serial 10% subset takes about as long as the entire parallel search — so enabling calibration roughly doubles wall-clock time for no extra useful work.

Measurements

172k MS2 spectra, 20 threads, same binary (only the calibration loop's pragmas differ):

wall total CPU CPU util
base (no calibration) 4:53 (293 s) 4897 s 1682% (~17 cores)
serial calibration (before) 9:21 (561 s, +91%) 5389 s 965% (~9.6 cores)
parallel calibration (this PR) 5:14 (314 s, +7%) 5424 s 1734% (~17 cores)
  • Calibration went from +91% wall to +7% wall (the whole job is 1.79× faster with calibration enabled).
  • Total CPU-seconds are unchanged (5389 vs 5424) — the fix adds no work, it only spreads the same work across cores. The CPU-utilization collapse (965%) is the signature of a serial phase injected into a parallel job.

Fix

Parallelize runCalibrationPass_'s scoring loop the same way as the main loop (scoreSpectraAgainstIndex_):

  • querySpectrum, reconstructModifiedSequence, and the shared TheoreticalSpectrumGenerator::getSpectrum are const, thread-safe methods that the main scoring loop already calls concurrently; HyperScore::computeWithDetail/Math::getPPM are static and pure.
  • Every working variable in the loop body is loop-local.
  • The only cross-thread write (cal_hits.push_back) is guarded by a critical section.

Correctness

Downstream is order-independent (cal_hits is sorted by score; the precursor/fragment error vectors are sorted before quantiles), so the calibrated tolerances do not depend on insertion order. On the benchmark, serial and parallel produce a bit-identical window [-19.22, +19.80], and the ProSEAlgorithm_test calibration sections pass unchanged.

Coverage

All three calibration call sites funnel through runCalibrationPass_, so this fixes the serial bottleneck for:

  • non-chunked single-file
  • chunked single-file
  • chunk-major multi-file

The chunked paths additionally build a strided-sample calibration index via FragmentIndex::build, which is itself OpenMP-parallel and bounded (built once, reused per file) — so it is not a serial bottleneck.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Performance
    • Enhanced calibration processing efficiency through optimized parallel computation techniques.

The optional mass-recalibration pass (Search:calibration:enabled) scored
its spectrum subset in a fully serial loop, while the main search scores
in parallel (#pragma omp parallel for). On a many-core machine the serial
10% subset took about as long as the entire parallel search, so enabling
calibration roughly doubled wall-clock time for no extra useful work.

Measured (172k MS2 spectra, 20 threads, same binary):
  - base (no calibration):      4:53 wall, CPU util ~1682%
  - serial calibration (before): 9:21 wall (+91%), CPU util collapses to ~965%
  - parallel calibration (after): 5:14 wall (+7%),  CPU util ~1734%
Total CPU-seconds are ~unchanged across serial vs parallel (5389 vs 5424) --
the fix adds no extra work, it only spreads the same work across cores. The
CPU-utilization collapse is the signature of a serial phase in a parallel job.

Parallelize runCalibrationPass_'s scoring loop the same way as the main
loop (scoreSpectraAgainstIndex_): querySpectrum and the shared
TheoreticalSpectrumGenerator expose const, thread-safe methods, and every
working variable is loop-local. The only cross-thread write
(cal_hits.push_back) is guarded by a critical section. Downstream is
order-independent (cal_hits is sorted by score; the error vectors are
sorted before quantiles), so the calibrated tolerances are unchanged: the
window is bit-identical (serial and parallel both produce [-19.22, +19.80]
on the benchmark), and ProSEAlgorithm_test calibration sections pass.

Covers all three calibration call sites (non-chunked single-file, chunked
single-file, chunk-major multi-file); they all funnel through
runCalibrationPass_. The chunked paths additionally build a strided-sample
calibration index via FragmentIndex::build, which is itself OpenMP-parallel
and bounded, so it is not a serial bottleneck.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@timosachsenberg
timosachsenberg merged commit e9cbefc into OpenMS:develop Jun 20, 2026
13 checks passed
@coderabbitai

coderabbitai Bot commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a3ede049-cfdd-4306-8d73-66604218727c

📥 Commits

Reviewing files that changed from the base of the PR and between fa9d892 and 9fe88ad.

📒 Files selected for processing (1)
  • src/openms/source/ANALYSIS/ID/ProSEAlgorithm.cpp

📝 Walkthrough

Walkthrough

In ProSEAlgorithm::runCalibrationPass_, the sequential loop over the TIC-selected calibration subset is replaced with an OpenMP parallel for schedule(dynamic) loop using loop-local variables. A named #pragma omp critical (prose_calibration_hits) section serializes concurrent push_back calls into the shared cal_hits vector.

Changes

ProSE Calibration Parallelization

Layer / File(s) Summary
Parallel calibration loop and critical section guard
src/openms/source/ANALYSIS/ID/ProSEAlgorithm.cpp
Sequential iteration over subset_size in runCalibrationPass_ is replaced with #pragma omp parallel for schedule(dynamic) using loop-local working variables; cal_hits.push_back(...) is wrapped in a named omp critical block to prevent concurrent vector corruption. The subsequent sorting and filtering logic on cal_hits is unchanged.

Possibly related issues

Poem

Hop, hop, threads in flight,
Each core computes with might,
But before the vector grows,
A critical section slows—
Then rabbits sort the hits just right! 🐇⚡

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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