9.12 Thread-count determinism
Thread-count invariance requires more than deterministic random numbers. nlmx combines:
- streams keyed by seed and work-unit label;
- ordered result collection;
- deterministic per-unit algorithms;
- aggregation designs that avoid schedule-dependent shared mutation.
The Chapter 9 experiment ran the same 400-subject, 16-subproblem simulation with 1, 2 and 4 threads. analytic_sim.csv and analytic_subjects.csv had identical SHA-256 hashes for all three runs.
Figure 9.5. Stable scientific CSVs were compared for identity; commands, thread messages, elapsed time and log filenames were expected to differ. The comparison set determines what the claim means.
What was not identical
Logs contain different commands, active-thread messages, elapsed times and random log filenames. Settings-used files record different thread counts. Summary/report metadata can include threads. These expected differences do not contradict identical scientific data.
Floating-point reductions
Parallel summation can change rounding if association order changes. Current code often collects ordered per-subject results and reduces deterministically, but each new parallel reduction must be reviewed. A thread-invariance regression suite should compare final bytes/values rather than infer safety from use of Rayon.
Stochastic identity
If a stream were consumed from one shared RNG protected by a lock, results could still depend on which worker acquired it first. Labelled independent streams eliminate that scheduling dependency. Adding a new random draw within one work unit can still change subsequent draws in that unit, so algorithm changes require validation/versioning.
Common mistakes
- Comparing whole output directories including logs.
- Assuming Rayon automatically guarantees deterministic reductions.
- Sharing one sequential RNG across workers.
Checklist
- Compare stable file hashes across thread counts.
- Audit every aggregation order.
- Preserve expected metadata differences separately.
Further reading
See stream derivation, parallel architecture and the worked experiment.