Tutorial for using LAPACK in Fortran 95?
Hey Folks,
New to Fortran (95) programming and I'd like to use LAPACK to diagonalize matrices. I must say, though, that I am having a difficult time understanding the sites I've come across on the web.
I feel I only have a cursory knowledge of compilation. I've been using Stephen Chapman's Fortran 95/2003 for Scientists and Engineers and it seems that he avoids tackling the issue of compilation/linking. Perhaps this is because the process varies significantly from platform to platform, I personally am unsure. For example, how do I create a proper makefile that includes LAPACK?
What I'm wondering is can anyone recommend a tutorial for incorporating LAPACK into my fortran 95 program? I presume my goal is to permit the use of LAPACK subroutines by simply calling them as if they were a part of my own source code file.
Much thanks,
CmdrGuard



LAPACK example
Are you looking for a mac specific example? It's not hard once you know what to do. The trick is to link to the correct library (and for the matter, what to call it). Fortran 95 provides some nice ways to make it a bit easier but the key is to include the library in the compilation step.
gfortran my_awesome_code.f95 -llapack -o my_program
If you take a look at /usr/lib/liblapack.dylib, it links to the accelerate framework and inside that is the Mac lapack library. the command -l links to this library. Linking to it this way should be fairly platform independent (well, as much as lapack is).
If you are looking for more help with the coding process itself, two good resources are:
http://www.netlib.org/lapack/lug/lapack_lug.html
http://www.cs.colorado.edu/~jessup/lapack/
The first is an electronic version of the LAPACK guide, the second helps you choose which subroutine to use.
Hope that this helps! I have some simple code that calls LAPACK if you are interested that I could probably post.
Kyle
Libraries
Thanks for another great reply, Kyle.
In the interim since I first posted, I found this site at apple:
http://developer.apple.com/hardwaredrivers/ve/fortran.html
which suggested using the compile line option:
-framework vecLibI was concerned though that I had only found a solution that applied to Mac OS X and so your statement as to your approach being platform independent is quite important to me.
Could you tell me where gfortran looks for libraries?
I'm guessing from the command line option you provide, that it looks for files in the /usr/lib/ directory that begin with lib. But can you tell gfortran other locations to look for libraries?
Also, is a library like liblapack.dylib what an installation of LAPACK, downloaded from netlib, is ultimately supposed to produce?
LAPACK dgesvd_ fails in multi-thread calls
Dear all -
I have a C++ program calling dgesvd_ from the LAPACK library in the veclib framework in Mac OSX 10.5.7. It is supposed to be thread-safe, provided that the
calls
(void) dlamch_("e");
(void) slamch_("e");
are made before calls to dgesvd_ are made from multiple threads. I do do those calls at the very beginning of my main(), before any multiple threads are created. Even so, if I don't protect my calls to dgesvd_ with a mutex, I get errors from dgesvd_. More specifically, dgesvd_ fails returning info=1 (failure to converge). This does not happen (ever) when I have a mutex protecting the call. All the variables/parameters passed to dgesvd_ are allocated by each thread, so there should be no conflict there. I use POSIX threads and include the pthreads library.
Is LAPACK thread safe or not? Am I missing compilation flags? It shouldn't matter, but I am using Eclipse and g++ to compile and link.
Many thanks for any hints/explanations. Regards,
Mauro
LAPACK Libraries
The -llapack should be platform independent on *nix platforms. Again, the liblapack.dylib located in /usr/lib is just a symbolic link to the one in the Accelerate framework (which is what -framework veclib is doing as well). As you suggested, the installations of LAPACK that would be downloaded from netlib are intended to produce a library like liblapack.dylib. One way to circumvent all of this is to download the appropriate routines from netlib and compile them directly into your program although the routines would not be optimized for the hardware so depending on your application, you may not want to do this.
Kyle