Fortran
fortran-lang.org
fortran-lang.org
<quote> Our assessment for seven distinct risks associated with continued use of Fortran are that in the next fifteen years:
1. It is very likely that we will be unable to staff Fortran projects with top-rate computer scientists and computer engineers.
2. There is an even chance that we will be unable to staff Fortran projects with top-rate computational scientists and physicists.
3. There is an even chance continued maintenance of Fortran codes will lead to expensive human or financial maintenance costs.
4. It is very unlikely that codes that rely on Fortran will have poor performance on future CPU technologies.
5. It is likely that codes that rely on Fortran will have poor performance for GPU technologies.
6. It is very likely that Fortran will preclude effective use of important advances in computing technology.
7. There is an even chance that Fortran will inhibit introduction of new features or physics that can be introduced with other languages. </quote>
In my view, a language is destined for being a "maintenance language" if all of these are simultaneously true:
1. There is a dearth of people who know the language well.
2. Few people are opting to learn it in their free time, and/or seek it out for a job.
3. Companies do not seriously invest in training in learning the language.
4. Companies don't pay enough to convince an engineer to use it. who otherwise loves using other languages and has better prospects with them.
I've experienced unique challenges in hiring Lisp programmers, but the fact it remains sufficiently interesting to enough software engineers (who are usually good programmers) has been a boon, and likewise providing space to learn it helps even more.
Fortran though is teetering on its historical significance and prevalence in HPC. Aside from the plethora of existing and typically inscrutable scientific code, I'm not sure what the big iron imperative language offers over the dozens of other superficially similar choices these days, except beaten-path HPC integration. Scientists are more and more writing their code in C++ and Python—definitively more complicated than Fortran but still regarded as premier languages for superlative efficiency and flexibility respectively. Julia has had a few moments, but (anecdotally) it doesn't seem to have taken off with a quorum of hardcore scientist-programmers.
[1] https://permalink.lanl.gov/object/tr?what=info:lanl-repo/lar...
- "Very likely" poor or non-existent robust GPU support,
- Unlikely robust support for specialized processors (i.e., non-general purpose CPU) like "Data Flow processors" and "processing in/near memory",
- Fortran advocacy and advancement is likely limited to DOE, which the report implies is insufficient, and
- Vendors of hardware have prioritized C++.
About 4: I think Fortran looks quite like C when it comes to the CPU architecture. Both are somewhat low level procedural languages.
As long as C works well on future CPUs, Fortran is probably fine and I don't see C disappear overnight. At least, Fortran compilers can be updated to produce reasonable code for new CPUs. Which should happen because of the shared compiler architecture (backend).
About 5: GPUs architectures seem less stable and seem to require specific development. If those specific developments require language support, that's probably not coming to Fortran if the assumption is that Fortran is going maintenance-only.
About 6: advances in computing technology are not restricted to CPUs and GPUs.
(disclaimer: I've only seen Fortran code from far away. And code targeted to GPUs too).
Given the capabilities of modern machines and the fact that non-homogenous hardware (GPUs, different processors like in Apple Silicon) is back, the "winning" strategy is to have high-level scripting languages where you can ignore most of the details, which call into hyper-optimized, high performance libraries. For instance, when you're using Scipy, you call into Fortran and C almost interchangeably.
Since most likely you aren't writing full programs in the low-level language, it doesn't need to be a general-purpose language offering the same affordances, say, C++ is supposed to provide.
For numerical/scientific code, Fortran is much, much easier to use, especially for people whose background isn't computer science. Being able to write your code in terms of matrices and arrays rather than "pointer to const restrict" is a godsend when you're programming what is often very difficult mathematical code. When compared to modern C or C++ you won't get any advantage in terms of performance, but you don't lose much either, and in return you get to use a language that's much more suited to the task.
The historical Achilles' heel of Fortran is that it's kind of awkward as a general-purpose language, but that's negated by the "compiled core, interpreted shell" approach that's dominant these days.
I think what you say is true in principle, basically on all counts, but Fortran's niche that its advantages serve best has been continually eaten away at by the Python/C++ combination.
The "I don't know pointers" crowd steers toward Python, and the "I care about CPU cycles" crowd steers toward C++, and that relationship is symbiotic.
Julia promised to be a general-purpose language, both as fast (or faster) than Fortran/C++ and as easy (or easier) than Fortran/Python. But it doesn't seem to have panned out as they'd perhaps have hoped.
Julia has something similar but to a lesser degree. Its main problem has been the developer experience - the latencies (slowly getting better), lack of a great editor/LSP experience (the VS Code plugin is decent, but not yet great), lack of accessible how-to resources (people are starting to write more of these), and things like that.
I've just noticed it's now available on the system I work with, which puts it in the frame for a possible (probably far out still)future move for a massive C/Fortran codebase I maintain.
My general default if I'm going to update something is C++, but from what I see of Julia it's at least worth a look.
R or Python are still much easier to use and give you the same access to high-performance numerical accelerators via BLAS/LAPACK backends. And if you need a low-level language (e.g when developing an optimised routine that solves a specific problem), I would use a high-performance widely supported systems programming language like C++ or Rust.
Fortran seems to be around mostly for legacy reasons. And I am not sure that legacy considerations alone make a good foundation.
CuBLAS on the other hand makes a lot of sense to use from python if you have the right hardware.
That's not to say you should use C yourself, memory management is a lot nicer in Fortran, for multidimensional arrays. You can stack allocate arrays inside functions and modern fortran has move semantics. Arrays are contiguous even if they have multiple index. It's generally a nice language for math, has good C API integration (both as caller and callee) and compiles down to small libraries without runtimes.
For scientific computation I just need multi-dimensional arrays of floats and fast loops. Fortran has both of these things natively. Python has neither.
From personal experience, I don't believe this works in practice. Invariably, some level of logic is implemented in said scripting language, and it becomes a huge bottleneck. Counterintuitively, when you have a central thread dolling out work to many subroutines, the performance of that thread becomes more critical as opposed to less.
Not necessarily and if it does, then the solution is to add that logic into the low level libary. So yes, you need at least one guy who can do this.
Just to be clear, I'm not saying it's impossible to strike the balance where it makes sense. I'm just saying I've yet to see it work, and I would, therefore, not assume such a balance is given by default, or even easy to achieve.
In my experience, that means that 80-90% of the developer effort goes into getting the FFI bindings to not be terrible. (In fairness to things like python, most of my FFI experience is with Java, which is notoriously bad at such things)
And with wasm (or even webGPU) one can do now the same with javascript and the web. Some logic in scripting is fine, but the heavy calculations should be lower level if one is aiming for performance.
From personal experience, I don't believe this works in practice.
From personal experience, this works in practice.It works well for web or other server-side tasks where your database is doing the "heavy lifting" computationally.
I believe you, though, when you say that you've seen failures of this paradigm.
It's pretty common to see issues where an inexperienced programmer is doing a bunch of data manipulation in 200 lines of Python/Ruby/PHP/whatever that could have been accomplished more easily, more performantly, and with more atomicity in 10 lines of SQL. I wouldn't say that means it's a busted paradigm. I don't consider bad implementations of a particular paradigm to equal refutations of that paradigm.
I do appreciate that there are probably arenas (scientific computing?) where maybe this approach doesn't work at all.
That gets you about 70% of the way there, but the remaining 30% is tricky. Unfortunately, the library-call stage doesn't easily (with generality) let you fuse operations. For example, consider the example of a finite-volume code, where the flux is some nonlinear function of the interface value, taken to be the average of left and right cells:
flux = nonlinear_flux_op(f[:-1] + f[1:]) # Compute interface fluxes
f[1:-1] += dt/dx*(flux[:-1] - flux[1:]) # Update cell volumes based on flux differences
# Do something special for the boundaries
Each of the substeps here is fast. Sub-indexing these 1D arrays is trivial, and their local operations are highly vectorized. The nonlinear flux operator operates element-wise, so it's easy to compile it into a version that properly (CPU) vectorizes (and/or it might already be provided, like np.exp or *2). This code is also very readable.However, real performance would require fusing operations. There's no need to compute a full temporary array for the interface values, but that's exactly what would happen in naive NumPy code. Likewise, there's no need to compute all of the fluxes before taking their differences.
A hand-optimized code would perform the full computation in a single scan of the array, keeping all of the data in CPU cache (blocking by a cache line or so in order to use vector registers effectively). Even if given the code naively written, an optimizing compiler would try loop fusion and get most of the way to the hand-optimized result.
Code such as this is relatively FLOPS-light compared to the amount of memory accessed, so effective use of cache can lead to an order of magnitude speed-up.
With a fair amount of work you can still achieve this result in Python, but to do so you need to use one of the optimizing Python compilation tools like numba. Unfortunately, this is not easy for the not-a-programmer domain scientist, since working with numba means understanding the intersection of Python and numba's imposed compilation rules.
That's nice as long as it works, but in my experience gets ugly when it doesn't. While we can currently witness this being a successful model, the impedance mismatch between both worlds is often a pain.
I bet on a language like Rust as the winning strategy in the long run - high level like Python but still close to the metal and all in one language, one compiler, one ecosystem.
In C, pointers can alias by default. The last time I checked, that made these sorts of optimizations harder. However, I'm not sure how measurable the performance impact is these days.
Well, no. This is python's strategy. Doesn't make it the winning strategy. Python implicitly forces multiple languages upon you. A scripting one, and a performance one. Meanwhile languages such as Julia, Rust, etc. allow you to do the work in a single (fast/compiled) language. Much lower cognitive load, especially if you have multiple cores/machines to run on.
Another point I've been making for 30+ years in HPC, is that data motion is hard. Not simply between machines, but between process spaces. Take large slightly complex data structures in a fast compiled language, and move them back and forth to a scripting front end. This is hard as each language has their own specific memory layout for the structures, and impedance matching between them means you have to make trade-offs. These trade-offs often result in surprising issues as you scale up data structure size. Which is one of the reasons that only the simplest of structures (vectors/arrays) are implemented in a cross language scenario.
Moreover, these cross language boundaries implicitly prevent deeper optimization. Which leads to development of rather different scenarios for code development, including orthogonal not-quite-python based things (Triton, numba, etc.).
Fortran is a great language, and as one of the comments pointed out, its really not that hard to learn/use. The rumors of its demise are greatly exaggerated. And I note with some amusement, that they've been going on since I've been in graduate school some 30-35 years ago. Yet people keep using it.
I guess most of the legacy code for which they do this risk assessment is Fortran 77. Not any more modern.
And getting it up to date to modern fortran would be as much effort as any other modern language.
> 1. It is very likely that we will be unable to staff Fortran projects with top-rate computer scientists and computer engineers.
They are mentioning "top-rate", I'm assuming salary is not an issue. I can understand for a scientist who's job is not programming (and programming is just a necessary activity). But for a "top-rate" computer engineer, given a good enough salary and an interesting field, how hard can it be to learn enough Fortran for this?
Or am I misunderstanding what is a computer engineer?
Even for a top-rate scientist actually. Surely the programming language is not the hardest part of the job?
(not saying they should not try to move away from Fortran, there are better solutions for this field now, I mostly agree with this list full of insight)
Not necessarily when it's not your job, but it depends on what level of comfort / ease we are talking about.
A relative who is a physicist and who started with Fortran recently switched to Python. They told me it took them around 3 years to be as comfortable as before.
Now, I suspect they were very comfortable with Fortran to begin with, and if they programmed a significant amount of time every day, they would have been up to speed way faster.
(They also said they would not go back to Fortran)
She still doesn't feel comfortable with Python (or any language) and often needs guidance / help. Mostly because in this role, the amount of programming is really minuscule, and the expectation isn't that the programmer develops a useful application or library well-integrated into the larger ecosystem of applications or libraries. Rather it's that some research can sift through the data they've generated and publish on that.
The instances of "re-education" I was talking about were quite different: those were "programmer-first" people. In this capacity, they might write in a month more code than what what my wife wrote over the last four years, they are also expected to build a lot more complex (in terms of organization and integration) software.
I don't consider RSEs or similar roles to be professional programmers. These people typically have terminatory degrees in fields other than CS, but often no formal training in CS. They also rarely see their own goals in becoming as good of a programmer as they can, their evaluation is typically based on results that programming might help to bring about, but, in principle, isn't really necessary for. Sort of how you wouldn't call every programmer a "professional mathematician", even though writing programs is a kind of math, as is eg. checking out customers at the supermarket.
So, while someone like that might need years to adjust to a new language, OP seemed to have in mind professional good programmers. I think they even had another bullet point for hybrid scientist-programmers.
Source: am RSE. And I will also say, a few of the scientists I support are among the best software engineers I have ever worked with, despite caring about code only insofar as it can help answer useful questions.
Fortran is considerably simpler than Python, though. No metaprogramming. No functional programming. No objects. Etc.
It's basically C with nicer syntax, and some QoL features.
I can start a fresh Fortran program and write it out pretty quickly (though I do miss native dictionaries), but when I have to collaborate with an old-school Fortran programmer (especially one trained on FORTRAN 77) it's pretty tough for me. I have to reprogram my brain to think in that style/culture.
I tend to do most of my high performance numerical stuff in Numpy since it defers to the Fortran libraries for the hard stuff. I haven't found any properly written vectorized code get bottlenecked in the interpreter.
It would definitely not take years to get on top of it for anyone who knows a bit of programming.
The challenge isn't that people can't learn it, it's that they don't want to because it's a bad career move.
Enough of good programmers choose unpopular languages, and for different reasons. Some genuinely find particular aspects of the chosen language appealing, and since they are in general good programmers they don't have a fear of unemployment or the pressure to build their career -- they've already established themselves in their field and don't need to reassert their skills and knowledge.
Others may opportunistically choose a new, but still unpopular technology, sometimes because other good programmers seem to have chosen it, other times because they may hope to gain more popularity / acclaim, which is easier to do in a new, and especially in a small field.
Furthermore, it just so happened that popular technologies in the industry today are all kinds of bad. Just of sheer desperation / disdain to a particular group of related technologies one may want to try to switch to a niche technology that seems to go against the mainstream.
---
However, in all those cases, there must be something "interesting" going on for the technology in question. I don't know enough of Fortran to claim there's nothing "interesting" going on for it, but it's possible that there isn't. In which case, there won't be an incentive for good programmers to choose it over similar technology that has that glimmer of hope that it's going to be so much better.
You mean in the language itself or its applications. Honestly I’ve heard about a lot of really cool things written in Fortran. Honestly, I wouldn’t mind learning it, but I’m far from a “ top-rate computer scientist” so no Ike using Fortran would be interested in me.
Suppose this was the only really good thing going on for it... well, this wouldn't attract a lot of people. Also, I'm not sure Fortran can boast to be the easiest language for optimization. I believe the statement was made in the context of comparing it to C, in which case, it's not such a high bar.
The use of pointers in a language vastly complicates the task of optimization. From Fran Allen, a compiler researcher and co-inventor of SSA,
By 1960, we had a long list of amazing languages: Lisp, APL, Fortran, COBOL, Algol 60. These are higher-level than C. We have seriously regressed, since C developed. C has destroyed our ability to advance the state of the art in automatic optimization, automatic parallelization, automatic mapping of a high-level language to the machine. This is one of the reasons compilers are basically not taught much anymore in the colleges and universities.
Which is kinda good, to be honest. Long-term Fortran projects and the like don't deal with the usual FAANG-type career-oriented churn that well, that mirrors the same problems you have in academia-oriented libraries where you get maintenance gaps when graduate students leave.
In numbers, IT jobs are dominated by social media companies, and companies selling ads and services on the web and via mobile apps. But I don't think these areas of applications should define what is or isn't deprecated technology for e.g. nuclear simulations, and weather and climate forecasts.
Fortran is bad for implementing web services. But it doesn't make popular web service technologies good for weather forecasting, either.
[1] A SWE4 (BS + 12 YoE) has a pay scale of $109k - $182k and requires a Q clearance (top secret for nuclear): https://lanl.jobs/search/jobdetails/senior-software-applicat...
That's the thing for these "top-rate" posts, you need to sell the candidates on why they want to take your offer, not some other role they could have. Yes, one option is to "just" pay them a tremendous amount of money, but remember you're competing with the banks who have the same strategy and their whole business is making money. So that would be very expensive.
Instead it makes sense to compete on other considerations. Candidate doesn't like to work in the office? No problem. Stay where you are, work for us remotely. Or maybe they'd like to move their grand parents and extended family to your country? You could make that happen. Or could you? Do you think the US Federal Government will accept "We need to naturalize these sixteen random people, immediately to get one Fortran programmer" ?
And the choice of language is one of those other considerations. To a first approximation nobody is more keen to take your offer because they get to write Fortran.
Is there anything unique about Fortran that prevents experienced engineers from quickly learning it on the job?
But MPI, in most use cases, comprises far less than React does, so it's not a fair comparison.
No. I think that Fortran is a convenient scapegoat for LANL, not an actual obstacle. I discuss what I think the real problem is in this comment: https://news.ycombinator.com/item?id=37292569
Perceived prestige, or rather the lack thereof. People with CS background often feel that learning Fortran is beneath them.
The problem is in the longevity of Fortran. The variety of codes accumulated through time makes up for more than one Fortran. Modern Fortran may appear as a new language, yet still very compatible with 'classic' Fortran. MPI adds another dimension to learning it, though there's tooling around it.
The aspect of tolerance to single letter variables and cryptic function names could also be a factor, no kidding.
In general, asking for prior experience with Fortran is reasonable, just as hiring someone to "quickly learn" C on the job is quite non-pragmatic.
My own renaissance came via Jetson Nano where CUDA FORTRAN has some nice examples for image processing via convolution kernals. It's blazingly fast: both design time and run time!
This short film from 1982 shows the love scientists feel for "the infantile disorder":
The Beginnings of FORTRAN (Complete)
CUDA Fortran was amazing. It had a really nice syntax, which did not feel that odd next to standard Fortran, and great performance. But it faced an uphill battle, was not really well managed and suffered from being coupled with the PGI compiler. I wish they’d put it in gfortran instead.
I think their main problem hiring is that they are looking for perfect candidates. (The same may be true for some of the other DOE labs like LLNL as well.) I've interviewed for at least 3 positions at LANL. I have a security clearance and would love to work for them, but I have never received an offer from them since finishing my PhD. (I did a summer internship with them a long time ago.) Issues like there being relatively few Fortran programmers are convenient scapegoats. They seem to want someone who not only knows Fortran, but also can easily get a security clearance or already has one, can write highly optimized MPI code, is familiar with the unusual numerical methods LANL uses, etc. They seem unwilling to hire people who are 80% of the way there. I've never programmed with MPI, for example, but understand the basics of parallel programming and have programmed shared memory codes. The most recent LANL group I interviewed with also didn't like that I quit a previous postdoc due to disagreements about the direction of the project.
In contrast, in my current job at a DoD contractor, they didn't seem to care much about what I did before or knew previously. They apparently hired me because I had some familiarity with their problem and could learn what I didn't know. I've done well in this job working on things mostly new to me. I'd like to leave because of the bad job security and bad benefits, but otherwise, I have no major problems. (And yes, I do use Fortran on a daily basis here, including some horrendous legacy Fortran.)
Given this, I don't think LANL's hiring problems will stop if they switch all their active softwares to C++ or some other language, because that's only part of the problem.
Edit: Another problem is that LANL's hiring process is convoluted. I almost got an offer from them two years ago, as the group I interviewed with liked me. But they required me to write an internal proposal which would have to be approved by someone outside of the group. I think this is part of LANL's standard post-doc hiring process, though at the time I thought it indicated that they didn't have the money to hire me and were trying to get it. There was no guarantee that the proposal would be approved. I didn't have the time then and backed out, though in retrospect I wish I went through with it as I've heard this is more routine than I thought it was.
Edit 2: Also, for clarity, not every position I applied to required Fortran knowledge. But I think my basic message is correct, in that LANL tends to be fixated on hiring "perfect candidates" when there are plenty of capable people that they could hire instead who just need to learn some things, or might not have a perfect job record (gaps in employment, etc.).
I’ve noticed this with government and government adjacent stuff: they are choosing beggars.
The salaries they offer tend to cap well below what you can make in the private field, often are in weird areas and don’t offer relocation, and just seem terribly bureaucratic when it comes to advancement.
And yet, it seems they won’t hire you if you don’t hit their checklist to a T. I applied for a NOAA job, that wasn’t too crazy, and for the most part, was a pretty good fit for my resume. However, the application had a checkbox question along the lines of “have you ever written software for [hyper specific domain]”. I answered no and was unsurprisingly rejected. By the way, this wasn’t some wild scientific computing project, it was basically a job writing CRUD software for something that sounded interesting to me.
I really wonder how some roles get filled, I’ve seen some ridiculous asks.
Perhaps, interoperability is the way forward.
https://lpython.org/ https://lfortran.org/
LPython compiles Python at the Fortran speed, since both compilers share the same internals.
And this isn't meant as some kind of bait, just honest intellectual curiosity (its the internet so you can't see how it presented, just read the raw words).
Simply, why is it important for Fortran to survive in this space? Why not let the field move on? Why fight this fight?
[1] https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Libr...
https://lfortran.org/blog/2019/05/why-to-use-fortran-for-new...
Let me know if you have any follow up questions.
I studied Fortran in my college programming languages class (in the early 2010s) and loved it! Always wondered why it isn't used more.
Identification of the risks including the likelihoods and hazards is pretty good. I like the notion of contrasting opinions included in the report.
But the big thing missing is mitigations: what can they do about training, about recruiting, and especially about "industry" investing in compilers? This report says nothing about ways to assure continued usability of Fortran-based codes in the next 10 or 15 years. It just lists risks. What can they do to improve the capability of GPU compilers, CPU compilers, training or staff development?
And, setting Fortran aside, what are the plans to assure continued capability in supporting and developing all of their codes, in whatever languages, in the next 10 or 15 years? This evaluation might well be replayed for CUDA, Python or Julia in the next 5 years.
The US budget for supercomputing must be in the $2G to $5G per year range, yet it seems the notion of planning a software strategy for supercomputing is not achievable.
Does any other language have built-in COMPLEX type? Or funny (but fast!) stack-free function calling?
Is stack-free function calling equivalent to tail call optimization? If so, then many CL implementations support it, including SBCL. For Scheme, it’s part of the standard.
There is a race of sorts going on, to simplify and commoditize high performance computing in the post-Moore's era. This means enabling things like easy GPU programming, easy multi-core programming, easy "number crunching" etc. Historically this was the stuff of esoteric HPC (high performance computing) pursued by highly specialized computational scientists etc. (read -> an important but non-economic domain that subsisted largely on government funds).
Yet suddenly the same arcane HPC is effectively also the domain of "AI" and the associated planetary hyperventilation. Now all sorts of modern initiatives and language ecosystems aim to reposition to gainfully intermediate that AI revolution. Python was the scripting language that somewhat unexpectedly enabled all this, but now its warts are under the microscope and people think of various alternatives (julia), supersets (mojo), newcomers like rust etc. But that race is definetely not settled and it might not be so for quite some time. The requirements are highly non-trivial.
As far as taking part in this race, Fortran seems to have missed not one but several boats. Yet the fact remains that it was a language designed for number crunching and evolved as language for HPC, with parallel computing features (since F90) etc. It combines easy to read imperative numerical code with near optimal computational performance.
Its like a former world champion in a sport that was fell out of favor for a long time but is now unexpectedly back in vogue. So the question is whether the champ can get back into shape or make room for new contenders :-)
The Venn diagram of Fortran feature availability in the various actively maintained Fortran compilers is very messy, and the ISO standard is definitely not a subset of any of them. Standard-conforming code is not necessarily portable, and highly portable code is not necessarily standard-conforming, especially since Fortran '95.
X .= f.(2 .* X.^2 .+ 6 .* X.^3 .- sqrt.(X))julia> X = [1.,2.,3.]; f=sin;
julia> @. X = f(2 * X^2 + 6 * X^3 - sqrt(X))
c_y = (qmr*ey_sub*dtsq + c_y*(2 - omsq_b*dtsq))/gmdto2p1 - c_ym1*gminv
ey_sub, c_y, c_ym1 are N long arrays with the same shape, and in this case, the operation is elementwise, so indexing isn't needed, and I do not need an explicit do-loop (for loop in C languages) so it fits on a single line that is readable to a scientist in the field. The julia equivalent, I think is the same with a period on every operator c_y .= (qmr.*ey_sub.*dtsq .+ c_y.*(2 .- omsq_b.*dtsq))./gmdto2p1 .- c_ym1.*gminv
The assignment was already verbose as it is, and I at the time tried to make it terser but still marginally readable by using variables that are named for...scientists I guess (e.g., gmdto2p1 means "gamma * dt / 2 + 1" dto2 thoughout the codes I read and use is "dt over 2") and adding 10 characters makes a little more cumbersome. While I think the visuals can be acclimated to, it is tedious to write, especially when you translate a formula from vectorised form to non vectorised or vice-versa and have to insert or delete periods. Mind you this is one of the simpler formulae in the code in question. You can imagine it quickly gets worse when the number of terms exceeds 6 or so.If you can't rely on implicit-do or terse assignment statements, then the good alternative in terms of readability then for the formula is just to do an explicit do-loop (for loop for julia).
! fortran 90, `integer i` above
do i=1,size(c_y)
c_y(i) = (qmr*ey_sub(i)*dtsq + c_y(i)*(2 - omsq_b*dtsq))/gmdto2p1 - c_ym1(i)*gminv
end do
# julia
for i=1:length(c_y)
c_y[i] = (qmr*ey_sub[i]*dtsq + c_y[i]*(2 - omsq_b*dtsq))/gmdto2p1 - c_ym1[i]*gminv
end
The problem is then I have made more extraneous bits to worry about. This gets even more hard to parse when the shape of the arrays exceeds more than 3 dimensions. I've read C style codes that are 7 levels deep with different indices, god is it painfully unclear and easy to get lost reading that, it's best to hide extraneous loops with syntactical sugar where possible such as to keep the algorithm as clear as possible, especially when it's a simple elementwise operation. It isn't like you can hide complexity all the time (or that it's even a good idea to do so), but this was a code for just two figures in a paper that needed a bit more oomf than numpy could, so given the time constraint for me, the size of the problem and everything, fortran fit much better.If you want to know more about the dot macro in julia, here is a nice blogpost about them[0]. The line above is from work I did for a paper that I initially thought "hey, it's been a few years, why not see if julia has stabilised by now" only to find out this was a decisive change they made. I mean they might deserve praise having made this macro a very general thing and apply widely to things that aren't just syntactical sugar for broadcasting, but after being frustrated trying to write my code, googling, and then finding this post, I basically dropped the julia learning effort and got the code written in fortran and made my figures. I can learn things in my spare time to a limit but at the end of the day I have a job to do.
I still want to give julia a chance because the idea does seem cool. I complain about computer scientists a little tongue-in-cheek but really I find the metaprogramming in julia pretty interesting. I'm just not sure I can use it in my day job as a scientist without some effort in learning and time on my part which is at a premium right now.
A useful macro is @. which allows you to write "@. A * B * C" instead of "A .* B .* C". Also the macro avoid the creation of an intermediate vector with A times B.
I've certainly had moments where I've gone "just do that elementwise already, it's obvious!" and been mildly annoyed, but I'll take that any day over silent misbehaviour, hard to detect bugs, and being unable to tell at a glance what exact operations are going on in a line of code.
Functions like exp and sin can be defined on numbers, but are also well defined on square matrices. In languages that have automatic broadcasting of functions across arrays, if you write exp(x) and x happens to be a matrix, you won't get the mathematically correct answer. You actually get [exp(xi) for xi in x] which is nonsense.
Having the dot operators make it very easy to tell if a function should be operating on entire arrays or on elements of those arrays. It also enables performance enhancements, because if I write
exp.(x) .+ 1
that will do [exp(xi) + 1 for xi in x] instead of [y + 1 for y in [exp(xi) for xi in x]] which wastes and allocationIndeed it is! The standard IBM punch card had 80 columns.
> and not 100
The standard IBM printer models had 120 print positions.
It's true that one goal may be to pick an important race and try to win it.
Another goal, in my view more important, is to make Fortran more pleasant to use for people/Orgs who need it (there are many) and for people who love it (there are many).
I've found that more often than not, people/teams first like working with a technology, and then come up with technical arguments for why that technology is the best choice. Often the arguments are valid, sometimes they're made up, but ultimately underneath it all you either like it or not and that's all that matters. My goal with Fortran-lang has been to slowly and continuously increase the surface area of Fortran's likability. Fortran is not for everyone, but for people who think it may be, we can work to make it better and more pleasant to use.
As one example, we just released a small library to make high-level HTTP requests from Fortran applications: https://github.com/fortran-lang/http-client. This was a product of one of our Google Summer of Code contributors.
Words of wisdom (:
Maybe it's not the way things should be, but it's common and very human. Sometimes I'll even catch myself retconning explanations for my choices in my own head, despite myself.
And here is the reaction of the fortran-lang.org people to that and later streams where he went on to implement tic-tac-toe in Fortran using for the GUI the C library raylib (https://www.raylib.com/), for which he made his own bindings live on screen: https://fortran-lang.discourse.group/t/tsoding-on-fortran/61...
Matlab in theory has OO, but it's very slow and who bothers to verify that? So practically everything is matrices and there's very little "semantic expressed in code itself" (to paint issues with a broad brush). Also matrix calculations can get botched numerically, particularly matrix exponentials, but the whole culture (that I can't even expunge from my own thinking) is that I have a theorem so tests schmests.
This is somewhat of a link dump since the code is definitely too hard to interpret for someone not familiar but this is me converting some fairly performant Fortran code to python w/ numba at only a 1-2% performance penalty.
Python is horrifically slow, everyone knows that, but if used correctly numpy can even the playing field a great deal. I've seen lots of python/numpy written using nested loops, and this is always going to be really really slow.
http://www.bitsavers.org/components/motorola/6800/cross-asse...
But this was before FORTRAN had strings.. or even bit-wise operators.. But you could read an input line into an array of integers. Then to read each character from this array, you used integer multiplication and division to perform shifting and masking. Although in this version, I can see calls to assembly language helper functions.
Note the Hollerith constants.. (no strings).
When visiting the link, I expected some website written in boring plain text describing its history and docs BUT I was wrong, what a modern website for such a old language. Well done!
Some features were removed from the standard, and modern compilers are much better at detecting errors (and are much stricter than they used to be by default), but all of them have a switch to make them work with random codes from the 1980s.
There is an awful lot of new features on top of that (things like first-class multidimensional arrays language-level parallelism, object orientation, modules, etc), but old software keeps working.
So it is possible for a conforming program to be non-parallelizable, due to holes in the default data localization rules, despite the name of the construct and the obvious intent of the long list of restrictions imposed on code in the construct.
I summarized the two specific problems in https://github.com/llvm/llvm-project/blob/main/flang/docs/Do....
Also, isn't your employer promoting do concurrent as a method of GPU parallelization? Has this been controversial within Nvidia?
Lfortran: Modern interactive LLVM-based Fortran compiler - https://news.ycombinator.com/item?id=37295144 - Aug 2023 (25 comments)
(other thread is arguably better because less generic)
Semi-informed, but serious question: Isn't there any other modern, high-level language that can offer these kinds of optimizations? Preferably in a safe kind of way?
I'm still struggling to understand how Fortran still stays relevant and what could possibly succeed it as a migration (or transpilation?) target with equivalent speed but superior maintainability and safety.
Why is Fortran relevant? Because of that aforementioned history. However, Fortran’s use in numerical software has steadily been declining (e.g., look at the past two decades of TOMS articles).
> Fortran is a relatively small language that is surprisingly easy to learn and use
I suppose you could say the same of C. C is also a small language, but if you don't know your way around the libraries and tooling you're going to have a bad time. I wonder if the same is true for Fortran.
You still need to learn the tooling, but the tooling is actually pretty similar for Fortran/C/C++ (same compiler/linker toolchain). Libraries aren't that much of a thing in Fortran, but to the extent that they are, this again is similar to C/C++.
program hello
! This is a comment line; it is ignored by the compiler
print *, 'Hello, World!'
end program hello
https://fortran-lang.org/en/learn/quickstart/hello_world/1. Models are increasingly becoming much larger projects where flexibility, configuration, setup, are just as important as the actual number crunching that's done. These aren't areas that Fortran is known for.
2. The existence of libraries like Eigen for c++ provide most, if not close to all, of the advantages that Fortran gives for number crunching.
I think it should be corrected to year 3000.
"""
Just an example on how to declaring a couple of input float pointers in a fully optimized way, avoiding aliases and declaring it readonly (if I remember correctly, it's been a few years:
Fortran:
real(32), intent(in) :: foo, bar, baz
C: const float *const restrict foo
const float *const restrict bar
const float *const restrict baz
of course what happens then is that people will do a typedef and hide it away... and then every application invents its own standards and becomes harder to interoperate on a common basis. in Fortran it's just baked in.
Another example: multidimensional arrays. In C/C++ it either doesn't exist, is not flat memory space (and thus for grid applications very slow), or is an external library (again restricting your interop with other scientific applications). In Fortran: integer, parameter :: n = 10, m = 5
real(32), dimension(n, m) :: foo, bar, baz
Again, reasonably simple to understand, and it's already reasonably close to what you want - there are still ways to make it better like memory alignment, but I'd claim you're already at 80% of optimal as long as you understand memory layout and its impact on caching when accessing it (which is usually a very low hanging fruit, you just have to know which order to loop it over)."""
You declare all 3 variables on the same line in Fortran but not in C despite it being supported.
In any case, syntaxic sugar is irrelevant.
Edit: disagree also on sugar being irrelevant. It’s all about where you guide non engineers towards when they learn it. Domain scientists can be astonishingly productive in Fortran thanks to that - to achieve the same in e.g. C++ takes a lot more effort in training and establishing best practices, libraries etc.
typeof(const float *const restrict) foo, bar, baz;
But yes FORTRAN got the defaults correct for it's applications.[1]: https://gustedt.wordpress.com/2014/09/08/dont-use-fake-matri...
It depends on what you mean by that, but VMTs are pretty much that.
size_t n = 10, m = 5;
typeof((*float)[n]) foo, var, baz;
You still need to initialize those, but that's also quite easy, e.g. to allocate it on the heap: foo = malloc(m*sizeof *foo)They are awesome in Fortran because it means that I can (for example) write a function that takes arrays of size N and stack allocate temporaries of size N on entry. I can pass those to other functions etc and they will be freed automatically when I return to my caller. It's actually a really nice feature.
BTW, MSVC never supported C99 or VLAs. Recent versions support C11.
module kind_mod
use iso_fortran_env
integer, parameter :: wp = real64 ! or real32 or real128
end module kind_mod
use kind_mod
real(kind=wp) :: a, b, c
Then you change your entire program to use single, double or quadruple precision by changing the line that sets wp. foo: Box<f32> // or &’a f32 or &f32 if borrowing
Multidimensional arrays: foo: [[f32; M]; N]
(These have flat storage. However I do assume most Rust devs use external libraries, which also have flat storage but the incompatibility issues you mentioned)(The average data science/ML-ish person encounters/figures out custom algorithms maybe three or four times a year, and three of these are fast enough with vectorization contortions. I've had two cases that were recursive and 25X faster in $fast_lang than I could possibly make in Python.)
It is very suitable for it’s domain, but it’s old. Programmers have no attention span and love new and shiny things. They would rather reimplement known solutions in new languages rather than struggle with new problems. So perfectly serviceable code and languages get left behind.
“He who knows only his own generation remains forever a child.“ — Alan Kay, quoting Cicero.
The greatness and wretchedness of Python is "pythonicity". It's very hard to miss the mark with Python (all things considered: life is finite, most people are more like analysts than developers, analysts deliver generally more value per hour than developers, Rust is hard to learn) but you basically need to submit to the "Pythonic" brainwashing -- which includes "anything performance-critical should be written in $fast_lang and then used from Python; but almost nothing is perf critical, and most of what's conceivably needed already exists".
These are all assumptions on my part, and my own biases may have affected my understanding of the problem.
There is quite a lot of discussion on the Discourse group ( https://fortran-lang.discourse.group/ ), which also involves both committee members and ordinary developers.
We regularly address unconstructive behavior. If you or anyone has some feedback how we can run things better, please let me know (you can email me at ondrej@certik.us).
I didn’t intend to say that «not official» means «bad». I learned a lot of stuff from «non-official web pages» over the years.
Yes, I know, I understood that. Thank you. I was reacting to the term official, since it is an interesting question what official means for Fortran, since in a way it was "abandoned", there was the ISO committee as the only official body, but nobody wanted to provide an official place for it on the internet (the most official place was actually the Fortran Wikipedia article). So we volunteered that. In a way, I think it could already be treated as official, or if not, hopefully in a few years most people will treat it as the de-facto official. Kind of like the git webpage has migrated from https://repo.or.cz/ to https://git-scm.com/, but both in a way are unofficial, but the second one is a nice modern webpage and most people liked it and accepted it as official. I don't know the people behind either webpage.
There's two ways to go on this. They could have done the clean GNU style information-only webpage or the hip hyphy pitch.
The second is probably the right move to respond to the complaint "fortran? Isn't that from like the cold war?"
There's usually a small snippet of example code that does something useless on the splash, often with some typing animation. I'm surprised that's not here. Also where's a cute logo? A purple F is insufficient.
I vote for a sea fan. It's resilient, robust, doesn't seem to die, rhymes with fortran, is basically the same color, you can shape it like an F and the double entendre of "C Fan" harkening back to the classic roots, is there as well
In terms of features, it's definitely more modern than C, with generics, move semantics for pointers etc.
In essence: Fortran, please die more quickly.