18 ms·
LFortran: Modern interactive LLVM-based Fortran compiler
- pantalaimon 6y agoIs this related to flang? https://github.com/llvm/llvm-project/tree/master/flang/ https://github.com/llvm/llvm-project/tree/master/flang/
- kergonath 6y agoNot exactly. Development of both started at about the same time, but it was a coincidence. Flang is a standard compiler, whilst LFortran is more geared towards interactive use à la Jupyter, or source-to-source compilation. Here’s a demo of the Jupyter notebook-like interface: https://mybinder.org/v2/gl/lfortran%2Fweb%2Flfortran-binder/master?filepath=Demo.ipynb https://mybinder.org/v2/gl/lfortran%2Fweb%2Flfortran-binder/...
- certik 6y agoLFortran author here. As kergonath said below, both "new" Flang that you linked above, and LFortran started at about the same time. I know the Flang developers well and I am hoping we'll be able to collaborate in the future more. It looks like MLIR would be one option: they are going to use it for Flang and LFortran can have a backend that could also use it. LFortran's main advantage is that it is interactive, so the parser and semantics has to be a little different. And also we designed it so that it will be quite approachable for people to write tools on top.
- C1sc0cat 6y agoInteresting to see an interactive Fortran as I started with Fortran in my first Job - on my first day I was told there is a book in the company library go and learn Fortran For the really big Fortran systems I worked on in the 1980's (Map Reduce) the edit compile / link process could take several minutes for a single module - we did have a build system written in JCL to help automate this as well.
- mootzville 6y agoNice, I want to play with this, but I see on the Development page there is no/limited support for arrays?
- kergonath 6y agoNot sure about arrays (I am not involved in the project, I just thought it was cool). It’s still in a very preliminary stage, though, so there certainly are rough edges.
- certik 6y agoLFortran author here. There is a Python prototype version that you can see in the notebook and it has very limited support for arrays. I stopped spending more time on it once I got further enough to validate that the idea works. And I am now spending all my time on the production LFortran implementation in C++. I am very close to make it usable for some very simple things, and then we'll go from there.
- baggy_trough 6y agoNot much of a Fortran yet without arrays, complex numbers, or strings.
- dm319 6y agofortran - one of only a handful of languages that natively supports multidimensional arrays, maybe the only low level one?
- ironmagma 6y agoC kind of does, right? A multidimensional array in C isn't just an array of pointers.
- dm319 6y agoIs that more of a jagged / ragged array, or array of arrays? Sometimes these are called multidimensional arrays, but these are not the same thing. Dimensions and lengths of the dimensions should be a property of the multidimensional object. [1] https://stackoverflow.com/questions/597720/what-are-the-differences-between-a-multidimensional-array-and-an-array-of-arrays https://stackoverflow.com/questions/597720/what-are-the-diff...
- ironmagma 6y agoI was talking about int a[2][3]; in C. Is that jagged? I wouldn’t have thought so, since AFAIK you could only store 6 elements in that and no fewer. Interestingly you cannot take the value of &&a[0][0], assign it to an int **b; pointer b, and then access it via b[0][0] because it’s stored as a contiguous block of integers rather than an array of pointers that point to arrays as you might expect.
- dm319 6y agoYes, that's a jagged/ragged/array-of-array, and most languages support them. There isn't a requirement for the arrays to be the same length. There are many arguments about the pros and cons of each, and how different they are the closer to assembly you get. Golang had a proposition to include multidimensional arrays [1], there were lots of arguments. I think the different perspectives depend on what you want to use it for and how much numerical processing you do. [1] https://github.com/golang/go/issues/6282 https://github.com/golang/go/issues/6282
- sangfroid_bio 6y agoLooking forward to differentiable programming in Fortran.
- dnautics 6y agoI believe that's called "Julia".
- ChrisRackauckas 6y agoThere's a library for Julia coming out soon that can differentiate Fortran code. So, while tongue and cheek, it's not that far off!
- certik 6y agoThat has been requested quite often: https://gitlab.com/lfortran/lfortran/-/issues/97 https://gitlab.com/lfortran/lfortran/-/issues/97
- waynecochran 6y agoI use C++ Eigen extensively. I wonder if it feasible to write a C++ programs that hands off blocks of linear algebra code to Fortran subroutines. Eigen does a wonderful job of late binding and lazy evaluation so that something like the following is fairly efficient: (L.transpose() * P).diagonal().array().square().mean(); which computes the squared average of column by column dot products between matrices L and P. I assume Fortran, since matrices are native types, does this kind of thing even better. Aside: Fortran 77 was the first programming language I learned in 1985 and I hated programming for awhile after that. We called it the "F" language. Now that I am a bit older and do a lot of linear algebra coding... I wonder if I would like it now.
- kergonath 6y agoIf you use LAPACK there’s a chance that some Fortran code will be run at some point. For example OpenBLAS does it behind the scenes of you give it a matrix to diagonalise.
- celrod 6y agoI think Eigen's template strategy is probably hard to beat from the perspective of combining operations. How well Fortran does is probably mostly up to the compiler implementation. In some of my benchmarks, gfortran sometimes seems to fuse the operations and end up much slower than if it has performed them separately in succession, but I wouldn't be surprised if compiling with `-fexternal-blas` (and linking MKL) would've solved that. If you want to try external BLAS/LAPACK with Eigen, I'd look at: https://eigen.tuxfamily.org/dox/TopicUsingBlasLapack.html https://eigen.tuxfamily.org/dox/TopicUsingBlasLapack.html I have `A * B`, `A * B'`, `A' * B` and `A' * B'` small-single-threaded-matmul benchmarks here: https://chriselrod.github.io/LoopVectorization.jl/latest/examples/matrix_multiplication/ https://chriselrod.github.io/LoopVectorization.jl/latest/exa... I compared triple nested loops with Clang, icc, ifort, gfortran, Julia, and LoopVectorization.jl with matmul routines from ifort, gfortran, OpenBLAS, MKL, and Eigen. While gfortran's builtin hit over 40 GFLOPS with `A * B` and `A' * B'`, it failed to get half that if only one argument was transposed. I'm supposed awkward fusing at the start of this post because if it had done one after the other, it should have still hit >40 GFLOPS when only 1 matrix was transposed.
- deleted 6y ago[deleted]
- dang 6y agoIf curious see also 2019 https://news.ycombinator.com/item?id=19795262 https://news.ycombinator.com/item?id=19795262 https://news.ycombinator.com/item?id=19788526 https://news.ycombinator.com/item?id=19788526
- kergonath 6y agoThese are very interesting discussions. I don’t know how I managed to miss them when I submitted...
- dang 6y agoThe cutoff point for reposts is about a year, so it's good that you didn't see them and then not post. https://news.ycombinator.com/newsfaq.html https://news.ycombinator.com/newsfaq.html
- certik 6y agoLFortran author here. I missed one of these discussions.
- dng88 6y agoWish lisp have these like jupyter integration. And my first computer lecture many decades ago is really about how he hated fortran and why FORTRAN is still not dead (Mainly negative view due to haveGOTO that time). And it is still not dead.
- kergonath 6y agoTo be fair, it does not look much like it was many decades ago.
- mmaul 6y agoCommon Lisp has had Jupyter integration for a while. First cl-jupyter (https://github.com/fredokun/cl-jupyter https://github.com/fredokun/cl-jupyter) which is now in maintance mode and now common-lisp-jupyter (https://github.com/yitzchak/common-lisp-jupyter https://github.com/yitzchak/common-lisp-jupyter). Here is a notebook I did awhile back with cl-jupyter: https://github.com/mmaul/clml.tutorials/blob/master/CLML-Wine-pca-k-means-and-hierarchical-clustering.ipynb https://github.com/mmaul/clml.tutorials/blob/master/CLML-Win...
- fiddlerwoaroof 6y agoThere’s this: https://github.com/yitzchak/common-lisp-jupyter https://github.com/yitzchak/common-lisp-jupyter
- pjmlp 6y agoLisps were at the genesis of the original concept, it was called Lisp Machine, and the experience can still be replicated when using commercial Common Lisps like Allegro. Fortran has been continuously updated, supports OOP, modules, and even generics.
- waltpad 6y agoSadly, AFAIK, BLAS hasn't been updated to use generics. It would be so nice to have support for integer vector/matrix operations in there (not that it would require generics to have that, but it could be easier to implement integer support with it, though I suspect that for efficiency reason it might not be used in the end).
- deleted 6y ago[deleted]
- rarepostinlurkr 6y agoSupport for arm?
- yodelshady 6y agoModern fortran is surpisingly pleasant to write. The last time optimisation came up, I tried the author's problem - multiplying two 4096x4096 matrices - in numpy, FORTRAN and Rust, on a standard laptop. Supposedly it took 9 hours in naive Python (I didn't try). Results were: Python3 (numpy 1.18.4) 1.3s FORTRAN (gfortran 9.3.0) 6.0s Rust (1.43.1, debug) >60s Rust (1.43.1, release) 4.0s What surprised me is that python and fortran solutions were written in minutes. The Rust solution took hours and multiple forum posts for help. There's no obvious way, and every single way I tried had "gotchas" and utterly astonishing behaviour in it, particularly with simple, statically-allocated arrays. Fortran could do with proper namespaces, and properly dropping some of its older conventions, though. Reading it feels like archaeology.
- MaxBarraclough 6y agoSo to be clear, numpy gives you a highly optimised matrix multiplication algorithm, and your FORTRAN solution was just something you threw together yourself, right? Little surprise that numpy roundly outperforms it, especially if it's using a different algorithm, such as Strassen rather than naive matrix multiplication. [0] > every single way I tried had "gotchas" and utterly astonishing behaviour in it As someone who doesn't know much about Rust (or FORTRAN for that matter), what kinds of gotchas? I'd expect numeric code like this to be quite straightforward, as it presumably doesn't lean heavily on memory-management cleverness in the language, or anything like that. [0] https://en.wikipedia.org/wiki/Strassen_algorithm https://en.wikipedia.org/wiki/Strassen_algorithm edit For clarity, I made a table of your data. Seems surprising that Rust outperformed FORTRAN. ┌──────────┬─────────────────┬──────┐ │ Language │ Detail │ Time │ ├──────────┼─────────────────┼──────┤ │ Python3 │ numpy 1.18.4 │ 1.3s │ │ FORTRAN │ gfortran 9.3.0 │ 6.0s │ │ Rust │ 1.43.1, debug │ >60s │ │ Rust │ 1.43.1, release │ 4.0s │ └──────────┴─────────────────┴──────┘
- Someone 6y agoThe main reason for numpy’s speed is that it uses highly optimized code written in another language (for matrix multiplications, quite possibly FORTRAN).