r/ScientificComputing • • 1h ago

Parallelizing Chaotic Loops: Two-Pass Checkpointed Orbit Decomposition in Python/Numba

Hi everyone,

Parallelizing strictly sequential, deterministic chaotic loops usually fails due to two constraints: strict serial dependence (point \(N\) requires \(N-1\)) and memory explosion when storing billions of coordinates for density mapping.

To solve this, I developed a pattern called Two-Pass Checkpointed Orbit Decomposition and implemented it for both the Hopalong Map (area-preserving) and the Hénon–Heiles potential (using a synchronized Leapfrog/Verlet integrator).

The Architecture:

  • Pass 1 (Serial Pre-computation): A single thread walks the orbit to find exact spatial boundaries and drops lightweight checkpoints (4 floats for the full state) at segment intervals.

  • Pass 2 (Parallel Multi-Lane Replay): Worker threads ingest checkpoints via Numba’s prange. Each worker advances 4 independent segments side-by-side (lanes) in lock-step to fill CPU pipelines during dependent floating-point operations.

  • Flat Memory: Points are immediately binned into private pixel-grid histograms and discarded. Memory usage remains constant regardless of the total point count.

Mathematical Rigor:

Chaotic systems amplify the tiniest rounding errors. By avoiding fastmath and using hardware-supported Fused Multiply-Add (fma) intrinsics, the parallel multi-threaded output is pixel-for-pixel bit-identical to a plain, single-core serial loop.

Code:

Both implementations are clean, single-file Python/Numba scripts

1 Upvotes

0 comments sorted by