Demonstrating mathematical integrity under GPU parallelization and reduced precision.
pip install -r requirements.txt
cd src/cpu
python benchmark.py
Output:
data/energy_drift_comparison.pngcd notebooks
jupyter notebook 01_cpu_benchmark.ipynb
This notebook shows:
mkdir build && cd build
cmake ..
make
Requires CUDA toolkit.
======================================================================
GPU-ACCELERATED SYMPLECTIC INTEGRATOR - CPU BASELINE BENCHMARK
======================================================================
Configuration:
Trajectories: 100
Steps: 10000
Timestep: 0.001
Total time: 10.00
System: Henon-Heiles (chaotic regime)
--- Euler Integrator ---
Time: X.XXXs
Initial Energy: 0.XXXXXX
Final Energy: X.XXXXXX (DIVERGED)
Max Abs Error: X.XXe+XX
Max Rel Error: X.XXe+XX
--- RK4 Integrator ---
Time: X.XXXs
Initial Energy: 0.XXXXXX
Final Energy: 0.XXXXXX
Max Abs Error: X.XXe-XX
Max Rel Error: X.XXe-XX
--- Symplectic Integrator ---
Time: X.XXXs
Initial Energy: 0.XXXXXX
Final Energy: 0.XXXXXX
Max Abs Error: X.XXe-XX (TINY!) ✓
Max Rel Error: X.XXe-XX
The key insight: Symplectic preserves energy while Euler/RK4 fail
In the energy drift plot:
README.md for mathematical backgroundsrc/cpu/integrators.py — understand each methodbenchmark.py — try different initial conditions| File | Purpose |
|---|---|
src/cpu/benchmark.py |
Run CPU benchmark |
src/cpu/integrators.py |
All three integrators |
src/cpu/analysis.py |
Visualization & analysis |
notebooks/01_cpu_benchmark.ipynb |
Interactive analysis |
include/henon_heiles.h |
System definitions |
src/gpu/integrators.cu |
GPU kernels |
CMakeLists.txt |
Build configuration |
python benchmark.py 1000 50000 0.0005
This runs 1000 trajectories for 50,000 steps with smaller timestep.
Modify henon_heiles_gradients() in src/cpu/integrators.py to implement another Hamiltonian.
nvprof ./build/symplectic_gpu_benchmark
Q: Why symplectic integrators?
A: They preserve the mathematical structure (symplectic form) that encodes energy conservation. This survives discretization, unlike naive methods.
Q: Why GPU?
A: Each trajectory is independent → embarrassingly parallel. GPU excels at this pattern. 100x-1000x speedup expected.
Q: What’s special about Hénon-Heiles?
A: It’s chaotic and nonlinear, so errors accumulate fast. A perfect test case for structure preservation.
Q: Can I use this for other systems?
A: Yes! Modify the potential and gradient functions to implement any Hamiltonian.
Ready to dive in? Run python src/cpu/benchmark.py and check data/energy_drift_comparison.png!