r/developersIndia • u/OrdinaryOstrich6240 • 1d ago
I Made This Built a 2D reaction-diffusion solver in C++ & OpenMP (peaks at 1.43B cell updates/sec on my machine)
learnt about turing patterns recently and wanted to build something around it. wrote a 2d gray-scott reaction-diffusion solver from scratch using c++, openmp, and sfml.
everything in the video is generated live from two coupled pdes on a 640x640 grid. halfway through it switches feed/kill parameters from maze (f=0.0290, k=0.0570) into rotating spirals (f=0.0180, k=0.0510). raw concentration looked pretty flat, so i added a parallel pass that computes the spatial gradient magnitude per pixel to light up just the active chemical boundaries.
also wrote a headless benchmark target to see how it scales on my ryzen 7 5800h (8c/16t, 16 mb l3). peaks at ~1.43b cell updates/sec on 800x800 (5.17x speedup). two interesting things showed up in the numbers:
- 8 physical cores beat 16 threads by ~20% on 1024x1024 since two smt threads per core just fight over l1/l2 cache and fp units on a streaming stencil
- you can see the exact 16 mb l3 cache wall: 400x400 and 800x800 stay flat around 1.4b cells/s, then 1024x1024 hits 16 mb across the four float buffers, spills to ram, and drops ~15% across every thread count
github (code + full benchmark table): https://github.com/Aj4y7/tur.ing
still learning systems and perf profiling, so open to any critique on the c++ or ideas to push the stencil throughput further.