4 ms·
At least back in the mini super era, Fortran was (far) easier for the compiler to optimize than C. Yeah, you could add all sorts of #pragma indicating that poin
by jleyank 5y ago
At least back in the mini super era, Fortran was (far) easier for the compiler to optimize than C. Yeah, you could add all sorts of #pragma indicating that pointer/array are not overlapping in memory but that equivalence was a problem. But then, trying to do I/o in Fortran was annoying so lots of compute codes ended up with c front ends.
- pjmlp 5y agoStill is. Trying to outperform Fortran relies on C developers putting the right annotations on the right places and never get them misplaced, otherwise it will trigger UB.
- adgjlsfhk1 5y agoIn my opinion, Julia is much better for numeric performance than C or Fortran. Real macros mean that you don't have to use a janky preprocessor (or a separate programming language) to generate optimal code, and multiple dispatch means you don't need to give your functions awful names (looking at you cgbtrf) and instead can just name them for what they do. (Also, Julia gives you easy automatic differentiation and gpuification)
- klodolph 5y agoThe awful names are from a six-character limit somewhere. I'm curious why you would want multiple dispatch. Seems to me like either longer names or single dispatch would be enough. In "cgbtrf", the first three letters just tell you what kind of matrix are the input... "cgb" being a complex-valued band matrix. That leaves you only three letters to say what the function does.
- adgjlsfhk1 5y agowith multiple dispatch, this function would just be lu. Multiple dispatch means that all the functions that add things can just be called +, and all the ones that compute lu factorizations can be lu, and which specific version gets called is all handled by the type system. If I call lu on a complex banded matrix, it will dispatch to the method optimized for that without me having to care about what that is. This makes writing generic code much easier because you don't have to write a separate copy of your function for each new datatype you want to support.
- pjmlp 5y agoSo like Fortran generics.
- adgjlsfhk1 5y agoNot really, Fortran is inching it's way towards generics, but doesn't actually have them in a usable form yet.
- pjmlp 5y agoParameterized derived types seem good enough for what Fortran is used for.
- adgjlsfhk1 5y agoThey are powerful enough to express functions that only depend on one argument, but how would you use them to encode the types of both arguments for matrix multiplication?
- pjmlp 5y agoLike this? https://www.pgroup.com/blogs/posts/f03-oop-part3.htm https://www.pgroup.com/blogs/posts/f03-oop-part3.htm
- adgjlsfhk1 5y agoThat gets you some of the way there, but isn't powerful enough to handle things like orthogonal*banded or really any situation where all the types aren't planned out in advance.
- gnufx 5y agoI don't remember if it exists for LAPACK, but there's a generic BLAS interface with ifort/MKL. It's just a pity it was never (quasi-)standardized. (The trivial example is Fortran intrinsics.) I was happily using CLOS-like systems long before Julia, though. Does Julia actually beat SBCL, for instance, on such things?
- pjmlp 5y agoEventually, note that you should compare it against latest ISO Fortran standard per commercial compilers, not what gfortran is capable of.
- sampo 5y ago> multiple dispatch means you don't need to give your functions awful names (looking at you cgbtrf) and instead can just name them for what they do. Fortran has ad-hoc polymorphism, and 63 characters maximum length for names. These should be enough to keep the user happy in this use case. (The programmer still needs to write separate code for each version of input types.)
- cudder 5y agoWhy is fortran so much more efficient (or easier to optimize)?
- pjmlp 5y agoBecause it was designed for mathematics from the ground up. So the language has built-in optimization for linear algebra kind of math since decades, doesn't rely on pointers for basic data structures and type system prevents aliasing by default.
- gnufx 5y agoThe language doesn't specify optimization, though it has features for optimizers to take advantage of, and the classic loop optimizations were introduced in Fortran H if I remember correctly. The storage association rules aren't in the type system; you can write code that violates them, and many people did, but perhaps fewer now.
- jejones3141 5y agoSee the section of Coders at Work where the author interviews Frances Allen.
- gnufx 5y agoWell, Fortran relies on you obeying the storage association rules that people regularly used to assure me didn't exist.