Linking Fortran to Matlab-generated MEX files
13 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Marat Kulakhmetov
il 1 Mag 2014
Risposto: Ryan Livingston
il 12 Mag 2014
Hey!
I have written a trajectory code in Matlab and sped it up by compiling it into C using the codegen command. I run this code from matlab as a Trajectory_Mex function and got a 100x speed up compared to the original Matlab script, which is great given that even with the speed up my calculations take a few hours on a cluster.
The trajectory calculations need potential functions, which were provided to me in a Fortran format. After going through Matlab documentation I learned that I could also make Fortran-mex files, that work from the main Matlab workspace but when I try to compile a Matlab script that uses the Fortran-mex file I get the " ??? Only MATLAB files are supported for code generation. Unsupported file extension 'mexa64' for '/PotentialTests/O3PES/timestwo.mexa64'" error.
Is it possible to use a Fortran-mex within a codegen-compiled script? Do I have to rewrite the Fortran files to use codegen? What is the best way for me to implement my Fortran code within compiled scripts?
Thank you very much! MK.
0 Commenti
Risposta accettata
Ryan Livingston
il 12 Mag 2014
If your goal is to generate a MEX function, then I would recommend just declaring your Fortran MEX function as an extrinsic function:
function y = extrinsicTimesTwo(x)
coder.extrinsic('timestwo');
y = 0;
y = timestwo(x);
>> codegen extrinsicTimesTwo -args 1
This will allow the call to the Fortran MEX function to occur similar to how you call it in MATLAB.
See:
for the doc.
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Fortran with MATLAB in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!