Repository navigation
[INTERNAL,FIX] UniqueIdGenerator: one mutex per draw, exclude zero ids - #10538
timosachsenberg merged 2 commits into
Conversation
Amortize shared Mersenne Twister synchronization across batches of 1024 nonzero IDs. Keep the seeded single-thread sequence, and invalidate caches on every seed reset. Protect refills in builds with and without OpenMP. Consolidate private generator state and cover serial stream compatibility, million-ID parallel generation, persistent-worker reseeding and UUID batch boundaries. Document the changed parallel allocation and idle-worker requirement for reseeding. Related to OpenMS#10520.
There was a problem hiding this comment.
🟢 Approval recommended
The implementation is internally consistent, correctly synchronized under its documented contract, and comprehensively tested.
0 open findings
What changed in this PR
Improves UniqueIdGenerator concurrency and performance while ensuring generated IDs are nonzero.
Changes:
- Adds thread-local buffering with synchronized batch refills and reseed invalidation.
- Expands serial, OpenMP, standard-thread, reseeding, and UUID tests.
- Adds thread linkage, API documentation, and changelog coverage.
| File | Description |
|---|---|
CHANGELOG |
Documents behavior and compatibility changes. |
src/openms/CMakeLists.txt |
Links OpenMS with thread support. |
src/openms/include/OpenMS/CONCEPT/UniqueIdGenerator.h |
Documents buffering and reseeding semantics. |
src/openms/source/CONCEPT/UniqueIdGenerator.cpp |
Implements synchronized batch generation. |
src/tests/class_tests/openms/CMakeLists.txt |
Links generator tests with thread support. |
src/tests/class_tests/openms/source/UniqueIdGenerator_test.cpp |
Adds comprehensive concurrency and sequence tests. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
…stead of buffering per thread The per-thread 1024-id buffer made seeded runs with more than one thread irreproducible: the set of ids drawn in a parallel region, and every id drawn serially after it, depended on thread count and scheduling. For example, ProteomicsLFQ -test produced different consensusXML ids at 2, 4 and 8 threads than at 1 thread. Take the shared mutex on every draw instead. All threads advance the one engine, so for a given seed the ids drawn up to any point are the same set however many threads drew them, as before the buffer was introduced. This still replaces the two OpenMP critical sections per id with a single lock and still protects callers that do not use OpenMP. Removes the buffer, the generation counter, the cache-line alignment and the setSeed() precondition that no other thread may be generating ids. Tests: the multi-threaded sections now assert that the ids drawn by eight OpenMP or standard threads are exactly the first outputs of the seeded engine and that the next id follows them. The batch-boundary and cache-invalidation cases are dropped with the buffer. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Priority: ⬇️ Low Change: Bug fix Merge Risk: ⚪ Minimal · up to Unique ID generation now uses one shared, mutex-protected engine and skips zero IDs. No actionable merge-blocking risk was found. Update the PR description to match the implemented design. Pre-merge checks |
|
|
could be improved if we accept different orders on different threads |
…ProSE) Only CHANGELOG conflicted (both entries kept). The new PeptDeep rescoring works on PeptideIdentification lists, which this branch keeps. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01B51nRFoHvZuVXD7cT8XZav
…oring in ProSE) Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01B51nRFoHvZuVXD7cT8XZav
Description
getUniqueId()currently enters two OpenMP critical sections per draw. This makes bulk generation contend between workers and leaves the shared RNG unprotected in builds without OpenMP.setSeed()uses a different critical section than the draw, so a concurrent reseed races with it.Guard the shared
std::mt19937_64with onestd::mutex, taken on every draw and insetSeed()/getSeed(). Skip zero engine outputs, whichUniqueIdInterfacereserves for an invalid id.Keep the implementation small: one private state object owns the seed, engine and mutex; the engine is stored by value. Remove the old singleton bookkeeping, redundant test buffers and unused includes. There is no new public API or configuration. Add explicit standard-thread linkage, regression coverage and a changelog entry.
An earlier revision of this PR cached 1024 ids per thread. It was faster under contention, but seeded runs with more than one thread stopped being reproducible: the ids drawn in a parallel region, and every id drawn serially after it, depended on thread count and scheduling. For example,
ProteomicsLFQ -testwrote different consensusXML ids at 2, 4 and 8 threads than at 1. The second commit replaces the cache with the per-draw mutex.Related to #10520. This excludes zero and makes generation thread-safe without OpenMP; it does not implement the broader map-ID lifecycle changes in that issue.
Compatibility and tradeoffs
setSeed()may run while other threads draw; each draw comes from either the old or the new seed.Validation
LD_PRELOAD: six CometAdapter output comparisons (forCometAdapter_1, the reference idXML records acalibration_toleranceparameter that this build's output lacks), five ProSE rescoring tests/comparisons (vendored Percolator'sBaseSpline.cpp:236assertion), and one external Percolator output comparison.std::mt19937_64for each of three seeds; 100,000 ids drawn by eight OpenMP workers and by eight standard threads, each asserted to equal the first engine outputs for the seed, with the next id following them; and UUID and integer ids sharing the sequence. The multi-threaded assertions fail against the earlier per-thread cache.TOPP_ProteomicsLFQ_1command wrote byte-identical consensusXML at 1, 2, 4 and 8 threads, and its two reference comparisons passed at each.clang-format --dry-run -Werrorandgit diff --checkpassed.Generator microbenchmark, this implementation versus unchanged develop source, built as a shared library with
-O3 -fPIC -fopenmp, tight loop of 2,000,000 ids per thread, best of three:In a process that has not started another thread, a draw costs 9.2 ns versus 38.5 ns on develop. These are generator timings, not end-to-end workflow speedups.
Checklist
🤖 Generated with Claude Code
Summary by CodeRabbit