
Fortran is still a thing (2017) - aphextron
https://hackernoon.com/fortran-is-still-a-thing-fc84df4cf638
======
romwell
I'm writing this comment while compiling OpenMP Fortran code that models
photoresist behavior in chip lithography.

Could've written the same in C++, but for things like that, Fortran is more
natural (its math syntax is Matlab-ish, although, of course, it's more correct
to say that Matlab's syntax is Fortran-ish).

Anecdote: I'm starting to learn Rust, and just for fun, wrote a dumb single-
loop Riemann sum to compute pi in Rust and Fortran (as the area of the circle)
- and Fortran code ran 2x faster. When the computation time is measured in
_days_ , this kind of difference matters.

~~~
philipkglass
Most people I know who use Fortran for long-running HPC jobs compile it with
Intel's ifort. Are you using ifort (or another high-performance commercial
compiler)? I ask because Intel's compilers can produce binaries with
significantly better runtime performance than GNU or LLVM. AFAIK Rust relies
exclusively on LLVM.

I'm wondering if the slowdown is mostly about the very mature optimizing
compilers available for Fortran or if it's intrinsic to Rust's language
design. (I've never written any Rust myself.)

~~~
romwell
> Are you using ifort (or another high-performance commercial compiler)?

Yes, PGI Fortran.

>I'm wondering if the slowdown is mostly about the very mature optimizing
compilers available for Fortran or if it's intrinsic to Rust's language
design.

I wonder about that too. Time will tell!

~~~
renox
I think that rust doesn't have (doesn't want to have) -ffast-math.

~~~
steveklabnik
We tend to shy away from flags like this that change behavior globally. I
wonder if it could be done similar to Wrapping, where you opt into the
semantics on a specific basis. I know there’s been _some_ discussion about
fast-math but I don’t remember the details.

------
riskneutral
“After careful deliberation, NASA has decided to cancel the High Performance
Fast Computing Challenge competition it announced six weeks ago.“

The canceled competition would have involved running contestants’ code on a
NASA supercomputer. The only logical reason I can think of for restricting the
language to Fortran would be security concerns. Limiting submissions to one,
well-understood and possibly safer language would limit the attack surface.
But they canceled the whole thing anyway, again probably due to security
concerns.

In any case, yes Fortran codes are still around. The BLAS and LAPACK libraries
are implemented in Fortran, which means that Fortran code is at the
foundations of a ton of numerical software (e.g. MATLAB, NumPy, R, probably
Julia, probably a lot of neural net libraries, etc). Any new HPC chip always
comes with an optimizing Fortran compiler, we saw this with Nvidia GPUs for
example). There are two reasons why Fortran is still used: (1) decades of work
has gone into implementing numerical optimizations in these libraries. I am
not just talking about machine-oriented optimizations, I am referring to
higher level mathematical tricks that require deep domain specific expertise
in things like linear algebra as well as a very strong handle on managing
floating-point error. Extensive testing has gone into those libraries, and the
continued validity of that testing depends on the language standard, compiler
implementation, and compiler optimization levels. There is simply no value in
rewriting all of this code in another language, given the enormous cost and
risk. (2) older professors just prefer Fortran because they know it, and grad
students have to use it because their profs use it, and front-line experts
have to use it if they want to work on making enhancements to the imoortsnt
existing Fortran libraries.

~~~
busterarm
Edit: apparently I believed some bullshit :P

~~~
twic
Wait what? Which BSD? Which bootloader? Which Fortran? I would be pleasantly
astounded if this was true.

~~~
groovy2shoes
The FreeBSD bootloader (on several platforms, at least, including i386 and
amd64) is written largely in a dialect of Forth called Ficl [1]. Perhaps GP
got "Forth" and "Fortran" mixed up?

Looks like the Forth loader is going to eventually be replaced by a Lua one,
though [2].

