将 MATLAB 代码转换为 Fortran

发布于 2024-08-12 12:25:17 字数 1436 浏览 4 评论 0原文

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

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

发布评论

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

评论(2

瀞厅☆埖开 2024-08-19 12:25:17

我建议使用现代 Fortran,至少 90/95,因为语法更加宽容,而且几乎所有编译器现在都支持它。

在 Mac 上,我会推荐 此处 的 gfortran。它不是最新版本,但它与 Apple 构建工具完美集成(您需要从 Mac OS DVD 安装 Xcode)并且运行良好。在依赖大量 Fortran 扩展的数值 Python 社区中,强烈推荐此构建。

我实际上并没有在 mac 上使用过 fortran mex - 但我认为如果你遵循 mex 文档,它应该相当简单 - 正如你所说,将代码从 Matlab 翻译成 Fortran 应该不会太糟糕(如果你能避免的话,那就更好了调用 Matlab 函数,但 Fortran 具有合理的切片和数组访问)。

I'd recommend using modern Fortran, at least 90/95 as the syntax is much more forgiving and almost all compilers now support it.

On a Mac I would recommend gfortran from here. It's not the most recent version, but it's well integrated with Apple build tools (you will need to install Xcode from your Mac OS DVD) and works well. In the numerical python community, which depends a lot of Fortran extensions, this build is highly recommended.

I haven't actually used fortran mex on the mac - but I think it should be fairly straightforward if you follow the mex documentation - and as you say translating code from Matlab to Fortran shouldn't be too bad (it's better if you can avoid calling Matlab functions, but fortran has sensible slicing and array access).

↘人皮目录ツ 2024-08-19 12:25:17

好吧,您可能已经找到了解决方案。不过,我要说的是:Matlab 已经变得越来越快了。然而,充分利用 Matlab 的 JIT 有时并不直观。 Mathworks 过去常说对代码进行矢量化以提高速度。然后他们说将所有内容都写在显式循环中。我实际上不确定当前的最佳实践是什么。

我的意思是,在学习 Fortran 之前,找出最佳实践并实施它。这可能会给你足够的加速。

另外,您是否绝对确定已将减速隔离到循环中?您使用过分析器吗?你可能有,因为你听起来很有经验。我只是想提一下。

祝你好运,
爱丽儿

Well, you have probably found a solution already. However, I will say this: Matlab has been getting faster and faster. However making full use of Matlab's JIT is sometimes not intuitive. Mathworks used to say vectorize code for speed. Then they said write everything in explicit loops. I'm actually not certain what the current best practice is.

What I'm saying is, before you go to fortran, find out the best practice and implement it. That may give you enough of a speed-up right there.

Also, are you absolutely certain that you have isolated the slowdown to a loop? Have you been using the profiler? You probably have, since you sound experienced. I just thought I'd mention it.

Good luck,
Ariel

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