English 中文(简体)
converting MATLAB code to Fortran [closed]
原标题:

Closed. This question needs to be more focused. It is not currently accepting answers.


Want to improve this question? Update the question so it focuses on one problem only by editing this post.

Closed 7 years ago.

I a medical researcher with code written in MATLAB 2009b that runs very slowly because of a self-referential loop (not sure of the programming lingo here), i.e., the results of the first iteration is used during the second iteration, etc. (I have vectorized it to a fare-thee-well. I have run the Profiler.)

I d like to convert the slow parts of the code to a mex function. I learned Fortran in the early 1970s but haven t used it since. The code I need to convert doesn t do anything fancy, it is just a long numerical calculation.

My question is: what would be the easiest-to-relearn version of Fortran adequate for this purpose, and what compiler works best on the Intel Mac for this? I found information comparing syntax in MATLAB to Fortran 90 for example, and the conversion doesn t look like it would be too daunting for me. However, again, I am no programmer.

I am using a MacBook Pro with OS 10.6.

Appreciate any help, thanks.

问题回答

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.

Good luck, Ariel





相关问题
2 mysql instances in MAC

i recently switched to mac. first and foremost i installed xampp. then for django-python-mysql connectivity, i "somehow" ended up installing a seperate MySQL. now the seperate mysql installation is ...

Iterating over string/strlen with umlauted characters

This is a follow-up to my previous question . I succeeded in implementing the algorithm for checking umlauted characters. The next problem comes from iterating over all characters in a string. I do ...

Controlling OSX windows

I m trying to control windows of a foreign OSX applications from my application. I d like to 1. move the windows on the screen 2. resize the windows on the screen 3. change the currently active window ...

Switching J2SE versions on Mac OS (SnowLeopard)

My current JDK on Mac OS (10.6) is set to 1.6 and I d like to switch to 1.5. A listing of /System/Library/Frameworks/JavaVM.framework/Versions/ shows: lrwxr-xr-x 1 root wheel 10 Nov 3 18:34 ...

Scrolling inside Vim in Mac s Terminal

I ve been googling around trying to figure out if it s possible to use my mouse wheel to scroll while inside Vim in Mac s Terminal, with no luck. It seems as if only X11 or iTerm support this. Before ...

export to MP3 from quicktime API

A question for Apple,QT programmers. Would like to know if it s possible to export a Movie object to MP3 using the QuickTime API. Preferably the ConvertMovieToFile function. I ve looked at ...

热门标签