BLAS and LaPack - two very useful librariesGianluca Moro - gianluca.moro@unipd.it14 October 2009 |
This is an overview, mainly to understand the installation process of two basic libraries used in numerical elaborations: in a numerical laboratory you tipically do not need these informations as the libraries are already installed and configured, but it could be interesting to see how to compile them.
These procedures are accomplished as normal user (no root access required): if you need to set up a computer dedicated to numerical elaboration, the setup should be accomplished as root, making everything available system-wide.
The used test machine was a DELL workstation with 2 quad core processors (Intel(R) Xeon(R) E5345, 2.33GHz, 16Gbyte of RAM). The computer is part of “Laboratorio per le Applicazioni Numeriche”, Dipartimento di Matematica Pura ed Applicata, University of Padova, http://numlab.math.unipd.it/, a system running GNU/Linux, Ubuntu 9.04.
The reference site for the BLAS library is http://www.netlib.org/blas/: To read about BLAS, please refer to that site: essentially (from the site): “The BLAS (Basic Linear Algebra Subprograms) are routines that provide standard building blocks for performing basic vector and matrix operations. The Level 1 BLAS perform scalar, vector and vector-vector operations, the Level 2 BLAS perform matrix-vector operations, and the Level 3 BLAS perform matrix-matrix operations. Because the BLAS are efficient, portable, and widely available, they are commonly used in the development of high quality linear algebra software, LAPACK for example.”
The directory /home/myusername is the $HOME directory, or can be any other directory where the user has read/write access.
The obvious answer is that, if you need the BLAS library, and it is not installed on your system, you need to compile it (or ask the system manager to install it for you). But there can be other situations where you could need to compile it: it happened to me to use a machine (Ubuntu 9.04) where I found the BLAS library already installed, but my programs where particularly slow. I recompiled BLAS and used my BLAS version instead of the system one and the program execution time was reduced a lot.
So, if you are not sure if the installed version is correct, well optimized or any other doubt, compile it by yourself ... it’s not so difficult!
$ tar zxf blas.tgz
this will create a directory BLAS.
$ cd BLAS $ make all
that’s all folks!
The package is a bunch of Fortran files, which compiles to a library: if you need to customize something, the correct place is the file make.inc: typically you could customize the name of the library (the variable is called PLAT, its default is blas_LINUX.a) and the fortran compiler (for example FORTRAN = gfortran)
If everything was correct in the previous step, your library is in the BLAS directory, called blas_LINUX.a: you can copy it where you prefer, you just have to set the correct PATH when you want to use it.
The reference site for the LaPack library is http://www.netlib.org/lapack/: “LAPACK is written in Fortran90 and provides routines for solving systems of simultaneous linear equations, least-squares solutions of linear systems of equations, eigenvalue problems, and singular value problems. 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.”
$ tar zxf lapack.tgz
this will create a directory lapack.
The configuration can be done in the make.inc file: the options I modified were:
FORTRAN = gfortran OPTS = -O -m64 ... BLASLIB = /directory/where/to/find/BLAS/blas$(PLAT).a
The LaPack library uses the BLAS library, so you need to tell where to find it. The result is a library lapack_LINUX.a: this can be copied in a place of your choice.
This installation is described just because, if you need BLAS, it’s possible that ATLAS is a good choice for you too.
Be careful: if CPU throttling (automatic CPU frequency change) is enabled in your machine, you need to have root access to disable it (if it is enabled, ATLAS will refuse to compile, unless forced).
ATLAS is a package that optimize the BLAS library for your machine, but, to do so, it needs to get some timing of our machine: if the system keep changing the CPU frequency, the timing will be useless and I (and ATLAS developers too) do not know what the compilation will produce. (i.e.: you are adviced to keep the standard BLAS).
To get ATLAS (and infos about it), please refer to the site http://math-atlas.sourceforge.net/
After unpackaging the sources, you can configure it using the given script:
$ cd ATLAS $ mkdir build $ cd build $ ../configure --prefix=/home/myusername/INSTALLED \ --with-netlib-lapack-tarfile=/home/myusername/lapack-3.2.1.tar.gz --shared -b 64 -Si cputhrchk 0 $ make build $ make install
Some notes:
This document was translated from L^{A}T_{E}X by H^{E}V^{E}A.