现代语言与FORTRAN的优点?

发布于 2024-09-15 06:53:17 字数 336 浏览 6 评论 0原文

我最近一直在使用 FORTRAN 77,虽然一开始我有所保留,但现在我看到了该语言的一些优秀品质。它是:

  • 简单易学(没有面向对象或函数式编程的复杂性)
  • 易于阅读
  • 数字运算速度极快

这些品质对于非程序员工程师和科学家来说自然具有吸引力,他们只是想要一种让计算机快速给出答案的方法。但基于它的年龄和一些基本假设,它有很多局限性。我对非程序员能否轻松理解 Fortran 更高版本的一些附加功能表示怀疑。

是否有一种现代语言能够像 FORTRAN 一样简单、数学应用同样快速且限制更少?或者是答案 Fortran 90, 95, 2003 。 。 。 ?

I've been working with a lot of FORTRAN 77 lately, and though I had reservations at first, I now see some great qualities of the language. It is:

  • Simple to learn (no object-oriented or functional-programming complications)
  • Easy to read
  • Blazing fast at number-crunching

Those qualities are naturally attractive to non-programmer engineers and scientists who just want a way to make a computer give answers quickly. But it has a lot of limitations based on its age and some of its basic assumptions. I'm skeptical about how easily non-programmers can understand some of the added capabilities of later versions of Fortran, as well.

Is there a modern language that is as straightforward as FORTRAN, just as fast for mathematical applications, and less limited? Or is the answer Fortran 90, 95, 2003 . . . ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(12

我偏爱纯白色 2024-09-22 06:53:18

我最近使用了很多 Matlab,今天我可以看到它的好处。是的,它很慢,因为它是一种解释语言,但它的矩阵算法很快。我正是因为这种行为才喜欢它。 for 循环的缓慢性和矩阵运算的性能鼓励您以更数学的方式思考,而不是坚持面向循环的编程。但我可以同意Matlab可以被驳回,因为它不开放。

目前我很期待 Julia 语言。它深受 Matlab 的启发,只是它确实希望速度更快。它还具有静态类型,这也是一个很大的优势。但 Julia 还很年轻,所以不要指望它已经满足您的所有要求。

I've worked recently with a lot of Matlab, and I can see it's benefits today. Yes is is slow because it is an interpreted language, but it's matrix algorithms are fast. And I like it exactly because of that behavior. The slowness of the for loops and the performance of the matrix operations encourage you to think in a more mathematical way instead of sticking to loop oriented programming. But I can agree that Matlab can be dismissed, because it is not open.

Currently I am looking forward to the Julia language. It is heavily inspired by Matlab except that it does want to be fast. Also it has static types which is also a very big advantage. But Julia is still very young, so do not expect that does already fulfill all your requirements.

幽蝶幻影 2024-09-22 06:53:18

简单易学(没有面向对象或函数式编程的复杂性)

易于阅读

数字运算速度极快

像 C。

购买 C 语言的数字食谱。这几乎以清晰、可读的风格涵盖了所有基础知识。

http://www.amazon.com/Numerical-Recipes-Art-Scientific-Computing/ dp/0521431085

Simple to learn (no object-oriented or functional-programming complications)

Easy to read

Blazing fast at number-crunching

Sounds like C.

Buy Numerical Recipes in C. That pretty much covers all the bases in a clear, readable style.

http://www.amazon.com/Numerical-Recipes-Art-Scientific-Computing/dp/0521431085

悲欢浪云 2024-09-22 06:53:18

我假设您正在考虑编写用于解决特定问题的小型专用程序。在这种情况下,如果 OO 的复杂性确实让您感到困扰,我只会编写一个 C# 或 Java 应用程序,而不使用 OO。现在 Visual Basic 应该也非常快了。

如今,几乎所有编译语言在数学上都很快,所有操作都是在数学协处理器上完成的——所以除非你发现某些语言特别缺乏,否则我不会让任何语言的“数学速度”太困扰我。

I assume you are considering small, dedicated programs written to solve specific problems. In that case, if the complexity of OO really bothered you I'd just write a C# or Java app and not use OO. Visual Basic should be pretty darn fast these days as well.

Nearly all compiled languages will be mathematically quick these days, all operations are done on the math co-processor--so unless you have found some language to be particularly lacking I wouldn't let any languages "math speed" bother me much.

只是我以为 2024-09-22 06:53:17

或者是答案 Fortran 90, 95, 2003
。 。 。 ?

是的。大多数编译器支持的 Fortran 95 就是您正在寻找的语言。然而,Fortran 2003 有一些可能有用的重大增强功能(除了从您的角度来看不必要的 OOP 支持)。 Fortran 2003 标准的编译器支持

Or is the answer Fortran 90, 95, 2003
. . . ?

Yes. Fortran 95 supported by most compilers is the language you are looking for. However Fortran 2003 has some major enhancements (besides unnecessary from your point of view support of OOP) which might be useful. Compiler Support for the Fortran 2003 Standard.

故乡的云 2024-09-22 06:53:17

好吧,我是一名非程序员工程师(无论这意味着什么;我认为这意味着与计算机科学研究没有太多接触)并且......

部分是 JasonFruit 对 S. Lott 答案的评论的延续:

是的,从 F90 到 2003,该标准添加了相当多的功能。但是,如果可以这样称呼它(我想不出或关心更合适的词),“问题”是:很多使用Fortran的人都不知道它,保存着他们需要的基本功能。在某种程度上,这是一种祝福和诅咒。他们从来没有学过它,也从来没有读过关于它的书——他们只是边走边学。这种方法肯定可以工作一段时间(如果你简单地构建你的程序,就像许多人几个世纪以来所做的那样,并且有一定的精神纪律,这种方法可以持续一生/你的整个职业生涯),但过了一段时间它就开始了以显示其缺点。例如,尝试按照 comp.lang.fortran 上最新功能的一些讨论来测试您的知识。

因此,带一本好书(许多人推荐给初学者三本中的一本;a)查普曼·J·斯蒂芬的 b)缅因州,或 c)梅特卡夫,里德和科恩(称为“MRC书”) - 之后有很多“更模糊”的特征不仅变得更清晰,而且变得“明显”(在某种程度上;这确实是更好的方式 - 为什么我以前这样做......?)。

