86 points · by bauta-steen · 7y ago · 51 comments
There might well be good answers to these; but it seems that if you want to make Fortran cool again, you have to provide a vision for what makes it special.
A physicist or engineer, already being familiar with Matlab or Python, can pretty much pick up Fortran in about 2 days to 1 week, get to be productive, and the compiler will generally generate fast code. Try to teach C++ to a domain specialist, who doesn't have too much extra time to study programming language syntax and quirks, because their main motivation is working in their domain?
If the scientific code was in C++, some scientists would probably never become fluent enough, and the workflow would probably deviate towards a division where scientists prototype their ideas in Matlab or Python, and separate technical programmer personnel implement it in the production code. The turnaround time from ideas to seeing results would be days instead of hours.
I see two reasons why C++ is not a suitable language for domain specialists in numerical computing.
1. Programming in C++ requires a certain discipline to understand what is going on, for example to not accidentally make useless copies of huge arrays. In fortran you do not need to learn such a discipline because everything is explicit.
2. Fortran natively supports multidimensional numeric arrays. In C++, not really; you need to use "libraries" whose evolution is independent to that of the language and may become unsupported. A few years ago, everybody said to use "blitz", somewhat later it was "eigen", now it probably is something new. The C++ numerical code that you may write today will probably be obsolete in a few decades. Yet the fortran code will be alright. It is "eternal".
That being said, the learning curve for someone not familiar with C++ to write code using Eigen is much higher than writing the same code in Fortran. If you're not already a C++ programmer, you just want to do some math, and Numpy/Matlab are too slow or constrained, then Fortran is a solid choice.
Moreover, the algorithms implemented inside eigen are hidden behind dozens of onion-like layers. Once you peel all these layers you find code such as this:
https://eigen.tuxfamily.org/dox/JacobiSVD_8h_source.html
I can read and write C++ and I teach numerical linear algebra for a living, but mother of god, this SVD implementation is horrendously unreadable to me. Most of the lines of code are stupid bureaucracy necessary just to add and multiply a few vectors. The same algorithm in linear algebra textbooks requires about fifteen lines of pseudo-code, and similarly for a fortran implementation.
Have you heard of MPI or even OpenMP ?. They can be used to accelerate fast computation in C++ or even work on domain-specified parallel execution.
these features are also available in fortran since forever
Fortran is a language more suited for numerical computing than C++. Modern Fortran is simpler, more maintable and more easily optimised than C++. Yes one could pick a subset of C/C++ and write fast numerical code but it would require more work and more discipline than using modern Fortran.
Fortran does not need Scott Meyers. And that's a good thing, because those who program in Fortran are typically not full-time software developers, they are individuals with other things to do that would not ever invest the time to write "proper" C++.
In the meantime, others in this thread pretty much hit all the main points already why Fortran as a language is still a very good choice for numerical computing. It's the tooling that must improve.
C++ is a messy, unsafe, and not particularly elegant systems programming language, which can be used for numerical computing, but it is not a good idea.
For example, Python's AST is not round-trippable, and that forces people to write alternative parsers such as Parso (https://github.com/davidhalter/parso).
ANTLR should allow to parse all the white space. But the issue is how to represent it in the AST, see the issue for more details. One could have an AST and a parser just for this round-trippable application, but that defeats the purpose. The goal should be to have this part of the compiler so that one can trust that it parses things correctly.
Right now I am concentrating my efforts to finish gfortran compatibility (see the roadmap at https://lfortran.org) and to get first users. Once we get further along, we will tackle this problem. I am hopeful there might be a way to do this.
1: At the bottom of the grammar, there are rules to intentionally skip over whitespace and comments, but it could have just as easily captured them and parsed them further. https://github.com/antlr/grammars-v4/blob/master/c/C.g4
Right now if you have any questions, you can open an issue at our GitLab repository:
What is a good Fortran compiler/implementation these days?
I know they have Intel and IBM and SimplyFortran as commercial software. GFortran works via GCC. Is it as good? Has anyone on here used this LFortran.
Regarding commercial implementations, I only have experience with Intel and NAG, both of which are very good.
Can you please point me to some documentation or examples where Intel Fortran is used to offload to, say, NVIDIA GPUs? I don't think it supports it yet.
PGI and IBM support CUDA Fortran, other compilers don't. PGI/Flang has an experimental support for offloading "do concurrent". Some compilers also support the openmp/openacc pragmas and GPU offloading. One can also call CUDA C from any Fortran compiler via iso_c_binding. None of this is ideal.
I think it's still a research problem how to best integrate GPU support in the language itself. CUDA Fortran is nice --- one thing we want to do down the road is to implement CUDA Fortran and to allow LFortran to transform code it understands into a Fortran dialect that all Fortran compilers can compile, so that one can use any Fortran compiler and still use CUDA Fortran.
The other path is to parallelize "do concurrent", but part of this is also means to extend Fortran to allow to specify the array layout, as Kokkos (https://github.com/kokkos/kokkos) allows.
That is one of the biggest problem with Fortran: people want to be assured that their code will run on modern hardware. When using, e.g., C++ and Kokkos, then there is some assurance that the code will run.
The goals look similar to me, so it's worth to take a look at them.
There is a really promising new project by Chris Lattner (the original author of LLVM) called MLIR: https://github.com/tensorflow/mlir. That might be the best intermediate representation that all the compilers (Julia, Fortran, ...) could target.