Installation and Use of Common Scientific Libraries in Unix Part 2: LAPACK and its wrappers LAPACKE and ATLAS
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
By ejspeiro at 2012-05-17 18:08
By. Eduardo J. Sanchez P. (ejspeiro)
Hi guys, since my research work has lead me to the necessity of using some important scientific libraries, I have decided to contribute to the tutorials section with this humble collection of summaries about how to install these libraries. An important purpose shall be to explicitly depict the hierarchical dependence among the libraries, while at the same time, as it's been already stated, to explain the basic mechanics of the installations.
I will assume (i) that a first semester Computer Science student has been asked to install these to perform basic operations with them. I believe that the arising knowledge from using them is highly more valuable that the annoying research required to figure this out for the novice user.
I will also assume that (ii) all the libraries are meant to be installed in the ~/Libraries directory. For example, in my computer:
$ echo ~
The libraries under consideration in this part (Part 2 out of probably 3) are:
1. LAPACK (Linear Algebra PACKage) and LAPACKE [ http://www.netlib.org/lapack/ ]. Quoting from LAPACK's presentation section in their website: LAPACK is written in Fortran 90 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.
2. ATLAS (Automatically Tuned Linear Algebra Software) [ http://math-atlas.sourceforge.net/ ]. Quoting: The ATLAS (Automatically Tuned Linear Algebra Software) project is an ongoing research effort focusing on applying empirical techniques in order to provide portable performance. At present, it provides C and Fortran77 interfaces to a portably efficient BLAS implementation, as well as a few routines from LAPACK.
Once we have access to the downloaded folder, we can begin the building process. LAPACK requires cmake as it is stated in its README file. Part 1 of these tutorials explains how to install any required application easily.
Before building we need to configure the installation in the inclusion file for the Makefile. Specifically, we have to modify make.inc. One can easily obtain a very good approximation for that file by utilizing the provided example:
Notice that this specific file can be extracted as follows:
~/Libraries$ bunzip2 -c atlas3.8.4.tar.bz2 | tar xfm -
Once we have extracted the files, we may want to rename ATLAS' folder to a less generic name:
~/Libraries$ mv ATLAS/ ATLAS_3.8.4-CORE
Excellent!!! Let us proceed with installing ATLAS, which is not as straightforward as the other libraries!!! Mainly because we have to configure ATLAS in a way that it can study our architecture to provided for optimized BLAS and LAPACK routines, thus tailoring the construction of these to our architecture, thus boosting performance! Similarly, we want to test this attained performance boost!!!
STEP 1: Turn off CPU throttling (frequency scaling) when installing ATLAS.
This is necessary since, according to ATLAS' authors, this feature makes all the timing taken in order to study the architecture, well: to be junk! XD In my computer, I first inquired regarding this being on or off by doing the following:
since those are in Hertz, then my processor is capable of 1.73 GHz, 1.33 GHz and 1.06 GHz and 0.80 GHz. Now that we know that our CPU(s) can handle scaling, let us now inquire about the modes available:
Thanks to  for helping me with this explanation!
STEP 2: Install a BOGUS ATLAS to learn about the preferred applications for your computer.
In order to minimize compiler/flag interoperability problems between ATLAS and both of your BLAS and LAPACK libraries, we want to build LAPACK with the same flags you use to compile ATLAS's FORTRAN API routines with. Clearly, this looks like a a chicken and egg problem, since we would like to install LAPACK BEFORE installing ATLAS. Therefore, we will only do a BOGUS CONFIGURATION step within the ATLAS' installation, in order to figure out the best flags. Notice that, I had been using -O3, for example, but ATLAS might inquire a different optimization flag that suits the best for my architecture! Therefore, I should go back AND RE INSTALL ALL OF THE OTHER LIBRARIES WITH THIS INFORMATION!!! Let us proceed with the bogus installation:
~/Libraries$ cd ATLAS_3.8.4-CORE/
~/Libraries/ATLAS_3.8.4-CORE$ mkdir BOGUS_ATLAS_INSTALL_DIR # For bogus configuration.
~/Libraries/ATLAS_3.8.4-CORE$ mkdir ATLAS_3.8.4-BUILD-Citadel # For real configuration.
~/Libraries/ATLAS_3.8.4-CORE$ cd BOGUS_ATLAS_INSTALL_DIR/
:O So ATLAS Prefers -O instead of -O3! Notice that the internal variable being called F77 implies nothing with respect to the fact that LAPACK is written in Fortran 90! The important thing is the information about the compiler that it contains! The same for F77FLAGS!
STEP 3: Erase the bogus installation directory AND reinstall BLAS AND LAPACK using the attained information from ATLAS!
This is just a matter of going back, cleaning and rebuilding both libraries!
This is how the new variable have changed for my LAPACK installation:
FORTRAN = gfortran
OPTS = -O -m32
DRVOPTS = $(OPTS)
NOOPT = -m32
LOADER = gfortran
LOADOPTS = $(OPTS)
TIMER = INT_ETIME # Now we are sure that the compiler is indeed gfortran!
CC = gcc
CFLAGS = -O -fomit-frame-pointer -m32
Notice that we have now specified our working LAPACK library!
Before building verify that the produced Make.inc has correctly recognized both the shell and the ranlib application you are actually using!
You will see cool things as for example, how ATLAS computes the size of you L1 cache and so forth!!! Be aware that this step can take up to ONE HOUR depending on you platform. In my case it took me around .
STEP 5: Perform the sanity tests and check for a correct install! And finally, install!
~/Libraries/ATLAS_3.8.4-CORE/ATLAS_3.8.4-BUILD-Citadel$ make check
~/Libraries/ATLAS_3.8.4-CORE/ATLAS_3.8.4-BUILD-Citadel$ make time
~/Libraries/ATLAS_3.8.4-CORE/ATLAS_3.8.4-BUILD-Citadel$ make install
I would like to encourage carefully reading ATLAS User Guide, the one that comes with the installation! There you
will find valuable information regarding related topics to the installation!
Finally  provides an excellent example on how to use ATLAS' LAPACK!