# Handle different versions of BLAS and LAPACK

## Description

Beside being implementations, BLAS and LAPACK are also API standard for basic linear algebra operations (such as vector and matrix multiplication).

Many implementations of these API exist. The reference implementation of BLAS and LAPACK is very stable but is not as fast as optimized ones such as ATLAS and OpenBLAS.

Implementations of BLAS:

blas - Reference implementation

atlas - Automatically Tuned Linear Algebra Software

openblas - OpenBLAS, an optimized BLAS based on GotoBLAS2

gsl - GNU Scientific Library (not ABI-compatible with the others, because it uses row major ordering)

- Intel MKL - Non-free
- AMD ACML - Non-free
- Sun Performance Library - Non-free
- ...

Implementations of LAPACK:

lapack - Reference implementation

- ATLAS and OpenBLAS both provide an optimized subset of LAPACK
- LAPACK++

## How to switch from an implementation to the other

It is just trivial. It can be used like any other software using `update-alternatives`.

### BLAS

update-alternatives --config libblas.so.3

Example:

There are 3 choices for the alternative libblas.so.3 (providing /usr/lib/libblas.so.3). Selection Path Priority Status ------------------------------------------------------------ * 0 /usr/lib/openblas-base/libopenblas.so.0 40 auto mode 1 /usr/lib/atlas-base/atlas/libblas.so.3 35 manual mode 2 /usr/lib/libblas/libblas.so.3 10 manual mode 3 /usr/lib/openblas-base/libopenblas.so.0 40 manual mode

### LAPACK

update-alternatives --config liblapack.so.3

Example:

There are 3 choices for the alternative liblapack.so.3 (providing /usr/lib/liblapack.so.3). Selection Path Priority Status ------------------------------------------------------------ * 0 /usr/lib/openblas-base/liblapack.so.3 40 auto mode 1 /usr/lib/atlas-base/atlas/liblapack.so.3 35 manual mode 2 /usr/lib/lapack/liblapack.so.3 10 manual mode 3 /usr/lib/openblas-base/liblapack.so.3 40 manual mode

## Getting the best performance out of ATLAS and OpenBLAS

The binary packages of ATLAS and OpenBLAS distributed by Debian are generic packages, which are not optimized for your specific machine.

The optimal way of using these two packages is to recompile them locally on the machines on which they are to be used. See the `README.Debian` file of the respective packages for details on how to achieve that easily.

## TODO

- Check for other implementations (CUBLAS, MKL in non-free, ACML in non-free)