Compiling Linear Algebra Libraries

Compiling Linear Algebra Libraries

This post would show how to compile a software suite of linear algebra libraries. Those linear algebra math libraries have been generously used for compiling a mid- and top-level scientific programming such as Fortran, C, and C++.

Linear algebra software I am installing are following

  • Basic Linear Algebra Subprogram (BLAS)
  • Linear Algebra Package (LAPACK)
  • C/C++ interface to BLAS (CBLAS)
  • Scalable Linear Algebra PACKage (ScaLAPACK)
  • Automatically Tuned Linear Algebra Soft (ATLAS)
  • Intel Math Kernel Library (MKL)

Their latest versions can be obtained from Netlib Repository: http://www.netlib.org/liblist.html, except ATLAS, which its latest version is available at https://sourceforge.net/projects/math-atlas/files/Stable/ as well as Intel MKL that available only at Intel software suite website.

Caveat

  1. I am using GNU Compiler and OpenMPI of writing this post.
  2. I installed all libraries in the home directory (/home/rangsiman/).

BLAS

See LAPACK

LAPACK

Due to a low-level BLAS software is part of LAPACK, thus I installed only LAPACK. No need to install BLAS separately.

1. Download tarball of LAPACK from this website http://www.netlib.org/lapack/.

2. There will be LAPACK directory called lapack-3.8.0. (the current version of this writing)

3. Move to LAPACK directory

cd lapack-3.8.0

4. Create make.inc by copying from makefile.inc.example, which is a standard one.

cp make.inc.example make.inc

5. Compile and Install using Makefile.

make blaslib
make

6. After installation is finished, there must be three libraries in LAPACK directory:

  • liblapack.a
  • librefblas.a
  • libtmglib.a

7. Create symbolic link of librefblas.a as libblas.a library.

ln -s librefblas.a libblas.a

CBLAS

libblas.a library is required for compiling CBLAS

1. Download the tar.gz. file of CBLAS from BLAS forum on Netlib repository to your Linux

2. Unpack the tar file using following command

tar -xzvf cblas.tgz

3. Move to CBLAS directory

cd CBLAS

4. Edit PATH of libblas.a and name of CBLAS library at line 26 and 27 in Makefile.in file

vi Makefile.in
BLLIB = /home/u31rkk00/lapack-3.8.0/libblas.a
CBLIB = ../lib/libcblas.a

libblas.a can be obtained from LAPACK directory, where you installed in previous section.

5. Install CBLAS using make

make

6. After installation is completed, there must be libcblas.a in CBLAS/lib sub-directory.

ScaLAPACK

1. Download the tar.gz. file of ScaLAPACK from Netlib repository to your Linux

http://www.netlib.org/scalapack/#_software

2. Unpack the tar file using following command

tar -xzvf scalapack-2.0.2.tgz

3. Move to ScaLAPACK directory

cd scalapack-2.0.2

4. Copy SLmake.inc.example to SLmake.inc.

cp SLmake.inc.example SLmake.inc

5. Install ScaLAPACK using make

make

This can take several minutes.

6. After installation is completed, there must be libscalapack.a in ScaLAPACK directory.


However, for alternative ways, if you are using Ubuntu you can use apt to install ScaLAPACK by running:

sudo apt install scalapack-mpi-test

or using Red Hat-based OS, run following command instead:

sudo yum install scalapack-mpich2

ATLAS

I am going to install ATLAS under my home directory as normal user.

1. Uncompress tarball

mv tlas3.8.3.tar.gz $HOME/
cd $HOME
tar -xzvf atlas3.8.3.tar.gz

2. Create new directory (either inside or outside ATLAS directory), for example, ATLAS_BUILD

mkdir $HOME/ATLAS_BUILD

3. Move to ATLAS_BUILD directory and run configure script (from ATLAS directory) to set up compilation configuration.

cd $HOME/ATLAS_BUILD
../ATLAS/configure

4. Compile ATLAS using following commands*

make

You may run compilation using parallel making, says use 8 processors

make -j 8

This step can take several minutes/hours (depending on your computer performance).

5. Then check library before install

make check
make ptcheck
make time

If having many error occur while checking program, you might ignore those error and proceed next step.

6. Install software

make install

When installation is finished (with or without error), please check if there is linear algebra library of CBLAS, LAPACK, and ATLAS at $HOME/ATLAS_INSTALL/lib/.

7. Done

Error while compiling ATLAS

There is two error that most users frequently face when install ATLAS using make install command.

1. Cannon create /usr/local/atlas

The default setting of target directory of compiled ATLAS library is /usr/local/atlas. If you are not root or sudo, you cannot install anything on global shared space. Thus you should tell make to install ATLAS under your home directory. Refer to a Makefile file at line 3, for example, change

DESTDIR=/usr/local/atlas

to

DESTDIR=/home/rangsiman/ATLAS_INSTALL

2. Cannot find some libraries

cp: cannot stat ‘/home/rangsiman/ATLAS_BUILD/lib/libsatlas.dylib’: No such file or directory
make[1]: [install_lib] Error 1 (ignored)
cp /home/u31rkk00/ATLAS_BUILD/lib/libtatlas.dylib /home/u31rkk00/ATLAS_INSTALL/lib/.
cp: cannot stat ‘/home/rangsiman/ATLAS_BUILD/lib/libtatlas.dylib’: No such file or directory
make[1]: [install_lib] Error 1 (ignored)
cp /home/u31rkk00/ATLAS_BUILD/lib/libsatlas.dll /home/u31rkk00/ATLAS_INSTALL/lib/.
cp: cannot stat ‘/home/rangsiman/ATLAS_BUILD/lib/libsatlas.dll’: No such file or directory
make[1]: [install_lib] Error 1 (ignored)
cp /home/u31rkk00/ATLAS_BUILD/lib/libtatlas.dll /home/u31rkk00/ATLAS_INSTALL/lib/.
cp: cannot stat ‘/home/rangsiman/ATLAS_BUILD/lib/libtatlas.dll’: No such file or directory
make[1]: [install_lib] Error 1 (ignored)
cp /home/u31rkk00/ATLAS_BUILD/lib/libsatlas.so /home/u31rkk00/ATLAS_INSTALL/lib/.
cp: cannot stat ‘/home/rangsiman/ATLAS_BUILD/lib/libsatlas.so’: No such file or directory
make[1]: [install_lib] Error 1 (ignored)
cp /home/u31rkk00/ATLAS_BUILD/lib/libtatlas.so /home/u31rkk00/ATLAS_INSTALL/lib/.
cp: cannot stat ‘/home/rangsiman/ATLAS_BUILD/lib/libtatlas.so’: No such file or directory
make[1]: [install_lib] Error 1 (ignored)
make[1]: Leaving directory `/home/u7/u31rkk00/ATLAS_BUILD'

These error massages can be ignored as long as the static libraries of linear algebra software are build successfully.

All library files should be stored at /home/rangsiman/ATLAS_INSTALL/lib/ directory.

MKL

Intel MKL provides a suite of ready-to-use math libraries including optimized linear algebra and Fast Fourier Transforms (FFT). Qualified student or educator and open-source software developer can obtain Intel MKL free of charge from https://software.intel.com/en-us/mkl.

The feature of MKL includes

Rangsiman Ketkaew