pub fn run_particles<T, N, H, M>(
seed: u64,
n_particles: u64,
chunk_size: u64,
new_tally: N,
history: H,
merge: M,
) -> TExpand description
Run n_particles histories in parallel and return the merged tally.
chunk_sizesets the unit of work and of summation order. It must not be derived from the thread count if bit-identical results across thread counts are wanted. A value of 0 is treated as 1.new_tallymakes an empty tally; one is created per chunk.history(&mut tally, &mut rng, index)simulates particleindexusing the streamstream(seed, index).merge(&mut total, chunk_tally)folds a chunk tally into the total. It is called sequentially in increasing chunk order, starting from an empty tally, so the result is independent of scheduling and thread count.
Chunks run in parallel in consecutive batches of a fixed small multiple of
the worker count; each batch is merged, in chunk order, before the next
begins. At most one batch of chunk tallies (plus the total) is alive at a
time, independent of n_particles. The batch length affects scheduling
only, never the result.
Runs on the current rayon pool (use ThreadPool::install to choose it).
Particle indices are 0..n_particles; run_particles_range continues a
global stream from another first index.