Live data from Hacker News

Why physicists still use Fortran (2015)

moreisdifferent.com

131–140 of 300 posts

Re: Why physicists still use Fortran (2015)

#131
post #100

One of the key points of the article is that there is a lot of legacy code written in Fortran. As a former high energy physicist, I have an anecdote here that some people might find interesting. There was a library written in Fortran called CERNLIB which included a broad variety of miscellaneous numerical algorithm implementations ( e.g. minimization, integration, special functions, random number generation) [1]. I c…

Huh, funny thing. I had to use a heavy-ion collision simulation program written in fortran, which had to be compiled using a certain compiler implementation (1). After a 2-3 weeks of debugging and trying different compilers in vein, my supervisor had put me on a phone with a guy that was more successful than me and told me which fortran compiler to use. (1) Each compiler gave different results: compilation errors, co…

For every nth performant, tested fortran code, there are 2^n goto ridden legacy codes.

Re: Why physicists still use Fortran (2015)

#132
I think this just shows how scientists don't understand programming. Pretty much every 'advantage' listed for Fortran over C++ could be added to C++ in an afternoon. C++ is an extensible language, you can define your own types and operators, so all the examples can be easily implemented. For some of the examples it's just sad that they were brought up. For example, 'you have to write a loop to allocate an array' should say 'you have to write a function one time to allocate arrays and never write this loop again'.

Re: Why physicists still use Fortran (2015)

#133
post #91

Earlier quoted context omitted.

> Yes, the electronic structure community is rapidly moving away from Fortran. Really? Seems to me that with very few exceptions (e.g. GPAW which is python/C and nwchemEx which I've never heard about until the parent poster mentioned it), electronic structure is pretty much a Fortran bastion. (Source: I did a Phd doing mostly electronic structure calculations, graduated ~5 years ago)

Well, it's moving, not moved yet. New libraries are being written in C/C++, and maybe Python. This includes libraries that should form the foundation of the QM community (matrix/tensor and integral libraries). These are meant to take advantage of newer hardware and libraries which themselves are written in C/C++, and often in a way that is inaccessible from Fortran. The old Fortran code will be around for a long time…

I don't understand why the implementation language of low level libraries should determine a high level language that uses them. In what way are C libraries inaccessible from Fortran, given that it defines interoperability with C?

I'm afraid you need a 10-, or preferably 20-, year perspective, not a week.

Re: Why physicists still use Fortran (2015)

#134
post #120
post #8

Physicists / engineers / mathematicians are the target audience for Fortran. For heavy number crunching it's still quite good, it's people trying to use it for other stuff that causes problems. That said, Fortran really is dying. Scientific code is much larger nowadays with more functionality and scientists want to do everything in one language. C++ and Python are taking over.

Vast majority of scientists is not able to write idiomatic Fortran, yet alone idiomatic C++. Scientific C++ code that didn't have an oversight from a professional C++ developer will be always horrible. Scientific Fortran code written without such oversight can sometimes be bearable. This is perhaps the main advantage of Fortran.

That's a very good point.

Re: Why physicists still use Fortran (2015)

#135
post #89

So the article basically says: 1) Some stuff is already written in Fortran so they don't want to rewrite that. I dig it. 2) It's fast (except C sometimes) but easier to write than c. Like 100x faster than python. I'm not sure about number two. With the gpu processing revolution wouldn't a python/TensorFlow stack be faster than Fortran? Am I missing something? I remember talking to someone who had worked heavily on at…

Dearest me. I hope you're not under the impression that the performant part of your ML code is written in python. Python is the interface to a C++ libary in tensorflow looking at its repo on github. I don't use tensorflow, but if it's anything like numpy and scipy, they are interfaces to C libraries which are extremely performant. If the question is why can't a CFD be in python...and the answer is well, I don't know if anyone has tried it due to your point 1).

Re: Why physicists still use Fortran (2015)

#136
post #107
post #93

Earlier quoted context omitted.

IIRC there was some project doing more or less real-time weather forecasts for small areas (think airports and such) that used deep learning instead of traditional CFD style simulations. They were able to do it with several orders of magnitude less CPU usage than the CFD calculations.

But was it more accurate? Was it for the same purpose? Getting within a few percent of a CFD model might be good enough for industrial use. For studying systems (from the perspective of scientific investigation) it's not even close.

Of course it isn't which is why ML isn't used by us in the computational community...yet.

Re: Why physicists still use Fortran (2015)

#137

Earlier quoted context omitted.

Potentially your "rival groups" will have a long term advantage now though. This might be bad for the graduate students that did the work, but could be good for the professor and group over the next decade. Graduate students need to think in terms of 4-6 years while forward looking professors might want to think in terms of 5-15 years.

I do wonder about this a little, but so far I haven't seen anything implemented elsewhere in my field that hasn't been possible to do with our existing code. In fact, I have spent a fair bit of my time replicating others' results with our code and getting sub-percent level agreement. However, I guess one drawback is that a lot of the things we currently implement are all written from scratch (for very standard things…

I use Python for most things and write C extensions which can use OpenMP or CUDA and which are hooked in via Cython for the slow parts. Find this works well, although it can lead to you duplicating things unnecessarily sometimes (needing a C function to be callable by Python requires you to write a wrapper for it).

Re: Why physicists still use Fortran (2015)

#138
post #98

Earlier quoted context omitted.

> and the original author continues to maintain it. What's the plan when they retire?

My hope is to release it in a form that can be compiled by open-source tools.

A problem for computational science is people care about their publications more than people being capable of reproducing their work. The funny thing is an open source code is a sure way to attain a legacy.

Re: Why physicists still use Fortran (2015)

#139
post #100

One of the key points of the article is that there is a lot of legacy code written in Fortran. As a former high energy physicist, I have an anecdote here that some people might find interesting. There was a library written in Fortran called CERNLIB which included a broad variety of miscellaneous numerical algorithm implementations ( e.g. minimization, integration, special functions, random number generation) [1]. I c…

Can't you just recompile with a newer compiler?

Re: Why physicists still use Fortran (2015)

#140

I think this just shows how scientists don't understand programming. Pretty much every 'advantage' listed for Fortran over C++ could be added to C++ in an afternoon. C++ is an extensible language, you can define your own types and operators, so all the examples can be easily implemented. For some of the examples it's just sad that they were brought up. For example, 'you have to write a loop to allocate an array' shou…

I don't think that's the case, seems a little too extreme to think that. I believe the central point of someone not directly enrolled with programming as an actual job (or as a hobby taken seriously) picking Fortran over C/C++ has to do with the features it has out-of-the-box, or at least that are more apparent from the surface of language knowledge. Even if it takes one afternoon to implement a certain feature, would scientists WANT or NEED to do that?

Don't get me wrong, this is probably an opinion I would defend if it were exclusively related to programmers being "too lazy to learn a new language", but this is a different learning purpose.

Post reply on HN