9.11 Parallel execution architecture
nlmx uses Rayon for data-parallel work. configure_threads attempts to build the global Rayon pool with the requested positive thread count; without an explicit value, Rayon uses its environment/default core selection. The log records the active pool size.
Parallel work units
Commands parallelize independent units where practical:
- subjects during likelihood, simulation and NCA;
- replicate simulations or bootstrap units;
- model candidates whose dependencies are complete;
- plot generation and other independent outputs.
Parallel nesting is constrained by one global pool rather than creating an unbounded pool at each layer. The useful concurrency depends on the number and cost of available work units.
Ordered collection
Parallel iterators are commonly collected into indexed vectors, preserving logical order even when workers finish out of order. Random streams are labelled by scientific identity, not worker. These two design choices support identical outputs across thread counts.
Pool configuration boundary
Rayon's global pool can normally be initialized only once per process. Commands are ordinarily one process/one command, so this is appropriate. Embedded or test contexts that invoke multiple commands in one process must understand that a later pool-size request may not rebuild the pool; warnings/logs determine the actual count.
Memory
More threads can increase simultaneous subject states, replicate buffers and output intermediates. Memory bandwidth, cache contention and serial output can dominate before all CPU cores are useful.
Common mistakes
- Equating requested threads with active parallel work.
- Assuming nested loops multiply thread counts.
- Ignoring memory and serial phases in capacity planning.
Checklist
- Record requested and logged active threads.
- Identify the command's parallel work unit.
- Measure peak memory as well as elapsed time.
Further reading
See thread determinism, scaling measurement and the command-specific chapters.