The Linear Algebra PACKage (LAPACK) library is useful for matrix algebra operations
like singular value decomposition, solving systems of linear equations, and computing
eigenvalues. You may want to consider using it instead of writing your own routines.
For lower level operations like matrix multiplication, see
BLAS. In this tutorial, we will compile and run a program
that uses LAPACK to compute SVDs. Before you begin, make sure to read the
tutorial for compiling C programs.
Where to find documentation
On this page, we'll show how to use LAPACK functionality within AMD Core Math
Library (ACML). We'll assume that you're using the default
"pgi-9.0-mvapich2-1.4rc2" switcher setting - other MPI+compiler combinations
may not work with the code below.
For more information about the LAPACK routines in ACML, see
AMD's ACML websiteLAPACK at Netlib has a lot of
information about the library. One useful section contains FORTRAN code for the procedures
The manual pages on tara (e.g. "man dgesvd") also show the FORTRAN function interfaces
LAPACK User's Guide
The ACML header file on tara shows the C interface.
This file is located in: /usr/cluster/pgi/linux86-64/9.0-4/include/acml.h.
You can browse through this file and see all the available functions and their
arguments & return values. Note that there are two versions of most
functions listed - one with an underscore ("_") at the end, and one without
an underscore. Both are versions of the same functional, but the underscore
version is compatible with FORTRAN conventions, and the no-underscore version
is a bit easier to use.
Example
In this example we will create a matrix, then compute its singular value
decomposition (SVD) using the LAPACK dgesvd function. The SVD of A (m x n)
will consist of U (m x m), S (p x 1, where p = min(m,n)), and VT (n x n)
Our matrices will contain doubles, and be stored in column-major order. Here
is the code