[1]:
[https://github.com/freebsd/freebsd/tree/release/11.1.0/sys/b...](https://github.com/freebsd/freebsd/tree/release/11.1.0/sys/boot/forth)

[2]: [https://lists.freebsd.org/pipermail/freebsd-
current/2018-Feb...](https://lists.freebsd.org/pipermail/freebsd-
current/2018-February/068464.html)

~~~
busterarm
Yeah, I have a shitty memory. Thanks.

~~~
twic
Fortran is a great language. Forth is also a great language, and much more
suitable for bootloaders!

------
cbcoutinho
Fortran also has an interesting pattern of dealing with memory, in that
everything is passed by reference between functions, yet there is no need to
manually manage memory like you would need to in C/C++.

I've never seen code where you need to deal with malloc et al. You are able to
create dynamically allocated arrays or let arrays be sized on evocation, but
I've never needed to deallocate or free memory at the end of a
function/subroutine.

~~~
gnufx
This comes up most times Fortran is mentioned, but it is not true that Fortran
passes by reference, and optimizations rely on that fact. The rules around
storage association are typically referred to as pass by value-return or copy-
in/copy-out.

It's misleading to imply you never have to free memory. The NAG compiler
runtime includes Boehm's conservative garbage collector (or did, last I
checked) for a reason.

------
aneutron
There's a passage in the article that I either misunderstood, or the author is
somewhat being agressive/hostile towards computer scientists and engineers:

> Its users are scientists and engineers; not computer scientists and software
> engineers, but the real ones.

Software engineers are in fact "real" engineers. Who do you think writes the
compilers for Fortran.

Edit: Read the article twice. The author is Ukranian. Either it's a linguistic
mistake, or he really has some sort of prejudice against Software Engineers,
in which case I find that sad.

~~~
ztjio
It’s a common, and I believe very fair criticism of the title “Software
Engineer” that there is nowhere near the rigor and requirements that “real”
engineers (structural engineers, mechanical engineers) must deal with. There’s
no licensing. No proof you know what you’re doing. And sure, that’s probably
because mostly software isn’t responsible for life or death situations like
bridges and buildings are constantly.

But honestly, the term “Software Engineer” is a farce at best.

So maybe the author is in the camp that worries too much about meaningless
titles.

~~~
aneutron
I respectfully disagree with your point of view.

There are certain things that are very ... softwar-y, and only engineers who
know how to handle software well can come up with.

Google's Percolator, the plethora of Apache data crunshing stacks, whole
paradigm shifts like Object Storage, virtualization, and so on. Some of these
are the equivalent of Burj Khalifa. Not anyone, or any team for that matter,
can build them correctly.

Which is why I think the term Software Engineer and the concept of software
engineering is very justifiable.

Yes, I think it is a form of engineering, in the sense that it a tangible
discipline that produces artifacts that are useful to humans and that require
very specific scientific knowledge and a minimum of academic background.

Just my two cents on the matter.

~~~
andrewflnr
"Software engineering" is definitely a real thing. The _vast_ majority of
people who call themselves "software engineers" aren't doing it. They're doing
the equivalent of cabinetry at best.

------
randyzwitch
As long as re-using fast FORTRAN code is better than re-writing it all
yourself, people are going to use FORTRAN.

~~~
bigger_cheese
This is pretty much the reason at my work there is so much Fortran code
already written a lot of it dates back to the '80's. This is mostly fluid
dynamics and thermo stuff the math hasn't changed in decades so there is
little impetus to rewrite.

I am a Materials engineer I work with Chem/mech engineers on process modelling
and simulation in an industrial plant.

You can kind of tell the vintage of programs around here by looking at the
languages used.

There are Fortran programs from 80's to 90's.

From early to late 90's there are C++ programs.

Then from late 90's to mid 2000's there are VB6 programs (for a while our work
was big on Microsoft, Visual Basic and Access was everywhere - boy did we get
burned by that).

From mid 2000's to early 10's there are java programs.

