logoalt Hacker News

rnhmjoj11/08/20241 replyview on HN

Rewriting the old Fortran code in C will probably make it slower with new bugs. A smarter thing to do when picking up terrible code written by physicists is to document everything you can, write tests and then start refactoring bit by bit using modern Fortran features (yes, the latest standard is 2023).

Fortran compilers had more than 40 years to become pretty good at generating efficient code; they can make assumptions that are not possible in C (for example, no aliasing) to do so. Besides, most compilers already can do vectorization and autoparallelisation with multithreading, coarrays, and/or openMP, which can be offloaded to a GPU.


Replies

nightowl_games11/08/2024

> Rewriting the old Fortran code in C will probably make it slower with new bugs.

Then it's not done yet.