Page 1 of 1

MATLAB to FORTRAN LAPACK

PostPosted: Fri Jul 30, 2010 10:00 am
by kayronjm
Hello everyone, this is my first post. I used to use MATLAB all the time so the function eig was perfect for calculating the eigenvalues and eigenvectors of a matrix. For reference, this is the kind of matrix I deal with:

Image

The top one is the matrix itself but the bottom is its transpose, to prove its real and non-symmetric.

I now have to use FORTRAN to write my code so I'm currently stuck on that stage - the eigenvalues and eigenvectors.

I looked up eig on the MATLAB help and found that for double precision for a real non-symmetric matrix, MATLAB in fact uses the LAPACK functions:

DGEHRD, DORGHR, DHSEQR, DTREVC

I've downloaded LAPACK and have found these four in there, although I believe the second (DORGHR) isn't required. The first would reduce my matrix to an Upper Hessenberg form. The third would calculate the eigenvalues from this matrix and the fourth would calculate the eigenvectors from this matrix. Am I correct?

My issue is that these three LAPACK subroutines (DGEHRD, DHSEQR, DTREVC) call other subroutines, some of which the LAPACK package does not contain (e.g. DGEMM). Would this be a problem?
Would I have to include in my FORTRAN project (I'm doing this on FTN95) not only the three subroutines I want but also the ones they call?

Thanks for any guidance you can provide.

Re: MATLAB to FORTRAN LAPACK

PostPosted: Fri Jul 30, 2010 10:54 am
by admin
Hi,
My issue is that these three LAPACK subroutines (DGEHRD, DHSEQR, DTREVC) call other subroutines, some of which the LAPACK package does not contain (e.g. DGEMM). Would this be a problem?

No actually, DGEMM is part of the BLAS library. The BALS library is the library that will brgin you good performance. A Reference BLAS is provided in the LAPACK package but it is recommended to get ATLAS, GOTO, VECLIB, MKL, ACML or any other BLAS implementation. Those are usually doing a very good job. For more info, http://en.wikipedia.org/wiki/Basic_Line ... ubprograms

Would I have to include in my FORTRAN project (I'm doing this on FTN95) not only the three subroutines I want but also the ones they call?

You just want to build the LAPACK library to make sure you have all the dependancies and link against it (and the BLAS library of course).

Julie

Re: MATLAB to FORTRAN LAPACK

PostPosted: Fri Jul 30, 2010 11:19 am
by kayronjm
Great Julie, thank you for your reply. To avoid including over a thousand files in my project, I included the three core subroutines and then let FTN95 complain about not finding the dependencies. I went through each of the warnings and included all the dependencies. Now it's compiling fine. My next mission will be to actually use the subroutines to get what I want working! :)

Re: MATLAB to FORTRAN LAPACK

PostPosted: Fri Jul 30, 2010 1:06 pm
by Julien Langou
(1) For a start, you might want to use straight "DGEEV" as opposed to the collection "DGEHRD+DORGHR+DHSEQR+DTREVC". Basically DGEEV is a driver which calls this four routines for you. No worries: you probably will need almost the same set of routines you already have included in your project. (2) Keep in mind that LAPACK (so DGEEV in your case) takes advantage of optimized BLAS library, so while it is good for portability and testing to include reference DGEMM source code in your project, the performance will likely not be good. For better performance, you need to remove DGEMM (and all BLAS subroutines) from your project and link with an optimized BLAS library. (See Julie's comment above.) Both approach makes sense. Julien.

Re: MATLAB to FORTRAN LAPACK

PostPosted: Fri Jul 30, 2010 5:43 pm
by kayronjm
Thanks for your reply, I will look into this. Performance is not a big issue however, especially at this stage. My states matrix will always either be 10x10 or 28x28. Finding eigenvalues and eigenvectors from such small matrices is pretty quick. In either case, I will indeed keep this in mind - thanks again!

Re: MATLAB to FORTRAN LAPACK

PostPosted: Sat Jul 31, 2010 1:58 pm
by DavidB
I am curious: if you are already familiar with MATLAB, why do you now have to use FORTRAN to solve eigensystems?

Re: MATLAB to FORTRAN LAPACK

PostPosted: Sat Jul 31, 2010 7:57 pm
by kayronjm
I've been using MATLAB for nearly six years and FORTRAN for about two months, so your curiosity is very much warranted. I'm doing a PhD in Plasma Physics and as with any physics research, FORTRAN seems to be the main basis for coding, mostly due to tradition but also for its speed and wide compatibility with codes written today and years and years ago by other researchers. My supervisor was very eager for me to leave MATLAB behind in favour of writing my code in FORTRAN. Now it is up to me to suffer the lack of integrated functions in FORTRAN. Thankfully packages such as LAPACK are around, otherwise I'd be very depressed..

Re: MATLAB to FORTRAN LAPACK

PostPosted: Sun Aug 01, 2010 8:39 pm
by DavidB
Okay. Thanks for posting back. I thought you might have been a graduate whose access to MATLAB was terminated but still needed the tools; I was going to mention my own translation of an eigensystem solver:

Eigenvalues and Eigenvectors Calculator

This Javascript utility is a translation of the older EISPACK routines into C++ and then into Javascript (C++ source code will be posted soon). Perhaps it still might be useful to you as another tool for comparison of results.

Re: MATLAB to FORTRAN LAPACK

PostPosted: Mon Aug 02, 2010 10:22 am
by kayronjm
Ah nice, thanks for that!
I will bookmark it for comparison, yeah.