5 ms·
> Why not just allow the ports to C++ to happen? I see two reasons why C++ is not a suitable language for domain specialists in numerical computing. 1. Progr
by enriquto 8y ago
> Why not just allow the ports to C++ to happen?
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".
- alexhutcheson 8y agoEigen is still the best-in-class C++ library for linear algebra as far as I know. It's been around for a while, is still actively developed, and I don't think there's a risk of it becoming obsolete anytime soon. 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.
- enriquto 8y ago> 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. 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 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.
- alexhutcheson 8y agoYeah, libraries that make extensive use of templates are basically dark magic only comprehensible to C++ experts (see also: almost everything in Boost). The positive side of this is that it enables nice interfaces for the library, and makes a lot of the abstractions basically "free" (since the cost is paid at compile time rather than via pointer indirection at runtime). But it definitely makes those libraries inappropriate for students who want to look at an understandable implementation of the algorithm.
- enriquto 8y ago> ...makes a lot of the abstractions basically "free" Maybe it is just me, but I do not really see the need for "abstractions" in a linear algebra library. Numbers are already an abstraction, you do not want to hide them! Ok, maybe you want to choose between "float" and "double", but this does not merit all that overcomplication.
- vbarrielle 8y agoThe abstractions inside Eigen are there to enable powerful compile time optimisations, such as compiling the addition of three vectors `Eigen::VectorXf x = a + b + c;` in a single loop instead of naively allocating a temporary to evaluate `Eigen::VectorXf tmp = b + c;` then evaluating `Eigen::VectorXf x = a + tmp;`. This logic is omnipresent in Eigen and is crucial to its performance. It is also used to have specialized versions of some decompositions when the matrix's size is known at compile time.
- certik 8y agoThe main advantage of this approach is that you can use any C++ compiler and the library (in this case Eigen) will work. The disadvantage of this approach is that the code is incomprehensible to average scientists, you must spend a lot of effort to become a C++ expert. The advantage of Fortran is that the code is simple and comprehensible to average scientist, and yet fast, because the effort goes into the compiler itself. I would also argue it is easier to implement an optimization pass in the compiler than implement optimizations on the template level in C++. The disadvantage is that you need a good Fortran compiler. If your compiler can't run your code on, say, GPU, then suddenly there is not a good path forward. While in C++, there is always a way forward via template metaprogramming: perhaps ugly, but at least it gets the job done.
- melan13 8y ago> I see two reasons why C++ is not a suitable language for domain specialists in numerical computing. 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.
- enriquto 8y ago> Have you heard of MPI or even OpenMP ?. They can be used to accelerate fast computation in C++ these features are also available in fortran since forever
- wahern 8y agoDidn't they originate with Fortran?
- melan13 8y ago> Hence why learning Fortran ?
- coldacid 8y agoBecause you don't have to learn yet another set of functions in a language that makes it stupidly easy to blow off your own feet, and yet still have all the advantages of those systems in a language that is actually _designed_ for calculating formulas (hence the name FORTRAN, i.e. FORmula TRANslation).
- melan13 8y agoAgain, should your users understand the code you present or should you use the language you feel more comfortable with. Reading FORTRAN formulas is a pain (just reading for example a Prime factorization function implemented in parallel written in Fortran takes 10-15min to understand). Hence, I see a large advantage of OPEN_MP & C++ here.