nilsberglund-orleans / YouTube-simulations

Code for simulations on YouTube
Creative Commons Zero v1.0 Universal
594 stars 39 forks source link

Remove copy from phi_in to psi_out in evolve_wave_half #5

Closed JulianKauth closed 1 year ago

JulianKauth commented 1 year ago

Hello Nils,

I am generating a high res version of 2022-01-07 (Noise reflecting panels) as a desktop background image and noticed a possible improvement to wave_billiard.c: Every iteration of evolve_wave_half the phi_in is copied to psi_out. Instead of copying value by value, we can redesign how we use our pointers and instead of copying everything we can simply swap pointers afterwards. The way I did it the evolve_wave_half now is basically an evolve_wave_third, but that is mainly because I don't know how to reassign pointers in C. Feel free to modify the code to make evolve_wave involve two evolve_wave_half instead of three again.

I don't know how to do proper performance tests, but in my rust copy of your project this lead to a ~10% performance improvement.

nilsberglund-orleans commented 1 year ago

Hi Julian,

Thanks a lot, that looks very clever indeed. One should keep in mind that the constant NVID should be multiplied by 2/3 for the new version to produce the same result as the old one. I will run some tests before accepting the pull request.

Best, Nils