Update OverlayTiming to support BIB random mixing - #413
Conversation
|
The downstream build failure doesn't seem related to the changes - but I can't retrigger it. |
|
Hi! I tried this implementation, and if I simply set |
|
Hello! while testing the implementation, I think I might have an idea why only one background file was being used across the bunch train.
fileIndices[0]And I guess this means that the same randomly selected background file is reused for all BXs of the signal event. I tried adding a counter outside the BX loop: size_t fileCursor = 0;and changing the file selection to: const int fileIndex =
m_randomMix ? fileIndices[fileCursor++ % fileIndices.size()] : 0;With this change, the code continues through the shuffled list instead of starting again from the first file for every BX. I rebuilt and tested this with 120 IPC background files and the overlay completed successfully, the different events showed different background patterns. |
|
Thanks for the checks @andread3vita and the suggestion for a fix @ArinaPon. |
…Core into add_overlay_BIB_random_mix
| With many large background files the algorithm is dominated by reading and | ||
| decompressing them. Set `OverlayThreads` to a value greater than 1 to read and | ||
| decompress the background files of a single event on several threads: |
There was a problem hiding this comment.
Conceptually this might interfere with Gaudis internal scheduling (even if we also use tbb to do our multithreading). It's unclear to me whether the Gaudi internal tbb bits communicate with the tbb bits here.
There is precedent for doing this though as the CKF in k4ActsTracking also does some internal multithreading. This might need some policy discussion as it could imply different usage patterns for different community (e.g. run the general chain on a single thread but branch out to multi-threading in dedicated algorithms vs. running the full chain on multiple threads with Gaudi scheduling but no algorithm-internal multi-threading).
There was a problem hiding this comment.
Indeed. In the ideal world you might want to allow users to do a combination of both, if possible.
For now, especially in colliders that are computationally challenging per event, being able to use MT inside the same event is much more important than multi-threading over events, which can be done trivially in batch jobs anyway.
There was a problem hiding this comment.
Maybe @jmcarcell knows if functional algorithms can already propagate that to the Gaudi scheduler somehow. Otherwise the potential interplay will for now just be another thing to document.
There was a problem hiding this comment.
With the help of Claude, I had a look at the Gaudi sources. My understanding is that there's no way for a functional algorithm to declare or hand its internal parallelism to the scheduler. But the two TBB layers aren't independent either.
The good news is we can't oversubscribe the machine; the bad news is the scheduler counts algorithms in flight, not threads, so it keeps dispatching while we're fanned out and conversely with ThreadPoolSize=1 the pipeline only gets ~2 threads regardless of OverlayThreads (ntokens bounds in-flight items, not concurrency).
One thing I've added as a precaution: the pipeline now runs inside tbb::this_task_arena::isolate(). The reasoning is that while the calling thread blocks in parallel_pipeline, TBB may steal another AlgTask onto it, and AlgTask::operator() sets the thread-local EventContext and calls whiteboard()->selectStore(slot) without restoring either. While I haven't observed this, it costs nothing, so I'd rather keep it than rely on arena timing.
I've documented the OverlayThreads / ThreadPoolSize interplay in doc/OverlayTiming.md: they draw from one pool, OverlayThreads > 1 pays off when ThreadPoolSize is small, and raising both just repartitions the same threads.
BEGINRELEASENOTES
OverlayTimingwith random background-file mixing: the newRandomMixBackgroundFilesoption treats each file in a background group as an independent event source and picks a random set of files for every overlaid event.BackgroundFileNamesentries may now be directories (their.rootfiles are used).MergeMCParticlesoption toOverlayTiming(defaulttrue); whenfalse, background MCParticles are not stored, tracker hits keep the momentum of their originating particle and calorimeter contributions get an empty particle.OverlayTimingis safe to run with intra-event multithreading.ENDRELEASENOTES
This PR updates OverlayTiming with the logic used by the muon collider software to overlay the BIB pseudo-events (from https://github.com/MuonColliderSoft/k4Reco/blob/main/k4Reco/Overlay/components/OverlayTimingRandomMix.cpp).
I opted for porting the changes over rather than asking to include a second algorithm, since the code was 95% the same.
The updated algorithm uses TBB for intra-event multithreading in processing the thousands of inputs for the overlay.