Expand description
Deterministic per-particle random streams and a parallel driver.
Every particle history draws from its own stream, keyed on
(run seed, particle index). The generator is ChaCha8 (the rand_chacha
crate, MIT OR Apache-2.0): a counter-based design in which the stream
identifier is part of the cipher state, so streams for different indices
are distinct keystreams by construction, not segments of one sequence
spaced apart. Counter-based generators for parallel Monte Carlo are
described in J. K. Salmon, M. A. Moraes, R. O. Dror, D. E. Shaw, “Parallel
random numbers: as easy as 1, 2, 3”, Proc. SC’11 (2011); ChaCha is
D. J. Bernstein, “ChaCha, a variant of Salsa20” (2008), here with 8 rounds.
The parallel driver run_particles fixes the floating-point summation
order independent of the thread count: particles are split into chunks of a
caller-chosen, thread-independent size, each chunk gets its own tally, and
the chunk tallies are merged in chunk-index order. The determinism test is
lindhard/tests/determinism.rs. Chunks are evaluated in consecutive
batches of a few chunks per worker and each batch is merged before the next
starts, so the number of partial tallies held at once is bounded by the
pool size, not by the history count; batching never changes a chunk, a
stream or the merge order.
Functions§
- run_
particles - Run
n_particleshistories in parallel and return the merged tally. - run_
particles_ range run_particlesfor the global particle indicesfirst_index..first_index + n_particles: particlefirst_index + kuses the streamstream(seed, first_index + k)and is passed that index.- stream
- Random stream for particle
indexof the run with the givenseed. - uniform
- Uniform draw on
[0, 1)with 53 random bits: the top 53 bits of onenext_u64(), scaled by the exact power of two2^-53.
Type Aliases§
- Particle
Rng - The generator type returned by
stream.