这就解决了这个问题。现在,另一个问题——肯定会出现——Fortran 如今是否值得学习? (总是如此,相信我:)。这已经被讨论过很多次了,所以我直接访问 我自己的帖子关于上述内容,以及我的旧帖子(您必须向下滚动一点),与此处提到的其他一些语言相比,它考虑了一些问题。

最后一件事,在大多数情况下,在某种程度上是所有这些问题的原因,是人们对 Fortran 的看法,重点是意见!总的来说(我们可以把这个论坛作为我们分析的一个很好的样本)是它不太好。很少有人喜欢[在这个论坛上关注标记为 fortran 的问题一个月,你很快就会知道他们是谁。顺便说一句,从你的名字出现的频率来看,你很快就会成为俱乐部的一员:)],大多数人要么漠不关心,有些人讨厌它,纯粹出于无知(经常使用 F66 与当今的语言进行比较),有些是出于自身原因。现在,如果我们把这些与一般人群进行比较,简单算一下,结果必然会很糟糕。如果你只采访传统工程师,结果会大不相同。

啊啊啊啊啊,就这样了。

哦,还有一件事 - Fortran 现在/过去仍然主要针对工程师,而不是数学家。它更适合求解大型系统,然后将 pi 计算到十进制小数。我不知道你的问题是错字还是故意的。对于纯粹的数学应用(在数学家的经典意义上),我(如果我是该领域的一部分)可能会选择,我不知道,Mathematica?或者 Pascal(不知道为什么它总是 Pascal;但它似乎非常受那些家伙的欢迎)。

Well, I'm a non-programmer engineer (whatever that means; I gather it means not having much contact with computer sciences studies) and ...

Partically in continuation to JasonFruit's comment on S. Lott's answer:

