The LAPACK forum has moved to https://github.com/Reference-LAPACK/lapack/discussions.

MATLAB to FORTRAN LAPACK

Open discussion regarding features, bugs, issues, vendors, etc.

MATLAB to FORTRAN LAPACK

Postby kayronjm » Fri Jul 30, 2010 10:00 am

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.
kayronjm
 
Posts: 9
Joined: Fri Jul 30, 2010 9:50 am

Re: MATLAB to FORTRAN LAPACK

Postby admin » Fri Jul 30, 2010 10:54 am

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
admin
Site Admin
 
Posts: 616
Joined: Wed Dec 08, 2004 7:07 pm

Re: MATLAB to FORTRAN LAPACK

Postby kayronjm » Fri Jul 30, 2010 11:19 am

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! :)
kayronjm
 
Posts: 9
Joined: Fri Jul 30, 2010 9:50 am

Re: MATLAB to FORTRAN LAPACK

Postby Julien Langou » Fri Jul 30, 2010 1:06 pm

(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.
Julien Langou
 
Posts: 835
Joined: Thu Dec 09, 2004 12:32 pm
Location: Denver, CO, USA

Re: MATLAB to FORTRAN LAPACK

Postby kayronjm » Fri Jul 30, 2010 5:43 pm

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!
kayronjm
 
Posts: 9
Joined: Fri Jul 30, 2010 9:50 am

Re: MATLAB to FORTRAN LAPACK

Postby DavidB » Sat Jul 31, 2010 1:58 pm

I am curious: if you are already familiar with MATLAB, why do you now have to use FORTRAN to solve eigensystems?
DavidB
 
Posts: 38
Joined: Thu Dec 15, 2005 1:49 pm
Location: Vancouver, B.C. Canada

Re: MATLAB to FORTRAN LAPACK

Postby kayronjm » Sat Jul 31, 2010 7:57 pm

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..
kayronjm
 
Posts: 9
Joined: Fri Jul 30, 2010 9:50 am

Re: MATLAB to FORTRAN LAPACK

Postby DavidB » Sun Aug 01, 2010 8:39 pm

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.
DavidB
 
Posts: 38
Joined: Thu Dec 15, 2005 1:49 pm
Location: Vancouver, B.C. Canada

Re: MATLAB to FORTRAN LAPACK

Postby kayronjm » Mon Aug 02, 2010 10:22 am

Ah nice, thanks for that!
I will bookmark it for comparison, yeah.
kayronjm
 
Posts: 9
Joined: Fri Jul 30, 2010 9:50 am


Return to User Discussion

Who is online

Users browsing this forum: No registered users and 7 guests