Repository navigation
[FEATURE] Biosaur2Algorithm: up to 24x faster, OpenMP-parallel, identical output - #10793
Conversation
…output Removes work and parallelises the independent parts of Biosaur2, keeping the hills and features bit-identical to the sequential implementation at any thread count: - cosineCorrelation_: merge walk over the (strictly increasing) scan lists instead of building two std::maps per candidate pair; same sums, same order - hill_idx lookups as dense vectors instead of std::map/std::set - hills and pattern candidates sorted through index permutations and moved, not copied (std::sort takes the same decisions, so ties keep their order) - hill detection: the per-scan part (filter, intensity sort, m/z and IM bins, dense bin offsets) is prepared in parallel; scan-to-scan linking stays sequential and records peak->hill references; the Hill objects are then built in parallel - processHills_, splitHills_ (fresh hill ids handed out in the original order), the RT and calibration filters and convertToFeatureMap_ (unique ids drawn serially in feature order) run in parallel with ordered concatenation; isotope candidate generation in parallel over chunks of mono hills - the per-peak ion-mobility format lookup is done once per scan - the initial isotope calibration, whose result was discarded (log only), is no longer run - exceptions inside parallel regions are rethrown after the region Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
No actionable comments were generated in the recent review. Walkthrough
Change: Refactor Merge Risk:
|
…the candidate loop charge_ban_map has keys 1-8; look the charge up with find() so higher charges ban nothing, as before. Exceptions in the parallel candidate generation are caught inside the OpenMP region and rethrown after it. Removes an unused variable. Co-Authored-By: Claude Opus 5.5 <[email protected]>
timosachsenberg
left a comment
There was a problem hiding this comment.
AI-generated initial review
This is an automated, AI-generated first review. It looks for high- and medium-priority issues only (no nits) and checks whether the PR has tests and measurements. I read the code at 5d814db against develop (cfc1a09). Please double-check anything before acting on it. A maintainer will follow up.
I could not build OpenMS here: the vcpkg submodule is not initialized and none of the dependencies are installed. Instead, I compiled the hill detection of both versions verbatim against a small mock of the OpenMS types and compared them on synthetic data. That covers linkScanToHills_ and detectHills_ from develop, and prepareScan_, linkScanToHills_ and detectHills_ from this PR. The only change to these functions since c9f22b0 removes an unused variable, so the results below hold for 5d814db.
Verdict: no high-priority issue. The abort with cmax >= 9 that CodeRabbit found is fixed correctly in 5d814db:
- the ban lookup uses
find(), so charges above 8 again ban nothing; - the candidate loop now catches exceptions inside the OpenMP region and rethrows them after it.
One medium issue: the memory held by the 256-scan look-ahead window in detectHills_.
Checked and found sound
- Hill detection, old vs new (harness):
- Result: 96 comparisons (24 synthetic runs × 1/2/4/8 threads), 0 mismatches. Every
Hillfield was compared, plus thehill_mass_diffssequence. In total, 7.3 M hills from 11.2 M linked peaks. - What the runs contain:
- 300–1,000 scans each;
- empty or all-filtered scans on either side of the 256-scan block boundaries;
- equal-intensity neighbours within
htol, in the same m/z bin and in adjacent bins; - out-of-range and below-threshold peaks;
- per-peak IM with
paseftol0.05 and 0; htol3, 8 and 20.
- The harness catches real differences:
- checking bin
fm - 1beforefm: 48/48 runs differ; - dropping the block
carry: 16/48; - disabling the IM gating: 12/48.
- checking bin
- Why this adds something: it covers the ion-mobility linking and the block edges. The three Orbitrap DIA runs in the description test neither.
- Result: 96 comparisons (24 synthetic runs × 1/2/4/8 threads), 0 mismatches. Every
cosineCorrelation_merge walk.- It adds the dot product and
n1in ascending scan order, as themap1loop did, andn2overscans2in ascending order, as themap2loop did. So the sums are bit-identical. - Scan lists that are not strictly increasing still take the old map path.
- It adds the dot product and
orderedParallel_.- Each index writes only into its own chunk, and the chunks are concatenated in order.
- The first exception is rethrown after the region.
processHills_. Makinghillan alias ofprocessed_hillis safe: the function writes only scalar fields and reads only the vectors.splitHills_.- The
FRESHids are numbered serially in output order. That is the sequential numbering. - This also holds when segment 0 is dropped as too short.
- The
- Sorting index permutations.
std::sorttakes the same path on the indices as on the elements, because its control flow depends only on comparison results. So the order is the same, ties included. - Dense lookup tables.
- The dense
hill_idxtables reproduce the maps' last-assignment-wins behaviour. - The isotope ids are bounds-checked in
occupied, and mono ids are always below its size.
- The dense
- Thread safety.
computeAveragine_uses a function-local static, which is initialized thread-safely.MetaInfoRegistryis guarded by a mutex, sosetMetaValuein the parallel feature build is safe.- The two warning log lines in parallel code are inside
criticalsections.
performInitialIsotopeCalibration_. It isconstand its result was already discarded on develop, so dropping the call changes only the log output.
Medium: the look-ahead window keeps a dense m/z-bin table for 257 scans
What happens:
detectHills_preparesblock = 256scans at a time (Biosaur2Algorithm.cpp:1701) and keeps them alive, pluscarry.- Each
ScanPrep::bin_start(:1522) is dense over the scan's m/z-bin range: (max − min m/z) /mz_step+ 1 ints, withmz_step = htol · 1e-6 · max m/z. - So its size depends on
htoland the m/z window, not on how many peaks the scan has. - On IM data,
im_bin_per_peak(:1458) is sized by all peaks of the frame, not only the valid ones, and is also held 257 times. - develop kept only two scans'
std::maplookups alive.
Measured with prepareScan_ verbatim (minmz 350, maxmz 1500):
| peaks/scan | htol |
bin_start per scan |
whole ScanPrep per scan |
257-scan window |
|---|---|---|---|---|
| 5,000 | 8 | 374 KB | 472 KB | 118 MB |
| 5,000 | 3 | 997 KB | 1.1 MB | 275 MB |
| 5,000 | 1 | 3.0 MB | 3.1 MB | 776 MB |
| 20,000 | 8 | 374 KB | 765 KB | 192 MB |
| 20,000 | 1 | 3.0 MB | 3.4 MB | 850 MB |
Peak RSS of hill detection alone, on a synthetic run (1,500 scans, about 7k peaks per scan, htol 8, 4 threads): develop 3,191 MB, this PR 3,372 MB.
Suggested mitigation: size the window by the thread count. The blocks only exist to feed the parallel prepareScan_ step.
#include <OpenMS/SYSTEM/BuildInfo.h>
// detectHills_: enough prepared scans to keep every thread busy; each one holds a dense m/z-bin table
const SignedSize block = static_cast<SignedSize>(std::max<Size>(8, 4 * Internal::OpenMSBuildInfo::getOpenMPMaxNumThreads()));Verified in the harness with a window of 4 × threads:
- identical hills at 1/2/4/8 threads;
- the same speed: 7.3 s / 4.2 s at 1 / 4 threads, vs 7.6 s / 4.0 s with 256 scans;
- peak RSS 3,257 MB.
I also tried replacing bin_start by a binary search over by_bin. The output was identical and the memory scaled with the peaks. But the serial linking became about 40% slower (7.6 s → 10.7 s on 1 thread), so the window size is the better place to fix it.
Tests
- Good:
Biosaur2Algorithm_testand the FeatureFinderLFQ TOPP and INI/CTD tests were run atOMP_NUM_THREADS1 and 4.- The out-of-tree equivalence check hashed all hills and features on three real runs at 1, 16 and 32 threads. That is strong evidence for the non-IM, non-FAIMS path.
- Gap: the in-tree tests do not reach the new parallel structure.
Biosaur2Algorithm_testuses at most 20 scans (10 per FAIMS CV).TOPP_FeatureFinderLFQ_1has 112 MS1 scans and 20 features (-htol 100,-cmin 2 -cmax 2).- So no test crosses a 256-scan block or a 1,024 / 2,048 / 4,096 chunk, and none compares thread counts. The equivalence driver is not committed.
- Gap: there is no regression test for
cmax >= 9, the bug fixed in5d814db. - Suggestion: one
[EXTRA]section inBiosaur2Algorithm_test.- Data: a synthetic run of about 600 scans with a few thousand persistent traces (with isotopes) plus noise.
- Thread counts: run it with
omp_set_num_threads(1)and(4), guarded by_OPENMP. Comparehillsandpeptide_featuresfield by field. - High charge: run it once more with
cmax 10, which must not throw. - Benefit: this pins down the "identical at every thread count" claim for later changes.
- Generator: a generator like the one in my harness would do. It has persistent analytes with gaps, equal-intensity twins within
htol, empty scans around the block edges, and optional per-peak IM.
Measurements
Yes, on real data: three public Orbitrap DIA runs (PXD032263, PXD021394, PXD063917), at 1 and 16 threads, median of 2 runs. The speedups are 5.5–9x on 1 thread and 12–24x on 16 threads. That fits the harness: on synthetic data, hill detection alone went from 26.7 s to 7.6 s (1 thread) and 4.0 s (4 threads).
Missing:
- Peak memory, develop vs PR (
/usr/bin/time -v, max RSS) on one of the three runs. Besides the window above, therefsandorderarrays add 32 B per linked peak while the hills are built (:1688,:1740). - Ion-mobility (timsTOF) input. The IM gating and the per-scan IM lookup are rewritten, and none of the timed runs has IM. My harness covers the equivalence of the IM linking, but not the rest of the pipeline or the runtime. The data of
TOPP_ProteomicsLFQ_DDA_PASEF_biosaur2or any PASEF run would do. - FAIMS input.
- On FAIMS data,
processFAIMSGroup_already runs inside the parallel loop over CVs inrun(). - OpenMS does not enable nested OpenMP there, so the new inner loops run on one thread per CV.
- This is not a bug. But the speedups in the table should not be read as applying to FAIMS data; one FAIMS timing would show what the PR gains there.
- On FAIMS data,
CI: all build-and-test jobs on 5d814db were still queued when I looked. The runs on c9f22b0 were cancelled.
Generated by Claude Code
|
looks good |
timosachsenberg
left a comment
There was a problem hiding this comment.
AI-generated initial review
This is an automated, AI-generated first review. It looks for high- and medium-priority issues only (no nits) and checks whether the PR has tests and measurements. I read the code at 5d814db against its merge base cfc1a09 on develop; develop has not touched Biosaur2 since then, and the PR merges cleanly. Please double-check anything before acting on it. A maintainer will follow up.
I could not build OpenMS here (no vcpkg sources or system dependencies). Instead, I compiled the develop and PR versions of the changed code side by side in a standalone harness, with small stand-ins for MSSpectrum and friends. The harness covers detectHills_ → processHills_ → splitHills_ → detectIsotopePatterns_, i.e. all of run() except the preprocessing and convertToFeatureMap_. I used it to check equivalence on the paths the description does not cover, and to measure memory.
Verdict: no high-priority issue. The output is bit-identical in every configuration I tried, including ion mobility data. I found one medium-priority problem: the per-scan dense bin table raises peak memory, by an amount that grows as 1/htol. There is also a test gap: none of the committed tests reach the new parallel or block paths.
Harness results (develop vs. this PR, g++ 13, -O2 -fopenmp):
- Synthetic LC-MS data:
- 300–1,030 MS1 scans, so the run crosses the 256-scan block boundary up to 4 times;
- 180k–342k peaks and 67k–210k raw hills, so every parallel stage runs several chunks;
- isotope envelopes of charge 1–10;
- with and without per-peak IM and IM gating, with empty scans and with tied intensities.
- Hills (all fields),
hill_mass_diffsand peptide features (all fields, isotopes included) are bit-identical in all 42 combinations of configuration and thread count (1, 4, 16 threads), withcmax6 and 10 andiuse−1, 0 and 1. - The harness is sensitive to tie order: swapping the candidate bin order to
fm - 1, fm, fm + 1makes it report differences. - An IM array shorter than the peak list raises the same
InvalidValuein both versions, with and without IM gating. cosineCorrelation_: the merge walk and the map path agree bitwise on 200,000 random pairs of strictly increasing scan lists.detectHills_alone, 800 scans × 8,000 peaks: develop 21.3 s; this PR 8.8–9.0 s on 1 thread and 2.7–3.0 s on 4 threads. This is in line with the description.
Checked and found sound:
- Linking.
- Candidates are visited in the same order: bins
fm,fm − 1,fm + 1, and within a bin by descending intensity, via the(bin, pos)sort. - The banned set becomes
vector<char>. - An empty scan still resets linking.
assigned_hill < hill_idx_counterequals the old< hills.size().
- Candidates are visited in the same order: bins
- Hill build from
PeakRefs. Same peak order (scan order), first-maximum apex, sums in scan order. IM errors are deferred but still raised for the same scans. processHills_/splitHills_.- Only scalar fields change after the move.
- Fresh ids are handed out serially in the old order.
- Index-permutation sorts and dense lookups.
- The sorts keep the same comparator.
- All hill ids are ≤ max.
- The
iso.hill_idx < occupied.size()guard drops nothing, because isotope ids come from the hill list.
- Thread safety of the parallel bodies.
- They read only shared data.
- The averagine table is a thread-safe function-local static.
setMetaValuegoes through the lock-protectedMetaInfoRegistry.- Unique ids are drawn serially, the debug warnings are in a critical section, and
charge_ban_mapis no longer written (find).
- The removed
performInitialIsotopeCalibration_call wasconstand its result unused. - CI. Linux g++/clang++ and ARM are green. Windows (cl.exe) and macOS were still running when I looked.
Medium: the per-scan dense bin table raises peak memory, scaling as 1/htol
Where: prepareScan_ builds bin_start over the scan's whole m/z-bin range (Biosaur2Algorithm.cpp:1519-1525). detectHills_ keeps 256 prepared scans plus carry alive at once (:1701).
The bin width is htol · 1e-6 · max m/z. So each table has about (scan m/z span / max m/z) · 1e6 / htol ints, however many peaks the scan has. For MS1 at 350–1,650 m/z, that is about 0.8 GB / htol[ppm] for the window, e.g. ~100 MB at the default of 8 ppm. Linking only ever reads the previous scan's table.
Measured peak RSS (synthetic, 1,000 scans × 3,000 peaks, 4 threads, detect + process + split):
| htol | develop | this PR | lazy variant (below) |
|---|---|---|---|
| 8 ppm | 944 MB | 1,023 MB (+79) | 927 MB |
| 3 ppm | 999 MB | 1,222 MB (+223) | 966 MB |
| 1 ppm | 1,516 MB | 2,011 MB (+495) | 1,313 MB |
- Large inputs are not affected. On 2,600 scans × 8,000 peaks, the hills dominate and the PR is below develop (6.30 vs 6.70 GB). So the cost shows on small and medium runs and at low
htol. This matters when several files run per node. - A tiny
htolhas no limit.htolonly has a lower bound of 0. At 0.1 ppm the window would need ~8 GB, where develop needs nothing extra.
Suggested mitigation (tested in the harness):
- Build the dense table in the sequential loop, only for the scan that is about to be
prev, and free it after linking. - This keeps the O(1) lookup. Output stays bit-identical (all 42 combinations), and peak memory is at or below develop (last column).
detectHills_time was within run-to-run noise of the PR on this shared VM.- A binary search on
by_bininstead of the table also restores memory, but it cost ~30 % ofdetectHills_time.
// prepareScan_: keep by_bin sorted, drop the dense-offset block. New helper:
void buildBinOffsets_(ScanPrep& sp) const // no-op if built or empty
{
if (sp.by_bin.empty() || !sp.bin_start.empty()) return;
sp.bin_lo = sp.by_bin.front().first;
const Size range = static_cast<Size>(sp.by_bin.back().first - sp.bin_lo) + 1;
sp.bin_start.assign(range + 1, 0);
for (const auto& e : sp.by_bin) ++sp.bin_start[static_cast<Size>(e.first - sp.bin_lo) + 1];
for (Size k = 0; k < range; ++k) sp.bin_start[k + 1] += sp.bin_start[k];
}
// detectHills_, sequential loop:
ScanPrep* prev = s == b0 ? (have_carry ? &carry : nullptr) : &preps[static_cast<Size>(s - b0 - 1)];
if (prev != nullptr) buildBinOffsets_(*prev); // only the scan being linked to needs its table
linkScanToHills_(..., prev, ...);
if (prev != nullptr) vector<int>().swap(prev->bin_start);Reusing one buffer across scans would also avoid the per-scan allocation.
Tests
-
Good: the existing class tests and
TOPP_FeatureFinderLFQ_1(+_out1) pass in CI. The description also reports an equivalence check on three real runs at 1, 16 and 32 threads. -
Gap: no committed test reaches the new code paths.
TOPP_FeatureFinderLFQ_1has 112 spectra and 3,084 peaks. It never crosses the 256-scan block (carry) and never produces more than one chunk inorderedParallel_or the candidate loop (1,024–4,096 items per chunk).- No class test uses per-peak IM.
TOPP_ProteomicsLFQ_DDA_PASEF_biosaur2only runs when Sage is found, and it checks no output.- Nothing runs
cmax≥ 9, so the fix in 5d814db is not covered. - The equivalence driver is not committed, so a later change that breaks ordering would go unnoticed.
-
Suggested test: an
[EXTRA]section inBiosaur2Algorithm_test.cppwith a syntheticMSExperiment:- about 600 MS1 scans, ~1,500 envelopes with charges 1–10, plus noise peaks;
- one variant with an
ION_MOBILITYfloat array andsetIMFormat(IMFormat::IM_PEAK); cmax= 10.
Run
run(fm, hills, features)withomp_set_num_threads(1)and(4)(inside#ifdef _OPENMP). Require identical hills (scan and peak indices,hill_idx,mz_weighted_mean) and identical features. To also pin today's behaviour, add the feature count, or a reference featureXML generated on develop.
Measurements
Yes, on real data:
- three public Orbitrap DIA runs at 1 and 16 threads, with the develop baseline;
- equivalence hashes at 1, 16 and 32 threads.
Missing:
- Peak memory. The description reports runtime only; see the finding above. Please add max RSS for develop vs. this PR on one of the three runs.
/usr/bin/time -varoundFeatureFinderLFQis enough. - timsTOF (IM_PEAK) and FAIMS data. Both code paths changed, but neither was timed or hash-checked on real data. My harness covers IM equivalence only synthetically.
- On FAIMS input,
processFAIMSGroup_already runs inside the per-CVomp parallel forinrun(). With default OpenMP settings, the new inner regions are nested and run single-threaded. So FAIMS runs get the serial gains, but no extra parallelism beyond the number of CVs. - One timsTOF run and one FAIMS run, before and after, would confirm both the identity and the expected speedup.
- On FAIMS input,
Generated by Claude Code
| // dense offsets: bin b's entries are by_bin[bin_start[b - bin_lo] .. bin_start[b - bin_lo + 1]) | ||
| sp.bin_lo = sp.by_bin.front().first; | ||
| const Size range = static_cast<Size>(sp.by_bin.back().first - sp.bin_lo) + 1; | ||
| sp.bin_start.assign(range + 1, 0); |
There was a problem hiding this comment.
Medium: this dense offset table spans the scan's whole m/z-bin range. That is about (scan m/z span / max m/z) · 1e6 / htol ints per scan, however many peaks the scan has. detectHills_ keeps 256 + 1 prepared scans alive (:1701), so for MS1 at 350–1,650 m/z the window costs about 0.8 GB / htol[ppm].
In my harness (1,000 scans × 3,000 peaks), peak RSS over develop was:
- +79 MB at 8 ppm;
- +223 MB at 3 ppm;
- +495 MB at 1 ppm.
For a tiny htol, the cost is unbounded: htol only has a lower bound of 0.
Linking only ever reads the previous scan's table. Building the table in the sequential loop just before its scan becomes prev, and freeing it after linking:
- keeps the O(1) lookup;
- gives bit-identical output;
- brings memory back to develop's level.
The review body has the numbers and a sketch.
Generated by Claude Code
…for single-CV FAIMS, thread-equivalence test - The dense m/z-bin table (~1e6 / htol entries per scan) was kept for all 257 prepared scans. It is now built in one reused buffer for the scan being linked to; peak memory is below develop's. - FAIMS input with one CV ran the per-CV loop as a parallel region with one iteration, so the new inner parallel loops ran nested, i.e. serially. The CV loop is parallel only with more than one CV. - Biosaur2Algorithm_test: a synthetic 600-scan run (charges 1-10, gaps, empty scans, equal-intensity twins, noise), with and without per-peak ion mobility, cmax 10; hills and features must be identical at 1 and 4 threads. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ation and the unreachable map path of cosineCorrelation_; one helper each for the OpenMP exception capture and the hill-id table Co-Authored-By: Claude Opus 5.5 <[email protected]>
…s stay inside), feature maps built after the CV loop in CV order, IM bins only with per-peak IM; test: a two-CV FAIMS variant Co-Authored-By: Claude Opus 5.5 <[email protected]>
…per peak); a sub-ppm htol binary-searches the scan's sorted bins instead Co-Authored-By: Claude Opus 5.5 <[email protected]>
… parallel conversion (registry order independent of threads); header documents the sparse-bin fallback; test draws its noise peaks in a fixed order Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks for both reviews. Both findings and the test and measurement gaps are addressed in Memory of the dense m/z-bin table (both reviews, medium). Fixed along the lines of the second review's lazy variant: the dense table now exists only for the scan being linked to, in one reused buffer, and is freed after linking. It is also capped at 1 M bins (or 16 per peak); a sub-ppm Peak memory, develop vs PR. Measured on all six public runs (table in the description). The PR is at or below develop everywhere except +3 % on the one-CV FAIMS run (0.65 vs 0.67 GB). timsTOF and FAIMS.
Tests. Also in these commits: the unused initial isotope calibration and the unreachable map path of |
|
No correctness bugs found. The "identical output" argument holds everywhere I could check, and the rewrite handles the places where this kind of change usually goes wrong. The suggestions below are about speed and memory still left on the table, and about tests that cover less than the description says. What I verified
1. Don't build the hills that
Building only hills with at least for (Size sc = 0; sc < exp.size(); ++sc) // scan_has_peaks recorded during linking
if (scan_err[sc] && scan_has_peaks[sc]) std::rethrow_exception(scan_err[sc]);
vector<Size> keep;
for (Size h = 0; h < hill_idx_counter; ++h)
if (start[h + 1] - start[h] >= min_length) keep.push_back(h);
hills.resize(keep.size());
parallelFor_(0, static_cast<SignedSize>(keep.size()), 4096, [&](SignedSize k)
{
const Size hs = keep[static_cast<Size>(k)];
Hill& hill = hills[static_cast<Size>(k)];
hill.hill_idx = hs;
// ... fill from refs[order[start[hs] .. start[hs + 1])] as now
});2. FAIMS runs with several CVs leave most cores idle The 4-CV run goes from 19.8 s to only 11.8 s at 16 threads, which suggests one CV group dominates and runs on a single thread. The larger runs gain 3–4.3× from the inner loops, so processing the CVs one after another with full inner parallelism could plausibly reach ~5–7 s. Worth benchmarking, e.g. going sequential when there are few groups relative to the thread count. Separately, with nested parallelism enabled ( 3. Two cheap memory fixes in touched code
Tests
Nits
|
|
Thanks for the post-merge review and the independent checks. I'll take all of it up in one follow-up PR:
|
…ding, tests) (#10835) * Biosaur2Algorithm: follow-up to #10793 (memory, FAIMS threading, tests) - detectHills_ builds only hills with at least min_length peaks; IM errors are checked first in scan order; calibration builds no hills - FAIMS: nested per-CV regions share the thread budget - splitHills_ and the FAIMS merge move instead of copying arrays - tests: htol 0.5 case, fingerprint of develop output, FAIMS feature maps at 1/2/4 threads with a fixed UniqueIdGenerator seed - nits: lowest-index rethrow in parallelFor_, static charge_ban_map, 'part' naming, redundant reserve calls removed Co-Authored-By: Claude Opus 5.5 <[email protected]> * Biosaur2Algorithm: no process-wide thread count in the FAIMS loop; fingerprint test within 0.5 % - The FAIMS CV loop no longer calls omp_set_num_threads() on its workers: on MSVC's vcomp the call sets the number for the whole process and nothing set it back, so the rest of the process ran on threads / n_CVs. The inner loops run serially as nested regions by default, so the sizing gained nothing. - The test checks that run() leaves the caller's omp_get_max_threads() as it was (4 threads; 2 threads with the FAIMS CVs in parallel). - develop's fingerprint is compared within 0.5 % instead of exactly: clang/ libomp, macOS and MSVC differ from Linux g++ by a hill or a feature and up to 0.05 % in the sums (last-bit differences of std::exp/FMA flip threshold decisions on the synthetic data). The thread-count equality stays exact. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0149aXmY7heshmULGihPVydG --------- Co-authored-by: Oliver <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
Summary
Makes
Biosaur2Algorithm3–9x faster on one thread and 4–27x faster on 16 threads; on a diaPASEF run with per-peak ion mobility it takes 117 s, where develop did not finish in 3 h. The hills and peptide features are bit-identical to develop at every thread count, and peak memory is lower than or equal to develop's, except +3 % on the one-CV FAIMS run. One deliberate difference: with several FAIMS CVs, the FeatureMap's unique ids are now drawn in CV order (develop drew them in completion order, which varied with the thread count).run()on public data, develop (cfc1a09) vs this PR. AMD EPYC 7543, threads pinned to cores, one run each. The hills and features (all fields) hash identically wherever develop finished:Changes
Less work:
cosineCorrelation_: a merge walk over the two scan lists replaces the twostd::maps built per candidate pair. Hill scan lists are strictly increasing (one peak per scan, in scan order; a debug precondition checks it), so the walk visits the same pairs in the same order and gives the same sums.hill_idxlookups (the occupied set and the hill lookups in the final selection and inconvertToFeatureMap_) use dense vectors instead ofstd::map/std::set.std::sortwith a user comparator decides only on comparison results (libstdc++, libc++, MS STL), so sorting the indices gives the same permutation as sorting the objects, ties included; verified on GCC by the hashes below.processHills_andsplitHills_take the hills by value and move them.performInitialIsotopeCalibration_is removed. Its result was discarded, so it only produced log lines.Parallel (OpenMP), with order-preserving concatenation (
orderedParallel_):Hillobjects are then built in parallel. The dense m/z-bin table that linking reads exists only for the scan being linked to (one reused buffer) and is capped at 1 M bins (or 16 per peak); a sub-ppmhtolthat would need more makes linking binary-search the scan's sorted bin list instead, with the same candidates.processHills_andsplitHills_run in parallel. New hill ids for split segments are still assigned serially, in the original order.convertToFeatureMap_run in parallel; unique ids are still drawn serially in feature order.parallelFor_), including the per-CV FAIMS loop, which develop left unguarded. The two consistency-warning log lines are in acriticalsection.Header: new private types
ScanPrepandPeakRef. The private methodslinkScanToHills_,processHills_andsplitHills_have new signatures, the private filter methods take astd::vector<Size>instead of astd::map<Size, Size>, andperformInitialIsotopeCalibration_is gone. The public API is unchanged.Limits: scan-to-scan linking and the greedy final selection stay serial and dominate beyond about 16 threads. With several FAIMS CVs the parallelism is over the CVs (as on develop); the new inner loops then run serially inside each CV.
Testing
Biosaur2Algorithm_testhas a new[EXTRA]section: a synthetic 600-scan run (crosses the 256-scan block and several parallel chunks; charges 1–10 withcmax10; gaps, empty scans, equal-intensity twins withinhtol, noise), plain, with per-peak ion mobility, and with two FAIMS CVs. Hills and features must be identical at 1 and 4 threads (with OpenMP), and features of charge ≥ 9 must be found.Biosaur2Algorithm_test,TOPP_FeatureFinderLFQ_1(+_out1) and the FeatureFinderLFQ INI/CTD tests pass atOMP_NUM_THREADS1 and 4 (Linux, GCC 13.3,-DWITH_THERMO_RAW=OFF).run()with develop and with this PR, hashing every hill (id, scan/peak indices, m/z, intensities, RT, IM and apex fields) and every feature (all fields, isotopes included). Identical at 1 and 16 threads.🤖 Generated with Claude Code
Summary by CodeRabbit