Yes, the standard has added quite a few features from F90 to 2003. But the "problem", if one can call it such (I cannot think or care to of a more appropriate word) is that many people who use Fortran do not know it, save the basic features they need. It is a blessing and a curse all in one, in a way. They have never learned it, never read a book on it - they kinda just picked it up as they went along. That way can certainly work for a time (if you structure your programs simply, as many have done for centuries, and have a sort of mental discipline, this approach can last for a lifetime/your entire career), but after a while it starts to show its disadvanages. Try for example, following some of the discussions on the recent features on comp.lang.fortran to test your knowledge.

So, take a good book (many recommend one of the three for beginners; a) Chapman J. Stephen's b) Maine, or c) Metcalf, Reid and Cohen (known as the "M.R.C. book") - after which a lot of the "more obscure" features not only become clearer, but also "obvious" (as in a way; this really is the better way - why did I did it that way ... before?).

That takes care of that question. Now, the other question -- which will certanly arise -- is Fortran worth learning nowadays? (it always does, trust me on this :). This has been covered numerous times, so I'll just direct to my own post regarding the above, and my older post (you'll have to scroll a little down) which regards some issues in comparison with some of the other langugages mentioned here.

The last thing, which is in a way the cause of all these question in most cases is people opinion on Fortran, with the emphasis on opinion! Generally speaking (and we can take this forum as a pretty good sample for our analysis) is that it's not so good. Few like it [ follow questions marked fortran on this forum for a month, and you'll quickly learn who they are. Btw, judging from the frequency your name's been appearing, you're quickly becoming a member of the club :) ], most are either indifferent, and some hate it, out of sheer ignorance (comparing F66 with today's languages is often used), some out of their own reasons. Now, if we take those and compare it with the general population, by simple an account, the result is bound to come out bad. If you interviewed just traditional engineers the results would be quite different.

Thhhh-aaa-ttt's it.

Oh, one more thing - Fortran is/was and still remains primarily aimed at engineers, not mathematicians. It is better suited for solving large systems, then calculating pi to a ka-zi-llionth decimal. I don't know if that was a typo in your question, or intentional. For purely mathematical applications (in a classical sense of mathematician) I would (were I a part of that field) probably choose, I don't know, Mathematica? Or Pascal (don't know why it was always Pascal; but it seems terribly popular with those chaps).

衣神在巴黎 2024-09-22 06:53:17

令我惊讶的是,这里的共识是针对现代 Fortran 的,我勉强同意。

不管它有什么缺点,Fortran 是唯一一种专门为科学编程而设计的语言。科学编程比网络服务器更微妙(每行)和更简单(结构),并且它只需要不同的工具。例如,垃圾收集对于解决主要数据结构固定的大型 2d/3d PDE 几乎没有用。

任何甚至没有多维数组作为第一类对象的编程语言都可以立即被科学编程抛弃。这就是所有基于 C 的语言。任何本质上慢得可怕的编程语言——Java,我正在看着你——都可以立即被抛弃。任何专有且需要数千美元许可费的编程语言——Matlab——都可以立即被驳回。

Python 和相关语言非常适合原型设计,而且绘图也很容易,一旦一切顺利,就可以用编译语言编写数值内核以提高速度;但它又缺乏真正的数组(Numpy 很好,但不是很好),而且它是 s..l..o..w。

顺便说一下——永远不要阅读《数值食谱》书籍。他们很糟糕,他们提出的算法是过时的,而且代码的范围从糟糕到错误。参加一门真正的数值算法课程——网上有很好的课程——或者买一本真正的数值算法书——看在上帝的份上,不要从书中输入代码来做线性代数或其他什么;这样做是为了让你的数学算法更容易。使用无数真实、专业的优质库。

I'm surprised that the consensus here is for modern Fortran, and I grudgingly agree.

Whatever its failings, Fortran is the only language out there being designed explicitly for scientific programming. Scientific programming is both more subtle (per line) and less complicated (in structure) than, say, a web server, and it just needs different tools. Garbage collection, for instance, is almost never useful for solving large 2d/3d PDEs where your primary data structures are fixed.

Any programming language that doesn't even have multi-d arrays as first-class objects can be dismissed immediately for scientific programming. and that's all of the C-based languages. Any programming language which is inherently god-awful slow -- Java, I'm looking at you -- can be dismissed immediately. Any programming language which is proprietary and requires thousands of dollars of licensing fees -- Matlab -- can be dismissed immediately.

Python and related languages are good for prototyping, and plotting is easy, and once you've got things working can write the numerical kernels in compiled languages for speed; but it again suffers from the lack of real arrays (Numpy is good, but not great) and it is s..l..o..w.

By the way -- don't ever by the Numerical Recipes books. They're crap, the algorithms they pitch are of date, and the code ranges from poor to wrong. Take a real numerical algorithms course - there's good ones on line - or buy a real numerical algorithms book -- and for the love of God, don't type in code from a book to do linear algebra or whatever; use the zillions of real, professional quality libraries out there.

伤痕我心 2024-09-22 06:53:17

对于您的问题的最直接答案,我认为 kemiisto< /a> 的答案是正确的,并且有 确定的警告伊迪加斯

也就是说,我发现我的数字代码更多地与 FTP、Web 等事物接触,更接近于图形。我在另一个答案中看到了 MATLAB 的建议,但我一直在编写越来越多的 Python(使用 NumPy),并在需要速度时调用 Fortran。我几乎肯定不会以这种方式编写整个系统(例如整个数值天气预报模型),但它确实使我在许多方面都能够两全其美。

For the most direct answer to your question, I think that kemiisto's answer is correct, with the caveats identified by Idigas.

That said, I've found more of my numerical code coming into contact with things like FTP, web, and closer to graphics. I've seen MATLAB suggested in another answer, but I've been writing more and more Python (with NumPy) and calling out to Fortran when I need the speed. I'd almost certainly not write a whole system (e.g. an entire numerical weather prediction model) this way, but it does allow me to have the best of both worlds in many respects.

苍暮颜 2024-09-22 06:53:17

或者是答案 Fortran 90, 95, 2003 。 。 。 ?是的。对于科学计算,Fortran >=90 消除了 FORTRAN 77 的限制。了解如何使用可分配数组来动态调整大小的数组。了解如何使用模块来组织过程和变量,并轻松地在实际参数和虚拟参数之间提供自动一致性检查。从 FORTRAN 77 开始,您可以逐步学习 Fortran 90/95/2003,使用您认为有用的任何功能。您不必学习面向对象的功能,并且可以忽略该语言的这一部分,直到有一天它为您提供实用程序。

我推荐梅特卡夫、里德和科恩的书。

Or is the answer Fortran 90, 95, 2003 . . . ? Yes. For scientific computing, Fortran >=90 removes the limitations of FORTRAN 77. Learn how to use allocatable arrays to have dynamically sizable arrays. Learn how to use modules to organize your procedures and variables -- and easily provide automatic consistency checking between actual and dummy arguments. Starting from FORTRAN 77, you can gradually learn Fortran 90/95/2003, using whichever features seem useful to you. You don't have to learn the OO features and can ignore that portion of the language, until perhaps someday it offers utility to you.

I recommend the Metcalf, Reid and Cohen book.

箜明 2024-09-22 06:53:17

您可能正在查看 MATLAB。许多工程师本科生都知道这一点,所以我认为非程序员很容易理解。

如果您想获得核心,请查看 J

You may be looking at MATLAB. Many engineer undergraduates learn that so I think it's easy for non-programmers to grok.

If you want to get hardcore, take a look at J.

萌无敌 2024-09-22 06:53:17

我认为 Fortran 95 应该是您的选择,它看起来更现代,并且显着扩展了 Fortran 77。大多数编译器并不完全支持 Fortran 2003 标准。
Fortran 的巨大优点是对于每个数学问题(例如求根、矩阵乘法、特征值问题等)都有一个优化的子例程。其他人提到了遗留库,lapack 只是一个非常强大的例子。 Fortran 的一个主要缺点是没有人在现实世界中使用它。

我认为最好的书是《Fortran 90/95 for Scientifics and Engineers》。

当然,所有其他建议都是有效的,但 matlab 不是免费的,而 Fortran 是免费的。

Python 是免费的,并且通过 Numpy 和 Scipy 等额外软件包支持许多科学应用程序。然而,Python 在数值性能方面相当慢。对于不需要大量计算能力的小型项目来说,这可能是一个不错的选择。语法非常容易理解。

C 当然也是一个免费选项,并且有很多(不断更新的)科学库可用。然而,就可读性而言,它无法击败 Fortran。 Fortran 可以很好地处理向量和数组。

C++ 是 C 的超集,因此它绝对也是一个可能的选择。然而,对于您正在查看的问题来说,这种语言可能过于复杂。科学 C++ 库的数量相当有限。有一些,但它们无法击败 Fortran 版本(或者只是这些版本的包装)。对于非常大的项目来说,这可能是一个非常好的选择,但是在世界上最快的计算机上运行的一些非常大的程序是用 Fortran 编写的。 C++ 绝对值得学习,因为它被用于广泛的现实世界应用程序。

当然还有其他语言或工具,但我认为这些是跨科学学科最常用的。

I think Fortran 95 should be your choice it looks more modern and extends Fortran 77 quite significantly. The Fortran 2003 standard is not completely supported by most compilers.
The great advantage of Fortran is that there is an optimized subroutine for every mathematical problem (such as root finding, matrix multiplication, eigenvalue problems, etc.). Other people mentioned legacy libraries and lapack is just one very powerful example. A major disadvantage of Fortran is that nobody is using it in the real world.

The best book around is is my opinion "Fortran 90/95 for Scientists and Engineers".

Of course all other suggestions are valid, but matlab is not free while Fortran is.

Python is free and has support for a lot of scientific applications through extra packages such as Numpy and Scipy. Python is however rather slow when it comes to numerical performance. It's probably a good option for small projects that don't require a lot of computational power. The syntax is very easy to understand.

C is of course also a free option and has a lot of (constantly updated) scientific libraries available. However, when it comes to readability it cannot beat Fortran. Fortran is well set-up to work with vectors and arrays.

C++ is a superset of C so it's definitely also a possible choice. However, it is a language that might be to complex for the problems that you're looking at. The number of scientific C++ libraries is rather limited. There are some around but they cannot beat the Fortran versions (or are just wrappers of those). It's probably a very good option for very big projects but some very big programs that run on the world's fastest computers are written in Fortran. C++ is definitely worth learning since it is used for a broad number of real world applications.

There are of course other languages or tools but I think these are the most commonly used across scientific disciplines.

人事已非 2024-09-22 06:53:17

如果您确实对使用 Fortran 感到兴奋,则可以考虑使用 Fortran for Microsoft。 NET。该项目背后的想法是,它允许您使用 Fortran 语言,同时通过公共语言运行时 (CLR) 利用托管代码环境。

If you're really excited about using Fortran, you might consider using Fortran for Microsoft.NET. The idea behind this project is that it allows you to use the Fortran language while taking advantage of a mangaged code environment via the Common Language Runtime (CLR).

此生挚爱伱 2024-09-22 06:53:17

@S.Lott:无法想象像科学家这样的 Fortran 用户必须切换并转储他们所有的 Fortran 工作......:S OP 正在寻找有关新内容的输入......

对于 OP:
您是否阅读过 Wikipedia,其中详细介绍了 2003 版本对 Fortran 所做的更改,允许互操作性与 C,所以也许 S.Lott 确实有一点,也许,一点一点地,轻轻地移植一些东西或者用 C 编写一个包装器来调用 Fortran 模块?我将从维基百科页面引用......

与 C 编程语言的互操作性。

@S.Lott: Cannot imagine Fortran users such as scientists, having to switch over and dump all their Fortran work..... :S The OP is looking for input on what's new...

To the OP:
Have you read up on Wikipedia which details the changes made to Fortran, for 2003 version, allows interoperability with C, so maybe S.Lott does have a point, perhaps, bit by bit, gently port some stuff over or write a wrapper in C to call the Fortran modules? I'll quote from that Wikipedia page...

Interoperability with the C programming language.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文