8 ms·
There is sadly a huge amount of Fortran code bases in science. Not old. Not left over libraries. Not software written for a bygone age. No... New software. Hug
by gravypod 10y ago
There is sadly a huge amount of Fortran code bases in science. Not old. Not left over libraries. Not software written for a bygone age.
No... New software. Huge, mission critical, core project, software.
The best part: No documentation, no maintainer, and no migration plan.
Scientists think in terms of how Units of Science per Units of Work. Translating code, learning new languages, testing, checking correctness, software validation, bug testing, or even just using external (non-science) libraries yield a very low science/work ratio.
Just opening a text editor, writing a language you already know, and calling it "good enough" is high science/work.
Their method of software validation usually boils down to "spit out your data, graph it, and see if it looks like what you expect".
There's also this notion that "Fortran is fast" that MANY people hold for some reason. They don't know about what kinds of modern compiler optimizations they're missing out on and what new IPC frameworks are available. They know Fortran is fast, MPI is parallel, and that's what they use.
Right now I'm looking at a codebase that is actively being developed and is written in Fortran. It's about 48,466 lines in total. The source is about 2.3M in size. No one seems to have formula listings for it. I want to rewrite it but pulling apart fortran is very difficult.
It's very scary that if I were to write the software in C that it would be seen as modern! This software is tax-payer funded and included in real time systems and production software.
(On that note if anyone is good at Fortran and can document the formulas in this software so I can rewrite them I'd be happy! Please email me)
- DHermit 10y agoWhat makes you think that Fortran is not a modern language? And when writing scientific code which involves multidimensional matrices, Fortran is most of the time more readable than C, because you can do array slicing, use elemental functions over an array (like simply doing sin(a) where a is an array). Your whole post is just complaining about Fortran still beeing used, but you don't really explain why. The only point I can find is > The best part: No documentation, no maintainer, and no migration plan. which is in no way language specific. Have you looked at modern Fortran? You have object orientation, polymophism and even parallel features like coarrays (I have to admit that I never really used them, because the gcc support is somehow incomplete).
- goalieca 10y agoI used to think academic code was a hack fest. Then I entered industry. I would not be so quick to shit on scientists. They may not be language gurus writing with the latest idioms and toolkits but there is a lot of carefully analyzed and "correct" software.
- qb45 10y ago> There's also this notion that "Fortran is fast" that MANY people hold for some reason. They don't know about what kinds of modern compiler optimizations they're missing out on and what new IPC frameworks are available. Fortran is fast and has no reason to be worse than C. In fact, it may be easier to write compiler-friendly code in F thanks to "restrict by default". And are there really HPC-grade C compilers with whatever "modern optimizations" that don't come with a Fortran frontend? Don't think so. BTW, I have seen an attempt to rewrite a few dozen KLOC Fortran project to C and it wasn't pretty. The code was still a bunch of for loops crunching through a bunch of arrays, just in a different language, and then it had some new bugs that were introduced in translation and also it produced slightly different results because of different language rules, compiler and optimizations translating the same math formulas to different machine code. And the formulas were written to produce expected output when compiled with, you guessed it, Fortran. Don't get me wrong, the old-school Fortran with 3-letter variable names, 72 character columns, GOTOs and stuff sucks donkey balls. But you don't have to write like that - while I'm no real Fortran expert (sorry), I've heard that modern standards of Fortran are vastly better and look much closer to C. I would certainly research this before rewriting everything in C.
- jay-anderson 10y agoAlso, there are optimizations that can be done with fortran that are more difficult or cannot be done with C (see https://en.wikipedia.org/wiki/Pointer_aliasing https://en.wikipedia.org/wiki/Pointer_aliasing).
- qb45 10y agoThat's what I meant by "restrict by default". You can get Fortran-like semantics in C by marking function arguments with the restrict keyword, at the cost of some manual labor (and possibly having to explain this to scientists who consider computers a necessary evil) ;)
- gravypod 10y ago> Fortran is fast and has no reason to be worse than C Finding developers and maintainability. Those are two reasons.
- dzdt 10y agoFortran often IS the best language for the job, when the job is scientific number crunching. Compared to C or C++ it has the advantages of better complex floating point number support and better control of reproducible math results. And there is better possibility for compiler optimisation because the langauge semantics let the compiler know one array will not alias another. Compared to Java, C#, or Python, or any other JVM language, it has the advantage of compiling to machine code for every relevant supercomputer and cluster architecture. And all of the well-tested high performance computing libraries are written in or support Fortran. The ecosystem is there. Don't assume things are done purely by inertia -- for big projects there are real reasons for the choices made!
- gravypod 10y ago> Compared to C or C++ it has the advantages of better complex floating point number support and better control of reproducible math results No it does not have better complex types. C++11 added std::complex which is a standardized implementation of complex types for all data sizes. > And there is better possibility for compiler optimisation because the langauge semantics let the compiler know one array will not alias another. These optimizations will only ever be made if Fortran has wide adoption. These optimizations are probably already done in GCC/Clang. Fortran also misses out on a HUGE optimization that can be provided by the existence of explicit inlining from C/C++ and implicit optimizations from things like C++/Rust. There's also constexpr from C++ which, in C++17, will offer huge benefits to non-trivial code. Most formulas can be expressed as an inline function or constexpr and as a result can, in some cases, see huge performance improvements from compiler optimizations. > Compared to Java, C#, or Python, or any other JVM language, it has the advantage of compiling to machine code for every relevant supercomputer and cluster architecture. You can do this with Python. Or you could juse use Julia which is built for clustered environments, performance, IPC & machine-to-machine communication. > And all of the well-tested high performance computing libraties are written in or support Fortran. The ecosystem is there. So is with most of these languages. C++ is just as developed in this aspect, Julia is getting there but it's already ready for most applications. > Don't assume things are done purely by inertia -- for big projects there are real reasons for the choices made! I'm not. I'm assuming these decisions are made because people in physics/ME/chemistry are not programmers and don't know about the latest and greatest our field has to offer. It's our fault for not advertising our successes to these people.
- walshemj 10y agoyou mean "spit out your data, graph it, and see if it looks like what you expect and if it matches the real world experiments" Hint supersonic 1:1 wind tunnel time is very expensive so do you want to spent millions to which is why NASA uses CFD rewriting every thing in C++ would require a lot of back testing
- tjoff 10y agoJust wait, when javascript has taken over you'll miss the Fortran days.