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).
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.
发布评论
评论(2)
我建议使用现代 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).
好吧,您可能已经找到了解决方案。不过,我要说的是: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