Repository navigation
feat(geant4): parallelize in-browser Geant4 simulations across multiple Web Workers (#2526) - #2584
Draft
DariuszRozmus wants to merge 2 commits into
Draft
DariuszRozmus wants to merge 2 commits into
DariuszRozmus wants to merge 2 commits into
Conversation
DariuszRozmus
marked this pull request as draft
December 2, 2026 19:59
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #2526
Parallelizes in-browser Geant4 WebAssembly simulations (demo / local mode) by splitting primary particles across multiple concurrent Web Workers instead of running on a single worker.
Changes
src/services/Geant4MacroHelpers.ts(new):distributePrimaries: evenly divides total primaries acrossKworkers, distributing remainders across the first workers and skipping workers assigned0primaries.generateRandomSeeds/prepareWorkerMacro: injects unique pairs of 32-bit cryptographic seeds (/random/setSeeds <seed1> <seed2>viacrypto.getRandomValues) immediately before each worker's rewritten/run/beamOn <workerPrimaries>command to guarantee statistically independent Monte Carlo streams.mergeGeant4ResultFiles: deterministically merges Geant4 primitive scorer dump files cell-by-cell (total(value),total(val^2),entry) across all workers before parsing.src/services/Geant4LocalWorkerSimulationService.ts:workersfrom a singleGeant4Workerper job toRecord<JobId, Geant4Worker[]>.numPrimariesandprimariesPerWorkerperjobId(removing shared instance state).getJobCombinedState,areAllWorkersCompleted,getJobStartTime,getJobEndTime, multi-taskgetJobTasksStatus, and multi-workercancelJob/markSafeForTermination).hydrateResultsto fetch output files from all workers and merge them viamergeGeant4ResultFilesbefore passing them toGeant4ResultsFileParser.determineWorkerCountdefaulting tomin(navigator.hardwareConcurrency - 1, MAX_LOCAL_GEANT4_WORKERS)withMAX_LOCAL_GEANT4_WORKERS = 3as a safe browser memory cap (since the upstreamgeant4_wasm.wasmbuild currently allocates a fixed-s TOTAL_MEMORY=512MBper worker withoutALLOW_MEMORY_GROWTH, spawning too many workers causesRangeError: Array buffer allocation failed).src/WrapperApp/components/Simulation/RunSimulationForm.tsx:min(hardwareConcurrency - 1, MAX_LOCAL_GEANT4_WORKERS)with helper text indicating the safe worker limit and detected CPU cores.src/services/__tests__/Geant4MacroHelpers.test.ts(new):Verification
npx tsc --noEmit— passed with 0 errorsnpm test -- src/services/__tests__/Geant4 --watchAll=false— 15/15 tests passingCompanion Documentation PRs