Difference between revisions of "The BLAS and LAPACK libraries"

From Planets
Jump to: navigation, search
Line 1: Line 1:
The BLAS and LAPACK libraries are very common libraries useful for doing linear algebra operations involving matrices and vectors, .e.g. solving linear equation systems, doing SVD factorization, etc.
+
The BLAS (Basic Linaer Algebra) and LAPACK (Linear Algebra PACKage) libraries are very common libraries useful for doing linear algebra operations involving matrices and vectors, .e.g. solving linear equation systems, doing SVD factorization, etc.
 
In many case they are already installed and available Linux systems, but not always... and then you will have to download and install them yourself.
 
In many case they are already installed and available Linux systems, but not always... and then you will have to download and install them yourself.
  
Line 20: Line 20:
 
make
 
make
 
</syntaxhighlight>
 
</syntaxhighlight>
which should produce the static library '''blas_UNIX.a'''. It is good practice to usually use a different naming convention and call the library '''libblas.a''' so you can make a symbolic link to have both available:
+
which should produce the static library '''blas_LINUX.a'''. It is good practice to usually use a different naming convention and call the library '''libblas.a''' so you can make a symbolic link to have both available:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
ln -s blas_LINUX.a libblas.a
 
ln -s blas_LINUX.a libblas.a
Line 27: Line 27:
  
 
=== Compiling the LAPACK library ===
 
=== Compiling the LAPACK library ===
Assuming you dowloaded the package in a "LAPACK" directory, edit the '''make.inc''' to fit your settings, if needed and simply run
+
Assuming you dowloaded the package in a "LAPACK" directory, e.g.:
 +
<syntaxhighlight lang="bash">
 +
wget https://github.com/Reference-LAPACK/lapack/archive/refs/tags/v3.11.0.tar.gz
 +
tar xvzf v3.11.0.tar.gz
 +
cd lapack-3.11.0
 +
</syntaxhighlight>
 +
copy the provided '''make.inc.example''' as '''make.inc''' and adapt it to fit your settings (e.g. compiler name and options), if needed, and the run:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
make
 
make

Revision as of 09:27, 24 May 2023

The BLAS (Basic Linaer Algebra) and LAPACK (Linear Algebra PACKage) libraries are very common libraries useful for doing linear algebra operations involving matrices and vectors, .e.g. solving linear equation systems, doing SVD factorization, etc. In many case they are already installed and available Linux systems, but not always... and then you will have to download and install them yourself.

Obtaining the source code of the BLAS and LAPACK libraries

The Fortran source codes are available on Netlib.org : http://www.netlib.org/blas/ and http://www.netlib.org/lapack/

Compiling the libraries

Prerequisites

All you need are a Fortran compiler and the gmake utility

Compiling the BLAS library

Assuming you dowloaded the package in a "BLAS" directory, e.g.:

wget http://www.netlib.org/blas/blas-3.11.0.tgz
tar xvzf blas-3.11.0.tgz
cd BLAS-3.11.0/

Edit the make.inc to fit your settings (e.g. compiler name and options), if needed and the simply run

make

which should produce the static library blas_LINUX.a. It is good practice to usually use a different naming convention and call the library libblas.a so you can make a symbolic link to have both available:

ln -s blas_LINUX.a libblas.a


Compiling the LAPACK library

Assuming you dowloaded the package in a "LAPACK" directory, e.g.:

wget https://github.com/Reference-LAPACK/lapack/archive/refs/tags/v3.11.0.tar.gz
tar xvzf v3.11.0.tar.gz
cd lapack-3.11.0

copy the provided make.inc.example as make.inc and adapt it to fit your settings (e.g. compiler name and options), if needed, and the run:

make

Linking to the libraries

One simply needs to specify options

-Lpath/to/the/LAPACK/library -llapack -Lpath/to/the/BLAS/library -lblas

at compile time. Note the ordering: as some LAPACK routines reliy on BLAS routines one must specify the LAPACK library first