The library has been converted to Fortran 90
The associated matrix factorizations (LU, Cholesky, QR, SVD, Schur, generalized Schur) are also provided, as are related computations such as reordering of the Schur factorizations and estimating condition numbers. Dense and banded matrices are handled, but not general sparse matrices. In all areas, similar functionality is provided for real and complex matrices, in both single and double precision. |
|
|
F77 restricts names to 6 characters
XYYZZZ |
The encoding scheme used is:
X = type of problem that the routine solves S Single precision real D Double precision real C Single complex Z Double precision complex YY = Matrix types BD bidiagonal DI diagonal GB general band GE general (i.e., unsymmetric, in some cases rectangular) GG general matrices, generalized problem (i.e., a pair of general matrices) GT general tridiagonal HB (complex) Hermitian band HE (complex) Hermitian HG upper Hessenberg matrix, generalized problem (i.e a Hessenberg and a triangular matrix) HP (complex) Hermitian, packed storage HS upper Hessenberg OP (real) orthogonal, packed storage OR (real) orthogonal PB symmetric or Hermitian positive definite band PO symmetric or Hermitian positive definite PP symmetric or Hermitian positive definite, packed storage PT symmetric or Hermitian positive definite tridiagonal SB (real) symmetric band SP symmetric, packed storage ST (real) symmetric tridiagonal SY symmetric TB triangular band TG triangular matrices, generalized problem (i.e., a pair of triangular matrices) TP triangular, packed storage TR triangular (or in some cases quasi-triangular) TZ trapezoidal UN (complex) unitary UP (complex) unitary, packed storage ZZZ = indicate the computation performed e.g., SV = Solve, SVX = Solve Expert |
(See: click here)
gunzip manpages.tgz tar xvf manpages.tar |
/home/cs561000/man/manl/* |
Try:
nroff -man /home/cs561000/man/manl/sgesv.l | more |
|
"Learning" about LAPack is not the object of this course.
I leave that to your exploratory endeavor.
But I will show you how to use LAPack so you can use the libray when you find the need for it.
nroff -man /home/cs561000/man/manl/sgesv.l | more |
Summary:
SUBROUTINE SGESV( N, NRHS, A, LDA, IPIV, B, LDB, INFO ) INTEGER N INTEGER NRHS REAL A(:,:) INTEGER LDA INTEGER IPIV(:) REAL B(:,:) INTEGER LDB INTEGER INFO |
PROGRAM Main IMPLICIT NONE REAL :: A(3,3), b(3) INTEGER :: i, j, pivot(3), ok ** Initialize A(:,:) ** Initialize b(:) CALL SGESV(3, 1, A, 3, pivot, b, 3, ok) PRINT *, b !! Print solution END PROGRAM |
Compile using the following commands:
|
|
See: click here
Example:
#define SIZE 3 float A[SIZE][SIZE]; // A matrix float AT[SIZE*SIZE]; // A transposed matrix for (i=0; i < SIZE; i++) { for(j=0; j < SIZE; j++) AT[j+SIZE*i]=A[j][i]; } |
Let me illustrate the caveat with the subroutine SGESV
PROGRAM Main IMPLICIT NONE REAL :: A(3,3), b(3) INTEGER :: i, j, pivot(3), ok ** Initialize A(:,:) ** Initialize b(:) CALL SGESV(3, 1, A, 3, pivot, b, 3, ok) PRINT *, b !! Print solution END PROGRAM |
A naive translation into C++ would result in:
int main(int argc, char **argv) { int i, j , pivot[SIZE], ok; float A[SIZE][SIZE], b[SIZE]; float AT[SIZE*SIZE]; // Initialize A(:,:) // Initialize b(:) for (i=0; i < SIZE; i++) // Convert to Fortran storage format { for(j=0; j < SIZE; j++) AT[j+SIZE*i]=A[j][i]; } sgesv_(3, 1, AT, 3, pivot, b, 3, &ok) } |
Compile using the following commands:
|
You will get compilation error
Caveat
|
This makes sense if you think throught it a little bit:
|
int main(int argc, char **argv) { int i, j , c1, c2, pivot[size], ok; /* Used to store constants */ float A[size][size], b[size]; /* Input problem */ float AT[size*size]; /* Help variable - stores column major */ // Initialize A() // Initialize b()... /* ********************************* */ /* Convert row-major to column major */ /* ********************************* */ for (i=0; i < size; i++) { for (j=0; j < size; j++) AT[j+size*i]=A[j][i]; } c1=size; /* Put all CONSTANTS we want to pass */ c2=1; /* to the routine in VARIABLES */ /* Find solution using LAPACK routine SGESV. */ /* 1. all the arguments have to be passed by reference */ /* 2. you have to add an underscore to the routine name */ sgesv_ (&c1, &c2, AT, &c1, pivot, b, &c1, &ok); for (j=0; j < size; j++) printf("%f\n", b[j]); /* print solution vector */ } |
Notice that you must store a constant in a variable in order to pass the constant value by-reference
Compile using the following commands:
|