This is the first part of a HOWTO that I'm writing on using LAPACK with Visual Studio. In doing so, I've made the assumption that the reader, although probably an expert in some other discipline that requires a linear equation solver, is a novice when it comes to LAPACK -- just as I was when I started. For this reason, I've tried to explain the whys rather than dispense instructions.
Thanks to Evgenii Rudnyi and Mark Hoemmen at
http://groups.google.com/group/matrixprogramming their early suggestions and the reading the draft of this HOWTO. Any inaccuracies in this document are mine. Use with care.
Soon to follow, part 2: Using LAPACK subroutines in a Visual (Studio) C/C++ Project
###########################################
Part 1: Compiling GotoBLAS
(Cygwin required --
http://cygwin.org/ )
###########################################
PreambleLAPACK [http://www.netlib.org/lapack/] is designed as a two-tiered Fortran library, comprising higher level subroutines and "lower-level Basic Linear Algebra Subprograms (BLAS) in order to effectively exploit the caches on modern cache-based architectures" [http://en.wikipedia.org/wiki/LAPACK]. For reference purposes, the LAPACK installation provides a(n untuned) version of the BLAS which is not optimized for any architecture. This reference BLAS implementation may be orders of magnitude slower than optimized implementations, for matrix factorizations and other computationally intensive matrix operations. Optimized implementations the BLAS are available from a number of vendors and projects such as: Intel (commercial), AMD, and ATLAS, but my favorite is GotoBLAS because it is:
- currently the fastest BLAS implementation
[see research report "Choosing the optimal BLAS and LAPACK library" at
http://tinyurl.com/m6lmqs ]
- trivial to compile
- is free (available without cost) for research/academic use.
You can read about sole author of this library Kazushige Goto (pronounced "Goat toe") at
http://en.wikipedia.org/wiki/Kazushige_Goto[Links to other BLAS implementations]
MKL -
http://software.intel.com/en-us/intel-mkl/AMD (AMCL) --
http://developer.amd.com/cpu/Libraries/ ... fault.aspxATLAS --
http://math-atlas.sourceforge.net/ (I was unable to build this library. I found the instructions too lengthy, complicated, and often ambiguous. Nevertheless, the goal of the ATLAS project is an admirable one. It aims to, by self-discovery, automatically generate an optimized BLAS library. However, its performance trails that of other libraries
http://en.wikipedia.org/wiki/Automatica ... a_Software )
Compiling GotoBLASThe GotoBLAS source is available from
http://www.tacc.utexas.edu/resources/software/#blas (there's short registration
form to fill), and can be compiled for Windows with Cygwin. No changes need to be made to GotoBLAS' config file
Makefile.rule, unless a particular compiler is preferred. Happily, the config file automatically enables multithreading if more than one processor is available.
1. Download and extract the GotoBLAS source to any directory of choice, and make any desired changes to the config file (the default option should also work well).
2. In Cygwin, "cd" to the top-level directory containing the source, and type "make"
3. The result of this process should be a file libgoto_<processor_class>-r<a_number>.a, and a (symbolic) link libgoto.a pointing to this file. (For example, libgoto_banias-r1.26.a, or libgoto_northwood-r1.26.a)
4. Now for the final part, building a Windows library (*.lib) and dll for GotoBLAS. This is best done in what's called the "Visual Studio command prompt". The Visual Studio command prompt is basically a version of of the command prompt (cmd) that knows the locations of all the Visual Studio tools e.g. compiler, linker.
- Add the path to the Cygwin binaries to your Windows PATH variable. (On my machine, this path is C:\cygwin\bin).
(Refer to the section "Adding or Editing Environment Variables" of the following page
http://vlaurie.com/computers2/Articles/environment.htm for help on how to do this.)
- Launch the Visual Studio command prompt from:
Start Menu -> Programs -> Microsoft Visual Studio -> Visual Studio Tools -> Visual Studio Command prompt
- In the Visual Studio command prompt, change directory to the "exports" subdirectory of GotoBLAS and run the command "make dll". The result should be something like: libgoto_<processor_class>-r<a_number>.lib and libgoto_<processor_class>-r<a_number>.dll . For example: libgoto_banias-r1.26.dll, or libgoto_northwood-r1.26.dll
Final note:
* Windows needs to be told where to find this dll, else you will get a serious error when you try to run your program. There are several ways to do accomplish this. One, is to add the location of the dll to the PATH environment variable. Another is to simply copy the dll to the Windows\system32 folder. I did the later.
For more information, refer to Microsoft guidelines on
Search Path Used by Windows to Locate a DLL