1
votes

First of all, I am new to this area of using Fortran and Matlab together, so please bear with me if I did not see the very obvious.

Here is my problem: I have a Fortran 90 code which will calculate 2 large complex matrices A and B. I write these matrices onto a file, read it in MATLAB and do some manipulations (solve for eigenvalues to be specific). The problem with this method is that it takes very long time to write and read data even in binary format. In some cases, the write and read operations are longer than actually solving the eigenvalue problem.

So, is there anyway I can directly pass the matrices generated by my Fortran 90 code to MATLAB without having to write and read?

I have read about call system in Fortran but it doesn't seem to pass any arguments.

1
Why not calculate the eigenvalues in Fortran without Matlab?Mark Setchell
You can use LAPACK in Fortran to compute the eigenvalues.Vladimir F
Matlab's documentation explains in considerable detail how to create a Fortran mex file to call directly; since this puts both parts of the code into the Matlab memory space you don't have the time-consuming file reading and writing to contend with. If that doesn't appeal, don't discard the idea of using Matlab for calculating eigenvalues -- most of Matlab's core computational routines are implemented in compiled code, often using the same libraries (eg BLAS, MKL) that you'd call from Fortran and the speed differences are negligible when, that is, Matlab isn't faster.High Performance Mark
Are you compiling with gfortran? Look up execute_command_line, which is part of the Fortran 2008 standard and should considered in new code for future portability. gcc.gnu.org/onlinedocs/gfortran/…jlokimlin

1 Answers

1
votes

If you have performance problems you might want to calculate the Eigenvalues in Fortran (by using LAPACK for example as Vladimir F already stated in the comments). However, instead of starting you Fortran program and trying to pass the matrices to Matlab you could call your Fortran program/your Fortran functions/subroutines/matrices/pointers from Matlab. You would have to rewrite parts of your program but then you could use the Fortran Matrix Library API. (Basically using mex as High Performance Mark mentioned in the comments)