Calling Matlab from Fortran

forall
June 29, 2009 11:09 AM PDT
Rate
 
#2 Reply to #1
Quoting - IanH
You've got two options:

1. Use the Intel Fortran Module Wizard to generate the appropriate interfaces to the Matlab Automation server and then use those interfaces along with the supporting routines provided by the IFCOM and IFAUTO modules. Stupid example attached.

2. You could use the routines exposed by the Matlab engine. This is what the mathworks recommends, but I hate the old F77 style call interfaces, use of the pre-processor, requirement for an external build script, etc, etc.   Supposedly this is just a wrapper around the COM stuff anyway.

You could wrap either method with your own set of interface routines to make your life easier.

Matlab's own documentation includes lots of supporting material.

IanH


Thanks a lot Ian!

I spent about 2 days searching through the web and the matlab help - its crystal-clear once you know the solution to the problem you are trying to get help on :-). The main problem was they keep talking about using their MEX compiler - which seems a very 'awkward' tool in its own right - and as I now understood just obscures the real issues.

But after your post I had your code running in 10mins (I never used the Module Wizard - what a nifty tool!) and I am seeing (more or less) how this all fits together.

A few quick questions:

1) While experimenting I did notice that IFAUTO is not used in your code - is it actually necessary?

2) I also quickly implemented an analogous code using the native Matlab commands (engGetVariable, etc) - after I coincidentally found a semi-working example on the mathworks website. It was also relatively straightforward once I understood the mechanism.

But what did you mean by "Fortran-77 interfaces, required preprocessor, external build script, etc.? I didnt end up using any of these.. At least I dont think I did ...

I just compiled an adjusted version of the Matlab-provided sample .f file - they didnt have the IMPLICIT NONE (oh, mine!!!) and so some integer handles became real values for about 40mins while I was trying to figure out the cause of access violation... argghhh!!!!

But the actual calls to the matlab-provided tools seem clean-enough.

Or am I missing something regarding the relative merits of your strategies 1 and 2? I am happy to hear an advanced explanation if thats what it takes (and if you have the inclination to do so) , since I'd rather invest my time from the start into a better code (I will indeed write wrappers etc to hide that ugliness).

thanks for ur help - and in advance!
dmitri


Intel Software Network Forums Statistics

8482 users have contributed to 31618 threads and 100685 posts to date.
In the past 24 hours, we have 34 new thread(s) 120 new posts(s), and 176 new user(s).

In the past 3 days, the most popular thread for everyone has been gemm(A,A,A) like possible? The most posts were made to gemm(A,A,A) like possible? The post with the most views is Dear Steve, excuse me for a d

Please welcome our newest member rohit5575