为什么 Matlab 是用 C 语言而不是 Fortran 语言编写的?

发布于 2024-07-22 05:34:41 字数 80 浏览 5 评论 0原文

如您所知,Fortran 是一种用于科学计算的语言。 然而,最著名的科学计算高级语言的内核是用 C 而不是 Fortran 编写的。 为什么?

As you may know, Fortran is a language for scientific computing. however, the kernel of the most famous high level language for scientific computing has been written in C instead of Fortran. Why?

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

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

发布评论

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

评论(6

眼角的笑意。 2024-07-29 05:34:41

回答你原来的问题:Matlab 最初是用 Fortran 编写的。但是 Matlab 的创建者 Cleve Moler 和他的合作伙伴在 1983 年做的第一件事就是用 C 重写了整个 Matlab 应用程序:

杰克·利特尔 (Jack Little) 辞去了他在
咨询公司并购买了新的
西尔斯的康柏便携式电脑。 这
机器只有 256 KB 内存
没有硬盘; 杰克不得不交换
用于编译的 5-1/4 英寸软盘
程式。 杰克和史蒂夫花了一年的时间
用 C 语言重写 MATLAB,
添加他们所设想的新功能
看到了。 (MATLAB 和 MathWorks 过去二十年的发展)< /p>

< strong>我认为今天一个更相关的问题是问:为什么他们在 1983 年转向 C?

我的猜测是 C 可能具有 Fortran 所没有的某些功能,因此转向更过时必要性并且为了代码的可维护性。

Fortran77 中缺少的一项杀手级功能是动态内存分配(动态内存分配仅在 Fortran90 中添加)。 在我看来,绕过这个单一限制将是一个可怕的交易破坏者。

编辑:

dmckee 的答案很好地解释了为什么使用 Fortran77 会很痛苦。

To answer your original question: Matlab was originally written in Fortran. But one of the first things that the creator of Matlab, Cleve Moler, and his partner did in 1983 was to rewrite the entire Matlab app in C:

Jack Little left his job at the
consulting company and bought a new
COMPAQ portable computer at Sears. The
machine had only 256 KB of memory and
no hard disc; Jack had to swap
5-1/4-inch floppies to compile
programs. Jack and Steve took a year
and a half to re- write MATLAB in C,
adding new features they had envi-
sioned. (The Growth of MATLAB and The MathWorks over Two Decades)

I think a more relevant question for today would be to ask: why did they switch to C back in 1983 ?

My guess is that C probably had certain features that Fortran did not have and thus the switch was more out of necessity and in the interest of code maintainability.

One killer feature missing in Fortran77 was dynamic memory allocation (Dynamic memory allocation was only added in Fortran90). Getting around that single limitation would be a horrible deal breaker in my opinion.

EDIT:

dmckee's answer has a great explanation of why using Fortran77 would be painful.

初见你 2024-07-29 05:34:41

根据经验猜测:

内存管理。

Fortran(好吧,是编写 matlab 时出现的 fortran)不支持动态内存管理。 这使得大型工作变得很痛苦(例如,参见 CERNLIB)。

CERNLIB 通过在公共块中分配一个巨大的数组,并为数组的单元实现一个类似 malloc 的(释放)分配器来解决这个问题。 笨重但有效:数组偏移量是指针等效项,然后就可以了......

Guessing on the basis of experience:

Memory management.

Fortran (well, the fortran that was around when matlab was written) has no support for dynamic memory management. Which makes it a pain for big work (see, for instance, CERNLIB).

CERNLIB solves the problem by allocating a whopping big array in a common block, and implementing a malloc like (de)allocator for the cells of the array. Clunky but working: array offsets are pointer equivalents, and away you go...

你的往事 2024-07-29 05:34:41

我的理解是,Matlab 是用多种语言编写的,包括但不限于 C、FORTRAN、Java 和 Matlab 本身。

我相信它在幕后采用了最好的库,包括 LAPACK (FORTRAN)、FFTW (C) 等等。

我认为最初的版本是纯粹的 FORTRAN,但随着它变得更加精致和商业化,他们并不羞于为每个组件使用正确的语言。 我不怪他们——我讨厌用 FORTRAN 编写解析器或 GUI!

My understanding is that Matlab is written in a hodge-podge of languages, including but not limited to C, FORTRAN, Java, and Matlab itself.

I believe it employs best-of-breed libraries behind the scenes, including LAPACK (FORTRAN), FFTW (C) and probably many more.

I think the original version was pure FORTRAN, but as it became more polished and commercial they weren't shy about using the right language for each component. I don't blame them--I'd hate to write a parser or a GUI in FORTRAN!

依 靠 2024-07-29 05:34:41

我想用以下声明来限定这个答案 - 我对 Fortran 或 Matlab 一无所知

,但是我认为您几乎在问题中回答了您自己的问题。

为什么不使用科学语言来编写内核。 您将使用最适合手头任务的语言。 内核最好用 C 编写,因为它更适合处理内核等低级任务(处理内存管理等)。

内核不是科学应用程序,因此您不会使用科学语言。

再说一次,我可能完全偏离主题,但我认为这是一个非常合乎逻辑的答案。

I want to qualify this answer with the following statement - I know nothing about Fortran or Matlab

However i think you almost answer your own question in your question.

Why would you not use a scientific language to write a kernel. You would use the most appropriate language for the task at hand. A kernel would be best written in C as it is better suited to working with low level tasks like kernels (working with memory management etc)

A Kernel is not a scientific application therefore you wouldn't use a scientific language.

Again, i may be completely off the mark but i think that is a highly logical answer.

世态炎凉 2024-07-29 05:34:41

您可以通过观看其网站上的视频找到有关 Matlab 起源的一些信息,特别是 首席科学家 Cleve Moler 的页面

You can find some information on the origins of Matlab by viewing a video on their web site, specifically on the page of the Chief Scientist, Cleve Moler.

飘然心甜 2024-07-29 05:34:41

Matlab 最初是用 Fortran 编写的,它更像是一个集合的包装器
Fortran 例程。 那么问题来了,为什么要用c重写呢? 其实Fortran为什么输了
转向 C 和其他并不真正适合数值计算的语言。 答案是 Fortran 深受政治影响。 由于各种原因,标准委员会可能会决定使用 Fortran 77 的替代品。因此,当 Fortran 90 最终发布时,Fortran 已经输给了其他语言。 这种情况现已得到纠正。 Fortran 2003 或多或少是在 gnu 编译器中实现的,是一种很好的语言,它非常适合数字,此外还具有动态分配、快速 io 和 OO ish 构造、多态性派生类型等。(Fortran 2008 会更好)

现代 Fortran不是为编写 GUI 界面而设计的,而是为 C 和其他语言的调用和被调用而设计的。 因此,如果今天重复进行 matlab 练习,很可能数字位将用 Fortran 编写,而用户界面将用其他语言编写。

Matlab was originally written in Fortran, it was more a less a wrapper for a bunch
of Fortran routines. So the question is why rewrite it in c? In fact why did Fortran lose
out to c and other languages that weren't really suited to numerical computing. The answer is Fortran suffered badly from politics. For various reasons the standard committee could decide on a replacement for Fortran 77. So, by the time Fortran 90 eventually came out Fortran had lost a lot of ground to other languages. This situation has now been corrected. Fortran 2003, which is more or less implemented in the gnu compiler, is a nice language its well suited to numeric and in addition has dynamic allocation fast io and OO ish constructs polymorphism derived type etc. (Fortran 2008 will be even better)

Modern Fortran isn't designed to write gui interfaces but it is designed to call and be called from C and other languages. So if the matlab exercise was repeated today its quite possible that the numeric bits would be written in Fortran and the user interface in something else.

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