TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Why physicists still use Fortran

205 点作者 urs超过 8 年前

26 条评论

bmh100超过 8 年前
Fortran is an excellent choice for numerical computation. Its non-aliasing assumption allows for compiler optimizations that dramatically speed up computations. It is even easy to get started with concurrent code through OpenMP. When I need to run a simulation or a discontinuous optimization algorithm, I turn to Fortran first.<p>Here are some resources I have collected over the years.<p>&quot;Introduction to Modern Fortran&quot; (Fortran 2003): <a href="http:&#x2F;&#x2F;people.ds.cam.ac.uk&#x2F;nmm1&#x2F;Fortran&#x2F;index.html" rel="nofollow">http:&#x2F;&#x2F;people.ds.cam.ac.uk&#x2F;nmm1&#x2F;Fortran&#x2F;index.html</a><p>Fortran Wiki: <a href="http:&#x2F;&#x2F;fortranwiki.org&#x2F;fortran&#x2F;show&#x2F;HomePage" rel="nofollow">http:&#x2F;&#x2F;fortranwiki.org&#x2F;fortran&#x2F;show&#x2F;HomePage</a><p>List of Fortran tutorials: <a href="http:&#x2F;&#x2F;www.fortran.com&#x2F;the-fortran-company-homepage&#x2F;fortran-tutorials&#x2F;" rel="nofollow">http:&#x2F;&#x2F;www.fortran.com&#x2F;the-fortran-company-homepage&#x2F;fortran-...</a><p>Fortran vs. C: <a href="http:&#x2F;&#x2F;www-cs-students.stanford.edu&#x2F;~blynn&#x2F;c&#x2F;fortran.html" rel="nofollow">http:&#x2F;&#x2F;www-cs-students.stanford.edu&#x2F;~blynn&#x2F;c&#x2F;fortran.html</a><p>Fortran&#x27;s influence on C&#x27;s &quot;restrict&quot; keyword: <a href="http:&#x2F;&#x2F;www.drdobbs.com&#x2F;the-new-c-it-all-began-with-fortran&#x2F;184401313" rel="nofollow">http:&#x2F;&#x2F;www.drdobbs.com&#x2F;the-new-c-it-all-began-with-fortran&#x2F;1...</a>
评论 #13207973 未加载
评论 #13208051 未加载
评论 #13209425 未加载
评论 #13207780 未加载
评论 #13208157 未加载
评论 #13208619 未加载
评论 #13220559 未加载
Animats超过 8 年前
Fortran is still better at multidimensional arrays. Other than Matlab, few other languages do multidimensional arrays at all. C-derived languages use arrays of arrays, and use templates, macros, or objects for multidimensional arrays. Fortran optimizers have lots of multidimensional array-oriented optimizations which other compilers usually lack.<p>I tried to talk the Go and Rust people into putting in multidimensional arrays, but the discussion degenerated into bikeshedding, with arguments for fancy but slower representations so you could take arbitrary N-dimensional slices from a multidimensional array.
评论 #13208193 未加载
评论 #13207627 未加载
评论 #13209595 未加载
评论 #13207921 未加载
评论 #13207773 未加载
评论 #13207766 未加载
评论 #13209636 未加载
评论 #13207683 未加载
srean超过 8 年前
Guy Steele and his group had a really interesting thing going with the language Fortress (name is a nod to Fortran of course, but fortified). It was meant for high productivity as well as high speed (petaflops range). It got shelved after Oracle bought Sun. It was one of the three languages seeded by DARPA funding for high productivity computing<p><a href="https:&#x2F;&#x2F;java.net&#x2F;projects&#x2F;projectfortress&#x2F;pages&#x2F;Home" rel="nofollow">https:&#x2F;&#x2F;java.net&#x2F;projects&#x2F;projectfortress&#x2F;pages&#x2F;Home</a><p><a href="https:&#x2F;&#x2F;blogs.oracle.com&#x2F;projectfortress&#x2F;entry&#x2F;fortress_wrapping_up" rel="nofollow">https:&#x2F;&#x2F;blogs.oracle.com&#x2F;projectfortress&#x2F;entry&#x2F;fortress_wrap...</a>
评论 #13210738 未加载
评论 #13208427 未加载
hzhou321超过 8 年前
It is simply due to apprenticeship. Physicists do research, and their code is research code. Like most other research, the research code is maintained and used in-house. As most in-house non-shared code (in any language), it is impenetrable unless you take apprenticeship. The masters are typically old and FORTRAN is their language and it is the only choice for the apprentices. Once the apprentices graduate and become masters themselves, they further developed their own in-house code and it is inevitably in FORTRAN too. As any over-developed code, it is too expensive to migrate even when the new master recognize the shortcoming. The bottom line, FORTRAN is not bad once you are familiar with (and invested in) it, so FORTRAN persists over another generation of apprentices ...<p>However, there is slight change. The new generation of masters often do know other languages, so they sometime tolerate their new apprentices to use other language and still able to teach them. So at this point, by far, not all physicists use FORTRAN.<p>FORTRAN will die out, just takes time.<p>One of the sticking point is the library BLAS&#x2F;LAPACK. It is in FORTRAN. Or more precisely, its interface is in FORTRAN. I don&#x27;t foresee this will change for a long time. So FORTRAN will be like COBOL, it will persist even when no-one really use it anymore.
评论 #13209272 未加载
评论 #13210459 未加载
评论 #13210536 未加载
评论 #13209623 未加载
supergarfield超过 8 年前
&gt; Interestingly, C&#x2F;C++ beats Fortran on all but two of the benchmarks, although they are fairly close on most.<p>Unless I missed something, this directly contradicts the quotes benchmark source[1], where C beat Fortran on all tests except one (where they were tied), and usually by a wide margin. Plus I believe gcc usually produces slower code than Intel&#x27;s compilers (at least for C), so it&#x27;s not clear that C-gcc and Fortran-Intel is a fair comparison.<p>But beyond that, I&#x27;m always confused as to why there is a significant difference. I would expect two compiled languages with reasonable compilers to perform almost exactly the same when they&#x27;re doing nothing but arithmetic operations, since those are almost entirely determined by the CPU, not the cleverness or speed of the standard library algorithms. Can anyone enlighten me?<p>[1] <a href="https:&#x2F;&#x2F;benchmarksgame.alioth.debian.org&#x2F;u64q&#x2F;fortran.html" rel="nofollow">https:&#x2F;&#x2F;benchmarksgame.alioth.debian.org&#x2F;u64q&#x2F;fortran.html</a>
评论 #13208006 未加载
评论 #13208001 未加载
评论 #13207745 未加载
评论 #13207583 未加载
评论 #13208322 未加载
评论 #13207662 未加载
评论 #13207570 未加载
dfgasfjhjhsdojj超过 8 年前
1. A program from 30 years ago will compile and run.<p>2. As a research student your first program is likely to be a F77 program written by your professor or an older colleague.<p>3. A library from 30 years ago can be easily wrapped into a modern program, compiled and run.<p>4. Arrays are really the most important thing for this sort of programming and since F90 array level operations have been baked into the language.<p>5. It is fairly trivial to write fast Fortran.<p>6. Fortran is much easier to use for numerical stuff than c++
troymc超过 8 年前
When I was doing my graduate studies in astrodynamics (spacecraft trajectory design) at Purdue University circa 2003, we worked closely with the Jet Propulsion Lab (JPL) and got to use a lot of their excellent astrodynamics code (used for missions like Galileo and Cassini). It was all Fortran.<p>I heard that there was an effort at JPL to convert over to using Python. I&#x27;m not sure how that went. Maybe they were just writing Python bindings for their Fortran code? I know that much of SciPy consists of Python bindings for Fortran and C code [1].<p>The software I used to do &quot;nonlinear programming&quot; (i.e. parameter optimization), called NPOPT, was also written in Fortran.<p>[1] <a href="https:&#x2F;&#x2F;www.scipy.org&#x2F;scipylib&#x2F;faq.html#how-can-scipy-be-fast-if-it-is-written-in-an-interpreted-language-like-python" rel="nofollow">https:&#x2F;&#x2F;www.scipy.org&#x2F;scipylib&#x2F;faq.html#how-can-scipy-be-fas...</a>
评论 #13208463 未加载
ChuckMcM超过 8 年前
<i>&quot;Early Fortran (designated in allcaps as FORTRAN)&quot;</i> that would be because it is an acronym &quot;FORmula TRANslator&quot;.<p>Fortran continues to do that well. And as the article mentions scipy doesn&#x27;t run as fast.<p>The logical successor to Fortran was APL (Arithmetic Programming Language) but its notation really killed it.<p>The properties that keep Fortran rolling (easy to start using, effective in translating formulas into computation) persist.
评论 #13208117 未加载
评论 #13207332 未加载
radioactivist超过 8 年前
The author is I think being a bit unfair to C++ when it comes to matrix&#x2F;array handling. Their example of things that would be difficult to do in C&#x2F;C++:<p>A = B<p>A = 3.24 * B<p>C = A * B<p>B = exp(A)<p>norm = sqrt(sum(A * * 2))<p>Quoting:<p>&quot;Similar C&#x2F;C++ code simply does not exist ... Having to use libraries instead of intrinsic functions means the resulting code is never as neat, as transferable, or as easy to learn.&quot;<p>While this statement is true, I think strongly undersells how well these kinds of libraries can be &quot;baked&quot; into C++ through operator overloading, templating, etc. See for example, the Eigen library [<a href="http:&#x2F;&#x2F;eigen.tuxfamily.org&#x2F;" rel="nofollow">http:&#x2F;&#x2F;eigen.tuxfamily.org&#x2F;</a>].
评论 #13209125 未加载
评论 #13208990 未加载
评论 #13208557 未加载
pif超过 8 年前
&gt; If a function that takes a ‘real’ is fed a ‘const real’, it will return an error. It is easy to imagine how this can lead to problems with interoperability between codes.<p>What&#x27;s he talking about? This is wrong!
spapas82超过 8 年前
One interesting fact that supports the point of the article is that Matlab is actually using the Fortran code for its implementation of special functions <a href="https:&#x2F;&#x2F;www.mathworks.com&#x2F;matlabcentral&#x2F;fileexchange&#x2F;6218-computation-of-special-functions" rel="nofollow">https:&#x2F;&#x2F;www.mathworks.com&#x2F;matlabcentral&#x2F;fileexchange&#x2F;6218-co...</a>.<p>The amount of existing scientific code in Fortran is huge and there&#x27;s a chicken and egg situation (new code uses&#x2F;extends old code so new code will <i>also</i> be in Fortran) that will lead to further increasing it!
评论 #13207581 未加载
jstewartmobile超过 8 年前
It&#x27;s funny that someone has to write an article to defend modern FORTRAN to people who write in <i>JavaScript</i>, which is the best proof we programmers have of entropy.
评论 #13207943 未加载
PaulHoule超过 8 年前
Even if you are using python, R or java you are still best off linking to matrix subroutines in fortran if you want to solve or diagonalize, get eigenvalues and such. This is not just about raw performance but also correctness, ecology of roundoff errors, etc.
评论 #13207540 未加载
评论 #13207618 未加载
pducks32超过 8 年前
As a physicist please have faith in us. We don&#x27;t all use Fortran. I use Ruby as much as possible and it&#x27;s fun because it forces me to write libraries that mimic ones that are found in other languages. So I end up learning a lot.
评论 #13207969 未加载
评论 #13208333 未加载
spullara超过 8 年前
When I was in undergrad I did some computer simulation work for my professor. He programmed in FORTRAN while I had been trained in C&#x2F;C++. I did my simulations in C&#x2F;C++ and I also wrote some libraries for his FORTRAN code so he could have more dynamic configuration files. At the time I thought that FORTRAN was an anachronism and was surprised that it was still being used in physics.<p>This was 1992.
santaclaus超过 8 年前
What ever happened to the effort to bring Fortran to LLVM (from Los Alamos I think)?
评论 #13209739 未加载
syphilis2超过 8 年前
I&#x27;ve been looking for a Matlab alternative and been disappointed with either the performance or the syntax of Octave, Python, and Julia. I&#x27;d known Fortran had modern features and updates every few years, but never tried to pick it up since the excitement seems to be elsewhere. This article is convincing that Fortran is worth trying out.
评论 #13207786 未加载
评论 #13207741 未加载
hcrisp超过 8 年前
FORTRAN may be faster but one graph shows Python recently overtaking it in mentions of Astronomy papers [0].<p>[0] <a href="https:&#x2F;&#x2F;mobile.twitter.com&#x2F;astrofrog&#x2F;status&#x2F;787007261877166080" rel="nofollow">https:&#x2F;&#x2F;mobile.twitter.com&#x2F;astrofrog&#x2F;status&#x2F;7870072618771660...</a>
评论 #13207480 未加载
Asooka超过 8 年前
I have one issue with the article. The way to dynamically allocate a multidimensional array in C is the following:<p><pre><code> size_t m, n; ... set m and n ... int (*a)[m][n]; a = (int(*)[m][n])malloc(sizeof(*a)); </code></pre> Edit: and you MUST NOT REUSE OR OTHERWISE CHANGE m and n FOR THE ENTIRE LIFETIME of the array, because bad things will happen.<p>And you access it via<p><pre><code> (*a)[x][y] </code></pre> And you free it with<p><pre><code> free(a); </code></pre> And if you want to pass it to a function:<p><pre><code> void do_with_array(void* raw_array, size_t m, size_t n) { int (*array)[m][n] = (int(*)[m][n])raw_array; ... do whatever ... } do_with_array(a); </code></pre> And I&#x27;d rather do it in Fortran, but if you ever need to do it <i>properly</i> in C (i.e. without using array of pointers) - now you know.
评论 #13208484 未加载
评论 #13210800 未加载
评论 #13208413 未加载
评论 #13211561 未加载
theden超过 8 年前
My reason for using fortran (when I was studying physics) was that when going through the university library looking for a computational physics textbook, I couldn&#x27;t find one that wasn&#x27;t in fortran—actually I found one (computational physics, Giordano &amp; Nakanishi) but it wasn&#x27;t enough to get by. Fortunately I already knew fortran, because all the legacy textbooks+journals were written in the language.
SFJulie超过 8 年前
Just in case you want to use fortran code in python here is the scipy HOWTO<p>Still up to date. <a href="https:&#x2F;&#x2F;docs.scipy.org&#x2F;doc&#x2F;numpy-1.10.0&#x2F;user&#x2F;c-info.python-as-glue.html" rel="nofollow">https:&#x2F;&#x2F;docs.scipy.org&#x2F;doc&#x2F;numpy-1.10.0&#x2F;user&#x2F;c-info.python-a...</a>
orionblastar超过 8 年前
Interesting as I learned WATFIV on an IBM 370 with JCL&#x2F;JECL under DOS&#x2F;VSE.<p>There is an Openwatcom project that does C and Fortran but I think it is Fortran 77.<p>I had Fortran and COBOL on my resume but most jobs I took used Visual Basic.
jheriko超过 8 年前
some of the information here is a bit wrong. the idea that const is weaker than parameter is true, but not for the reasons given. any function taking a float, int etc. in C++ can also take a const float or const int.<p>its also unfair to suggest that C&#x2F;C++ is as fault with not allowing a = b * c with array types. this is a failing of the standard library and easily fixed... operator overloading lets you create exactly this functionality, and std::valarray already does this for a lot of what you get in Fortran...
评论 #13209464 未加载
tomw2005超过 8 年前
In our company we still us FORTH because the timing of each command is well known.
davidf18超过 8 年前
It seems like a number of R packages use Fortran. I&#x27;m on Mac and it needs to Fortran compiler to be installed so that at least some of the R packages can be compiled when doing updates.
评论 #13207906 未加载
smegel超过 8 年前
&gt; Note that Python, which is the darling of computer scientists<p>Actually physical scientists love Python as much as they love Fortran. It a lot of cases, it is the only two languages they know.