Instruction for using LAPACK in c on Linux.
Installation
- Install BLAS
- Download latest version from http://www.netlib.org/blas/.
- Untar
$cd BLAS-*/
$make
- get lib
blas*.a
- Download latest version from http://www.netlib.org/lapack/.
- Untar
$cd lapack-*/
$cp make.inc.example make.inc
and change line 81 to point toblas*.a
$make lib
$make lapackelib
$make cblaslib
- Move files in
LAPACKE/include/
andCBLAS/include/
to someinclude/
you are familiar with. - Move ‘lapacke’, ‘lapack’, ‘blas’, ‘cblas’ librarys to some
lib/
you are familiar with, and rename them asliblapacke.a
,liblapack.a
,libblas.a
,libcblas.a
.
Test
- Get test program from http://www.netlib.org/lapack/lapacke.html.
- Compile with
$gcc test_lapack.c -L lib/ -llapacke -llapack -lcblas -lblas -lgfortran -lm -I include/ -o test_lapack
Documentation
- http://www.netlib.org/lapack/explore-html/index.html
- This documentation have specific defination for all lapack functions. But, if you want to use some function
f()
in lapack, you should useLAPACKE_f()
orcblas_f()
, you can see parameters ofLAPACKE_f()
orcblas_f()
in this documentation as well, but there are no details.
Functions
#include <lapacke.h>
for lapacke functions, #include <cblas.h>
for cblas functions
cblas_dtrsm
void cblas_dtrsm (const CBLAS_LAYOUT layout, const CBLAS_SIDE Side, const CBLAS_UPLO Uplo, const CBLAS_TRANSPOSE TransA, const CBLAS_DIAG Diag, const int M, const int N, const double alpha, const double \*A, const int lda, double \*B, const int ldb)
layout
:CblasRowMajor
orCblasRowMajor
Side
:CblasLeft
orCblasRight
, same meaning asSIDE
indtrsm()
Uplo
:CblasLower
orCblasUpper
, same meaning asUPLO
indtrsm()
TransA
:CblasNoTrans
orCblasTrans
, same meaning asTRANSA
indtrsm()
Diag
:CblasNonUnit
orCblasUnit
, same meaning asDIAG
indtrsm()
alpha
: same meaning asALPHA
indtrsm()
A
: same meaning asA
indtrsm()
B
: same meaning asB
indtrsm()
If you are using CblasRowMajor
, and A
is a square matrix:
M
: length of each edge ofA
N
: number of columns inB
LDA
: the same asM
LDB
: the same asN
FAQ
What is LDA?
(http://icl.cs.utk.edu/lapack-forum/viewtopic.php?f=2&t=1897)
On LDA, the doc says:
- LDA (input) INTEGER
- The leading dimension of the array A. LDA >= max(1,N).
Now N is the number of columns in the input matrix. But the input matrix is symmetric, so we’d expect it to be N x N, right? In that case LDA = N. The “>=” part in the comment just allows for the possibility that the input matrix A is in fact part of a larger array, with a greater number of rows than are actually used in this function. But unless you’re doing something tricksy, “LDA” is just the rows of A, and equals N.
Understunding of mine: While storing a matrix A
in memory, the jth element of ith row A[i][j]
can also be A[i*n+j]
, which means the (i*n+j)th element in A
, where n
is the number of elements in each row. However, while you are using part of a matrix to compute, for example part of A
, A'
, A'[i][j]
is the (i*n+j)th element of A'
, but n
is no longer the number of elements in each row of A'
. As a result, you need to tell the computer A'
is part of a larger matrix A
using LDA=n
.
In conclution, LDA
is the number of elements in each row of the matrix you stored in memory.