next up previous contents
Next: Infrastructure Up: No Title Previous: Contents

Linear Algebra Package (LAPACK)

This problem demonstrates the power of a highly optimized package such as LAPACK over Numerical Recipes. Compile and run the main program in Appendix A(Appendix B if you are using Windows), which compares the MFLOPS rates of Numerical Recipes routines ludcmpp480() and lubksbp480() for solving a linear system of N=512 equations in 512 unknown against the LAPACK routine dgesv(). The program also checks that the equations are solved correctly. You may wish to set the problem size N=512 (#define at top of code) to a smaller number while you are debugging.

Because LAPACK is written in Fortran 77, much of the work in calling LAPACK is to get the code to compile. You will note, for instance, that because Fortran 77 accepts all arguments as pointers to the corresponding data, the arguments in the call to dgesv() each represent the address of the first element of a set of data. (The &'s to the left of each argument accomplish this.)

Because of the above subtleties, Appendix A/B gives a completed program for you. You still likely will have to spend some time hacking with the code to get it to compile. Compilers on UNIX systems, for instance, usually put underscore characters (`_') to the right of the names of Fortran 77 routines (as we have done in the appendix). Your system may do something different and you may have to experiment with moving the `_' or, perhaps, eliminating it!

If you cannot find the LAPACK or BLAS libraries for your machine, Appendix C gives links to the P480 home page where you can down-load C code for the LAPACK and BLAS routines that you will need, and some hints for compiling. (Thanks to Nick Bailey, the grader for Spring 2000, for getting this for you!) Note that the code will run a lot faster if you can use the vendor-supplied BLAS provided there for Pentium/Linux machines.

Finally, if you are compiling under Linux, something like the following compile statement (all on one command line!) will probably get the code to compile:

cc -O3 -fomit-frame-pointer lapack.c p480.o nrutil.o -o lapack -L... -llapack -lblas -lf2c -lm
where ``...'' represents the full path name of the directory where the ``liblapack.a'' and ``libblas.a ''files appears. Don't hesitate to ask for help in getting this code to compile!

Important Note: To use LAPACK from C in real applications, it is important to keep in mind that LAPACK is written in Fortran and expects matrices to be stored in memory in the opposite order from C. This means that, if you start in C, you should send LAPACK the transposes of any matrices (and expect to get transposes back). For the test program in this example, we work with symmetric matrices -- so this transposing isn't needed!


next up previous contents
Next: Infrastructure Up: No Title Previous: Contents

Tomas Arias
Sun Apr 15 19:43:40 EDT 2001