Python seems to be goto nowadays.

------
King-Aaron
My father is a systems engineer with [large multinational company] who
primarily does HMI controllers for the oil and gas industry. A lot of their
products are written in sturdy languages like Fortran and it surprises me when
people dismiss "older" languages like these.

------
hprotagonist
Considering how much scientific code I write in python, I probably should drop
a month or so on rewriting the slow bits in fortran to learn the language.

~~~
marmaduke
Learning Numba will likely be a better pay off.

~~~
twic
Maybe. But basic Fortran is pretty easy to learn - it's a somewhat warty but
very simple language. It might well be the case that spending three days
learning it lets you spend two days writing some straightforward but really
fast code.

~~~
marmaduke
For those already working in Python, Numba is a 2 hour investment, that pays
off with similar speed as Fortran code except no new syntax, semantics,
compiler or FFI to bother with.

------
Something1234
Does anybody here have any advice on reading and understanding old fortran77
code written around the year 2000? We need to make it faster. Any advice on
visualizing the flow would also be helpful, as it makes use of goto
extensively.

~~~
celias
[https://stackoverflow.com/questions/3161564/how-can-i-
visual...](https://stackoverflow.com/questions/3161564/how-can-i-visualize-
fortran-90-or-later-source-code-e-g-using-graphviz)

has some suggestions. I haven't tried any but am thinking of using Doxygen as
described for some old Fortran77 code with lots of gotos since Understand is
well outside of our budget.

You're probably aware of this, but our biggest speed gains in some code we
ported from DEC Fortran to gfortran was vectorizing loops. Best of luck.

------
PredictorY
Of course FORTRAN still matters. Somebody has to write real neural network
code. We can't all be Python script kiddies!

~~~
CuriouslyC
What you call being a script kiddie I call working at a higher level of
abstraction.

~~~
Koshkin
I don't know about that. Fortran is no less abstracted from hardware than any
other programming language (including Python).

------
John_KZ
>Fortran is simple enough for domain specialist to write bad code and achieve
good results with it.

I don't understand the idea behind this statement. Nobody but the specialist
can produce efficient algorithms to solve a domain-specific problems, and
Fortran isn't any simpler than C.

If the writer argues that the implementation of the algorithm is bad when
written by non-programmers, then you might be surprised to find out that it's
usually the opposite.

Computers are still incredibly simple in their basic design, so unless you
hire a hardware-specialist programmer (like an x86 or CUDA/OpenCL specialist
with background knowledge of the chips you'll use), knowing basic latencies in
RAM operation, L-cache sizes and the ticks required for executing basic
operations like floating point additions and XORs, is enough for the
specialist to write better code, because he understand the algorithm, he can
tailor it the hardware, and he actually cares, unlike most
programmers/software engineers.

Knowing how to use hundreds of libraries might be helpful when you're writing
long "consumer" applications, but this kind of expertise has nothing to do
with scientific and high-performance programming.

------
jnaiz
Besides convenient syntax for numerical computing, Fortran also contains quite
some functionality for writing safe code, e.g., bounds checking for arrays,
strict typing of function arguments (unlike C) and 'pure' methods.

~~~
Koshkin
> _bounds checking_

Wouldn't this incur a performance penalty?

> _(unlike C)_

C is also strict in this respect.

------
code_duck
I know an acquaintance who works at a federal lab here in NM, writing Fortran
that runs on a 20,000 CPU super computer to support scientific research. I
think he makes something like 200k.

------
ktaylor
My friend (PhD in Physics) runs a small hedge fund in Chicago. A team of about
6 traders and quants. They have been doing all their fairly sophisticated
quantitative models in Fortran for the past 15 years.

He is currently learning R, though, and so Fortran at this shop may have its
days numbered.

------
Koshkin
Forget FORTRAN: [http://mmbasic.com/](http://mmbasic.com/)

~~~
romwell
And this is relevant.. how?

