I view Fortran as only good for number crunching, but for that purpose it is difficult to beat in many respects. Fortran is very common in supercomputing applications, though C and C++ are also very common. I know a lot of people who view Fortran as antiquated, and I understand their criticisms. I prefer other programming languages in general, but all programming languages are just tools and Fortran is a good tool in some circumstances.
And yes, as you've noticed almost all linear algebra is written in Fortran (BLAS, LAPACK, ScaLAPACK), so no matter what language you've written something to do some useful computation in, it's likely that most of the cycles are spent in Fortran!
Basically, I was starting to port some some Matlab code I had written to C/C++ to speed it up, but the most convenient solver for the differential equations I was dealing with outside of Matlab turned out to be a Fortran library. So I started learning basic Fortran in order to write a small C++ wrapper around that library, but ended up liking Fortran much better than C++, so I kept using it throughout my PhD.
Note that modern Fortran (2008+) is not at all like the infamous Fortran 77. There's no reason to write GOTO spaghetti; you have object-orientation, built-in support for complex numbers and matrices, array slicing, pointers, polymorphism, pure functions, vectorized ("elementary") functions and subroutines, and other modern features. There are even some unique features like the "associate" keyword that I sorely miss when doing mathematical programming in any other language (mostly Python these days). Because e.g. the built-in arrays "know how big they are", error messages are typically more helpful than debugging numerical C++ too.
In the modern day: R uses a standard Fortran BLAS implementation, as do many other libraries and platforms (NumPy, Numerics.NET, etc). LAPACK is also widely used for low-level numerical linear algebra: https://github.com/Reference-LAPACK/lapack Intel also maintains a BLAS implementation. So there's still a healthy need for a (small) community of Fortran programmers, it's not all about maintaining 70s legacy code. Very different than the situation with COBOL.
Nowadays: faster - maybe, noticeably - I doubt it.
> supercomputers have better-optimized Fortran compilers than C compilers
I don't know about supercomputer compilers but mainstream compilers usually have the same backend for FORTRAN and C (as well as other implemented languages).
> created a great deal of high-quality legacy Fortran code that nobody feels an urgent need to port into C
Optimized and tested FORTRAN code - maybe, but not high-quality. I've seen some of it, FORTRAN makes it difficult to write readable, maintainable code. For this reason even scientist are rewriting their tools and libraries (that also require good performance) in C++: for example see Pythia, GEANT, cern root.
I'm not sure I understand you correctly. Can you give examples of such flags?
> Also, vector/matrix operations are first class in fortran and you don't need to rely on 3rd party libs.
It may be useful as long as you're hell-bent on not using libraries (which is somewhat contrary to one of the pro-FORTRAN arguments that FORTRAN has lots of libraries that are tested and ready to use).
This is a weak consolation though, since anything complex enough deals with custom matrix/vector types for sparse matrices or data types used in parallel computations.
> It may be useful as long as you're hell-bent on not using libraries (which is somewhat contrary to one of the pro-FORTRAN arguments that FORTRAN has lots of libraries that are tested and ready to use).
Yes, library is still used but it's typically only for data input/output. For example NetCDF is a popular data format and many fortran projects support the format via 3rd party library. But for complex matrix computation, this is essentially what fortran was made for so it's not typical to use 3rd party library for this. Most big fortran projects in the area I was involved with (meteorology and air pollution) uses minimal amount of 3rd party library and mostly rely on built-in fortran functionality, with optimization being left to the compiler (typically intel or pgi fortran). There is definitely code reuse, but it's in the form of the scientist collecting snippets of useful algorithm over the years and copy it to the project when they needed.
[1] https://software.intel.com/content/www/us/en/develop/documen...
https://software.intel.com/content/www/us/en/develop/documen...
contrary to the earlier comment:
> You can't do this in C/C++
On a side note: having (semi)automatic parallelization with code generation for GPGPU would be very nice.
> There is definitely code reuse, but it's in the form of the scientist collecting snippets of useful algorithm over the years and copy it to the project when they needed.
I think that's just bad programming practices.
and I suspect they will be writing Fortran in C++
> Besides, the determined Real Programmer can write Fortran programs in any language.
And that billing system was very well designed using map reduce back in the early 80's, we did have an actual genius as a team leader though.
Fortan is pretty painful to write in. The lack of an STL means writing algorithms yourself. There is no good set of libraries, so you have to write more stuff yourself.
The string support is horrendous. Most of the language is based around clumsy fixed size strings. I wish they would add a new flexible string type.
The compiler quality is not up to C++ standards. My code currently has some nasty workarounds for problems in gfortran. It's not good to keep discovering compiler bugs.
I also find it's much vaulted numerical capabilities overstated. Vectorization only works in simple cases. You can't drop down to using SIMD wrappers to fix this. It's nice to be able to pass arrays around more easily than C, however. A good C++ array library would be better, but that would require everyone to agree on one.
Fortran needs a good compiler, that is why I started LFortran some time ago:
https://lfortran.org/blog/2019/04/why-we-created-lfortran/
and there is also Flang. Both Flang and LFortra are in development. GFortran is currently the most advanced open source compiler.
See our page for the list of all compilers:
Most of these tiny programs do at-least compile with ifc —
https://benchmarksgame-team.pages.debian.net/benchmarksgame/...
— fewer of them compile with gfortran —
https://benchmarksgame-team.pages.debian.net/benchmarksgame/...
— and fewer still compile with flang —
https://benchmarksgame-team.pages.debian.net/benchmarksgame/...
No doubt there's something ifc specific about the programs, or something obvious to a Fortran programmer but…
Edit: plus to ship our code to others requires a free good quality compiler. In the C/C++ world, that is standard. In fortran, that is not the case.
Regarding C and C++ compilers, for the same reasons most high performance HPC computers use Intel, IBM, PGI compilers instead of plain gcc or clang.
I don't think commercial/open source is the key here: on the fortran side we have been long suffering from a lot of bugs/regressions with the current versions of intel fortran (with respect to the "latest" features like OOP) -- I would even say that they could be more than we are finding in gfortran.
An explanation could be that they are investing time in supporting their big customers that likely use ancient code bases.
gfortran also does not do GPGPU.
It was quite surprising to find out the lack of understanding from Khronos that CUDA supports Fortran out of the box, during OpenCL 3.0 Q&A session.
I can code with CUDA in many more languages than fortran. If I wanted to use gfortran, I just would make a wrapper to CUDA with C++.
Yet, inline assembly is not part of ISO C.
Or one that generates lousy machine without full advantage of the CPU vector units.
Yet, vector instructions are not part of ISO C.
I also don't expect e.g. Ruby to have libraries for AAA game engines, or Erlang to have numeric libraries.
Most of the fortran codes I'm working on would be much simpler with a common libraries to do things like that.
So I don't think there are very many new projects being started but the presence of so much critical code in Fortran will extend its lifetime some more.