from:http://www.stat.cmu.edu/~nmv/2013/07/09/ for-faster-r-use-openblas-instead-better-than-atlas-trivial-to-switch-to-on-ubuntu/
installing additional BLAS libraries on Ubuntu
For Ubuntu, there are currently three different BLAS options so can be easily chosen: "Libblas" the reference BLAS, "Lib Atlas "The Atlas BLAS, and" Libopenblas "the Openblas. Their package names are
$ apt-cache Search Libblas
libblas-dev-basic Linear algebra subroutines 3, Static library
libblas-doc-basic Li Near Algebra subroutines 3 documentation Libblas3gf-basic Linear algebra Reference implementations
, shared library< c3/>libatlas-base-dev-automatically Tuned Linear algebra Software, generic static
libatlas3gf-base-automatically Tuned Linear algebra Software, generic shared libblas-test-basic Linear algebra subroutines
3, testing
programs Libopenblas-base-optimized BLAS (linear algebra) library based on GotoBLAS2 libopenblas-dev-optimized
(BLAS Algebra) Library based on GotoBLAS2
Since Libblas already comes with Ubuntu, we have need to install the "other" for our two. (note:in The following command, delete ' libatlas3gf-base ' If you don ' t want to experiment with ATLAS.):
$ sudo apt-get install libopenblas-base libatlas3gf-base
switching between BLAS libraries
Now we can switch between the different BLAS options that are installed:
$ sudo update-alternatives--config libblas.so.3
There are 3 choices for the alternative LIBBLAS.SO.3GF (providing/us R/LIB/LIBBLAS.SO.3GF).
Selection Path Priority Status
------------------------------------------------------------
* 0/usr/lib/ openblas-base/libopenblas.so.0 Auto mode
1/USR/LIB/ATLAS-BASE/ATLAS/LIBBLAS.SO.3GF manual mode
2/usr/ LIB/LIBBLAS/LIBBLAS.SO.3GF Manual mode
3/usr/lib/openblas-base/libopenblas.so.0 Manual mode
Press ENTER To keep the current choice[*], or type selection number:
Side Note:If the above returned:
Update-alternatives:error:no Alternatives for LIBBLAS.SO.3GF
Try
$ sudo update-alternatives--config libblas.so.3
instead. The comments at the "end of" the post for further details.
From the selection menu, I picked 3, so it now shows this choice 3 (Openblas) is selected:
$ sudo update-alternatives--config libblas.so.3gf
There are 3 choices for the alternative LIBBLAS.SO.3GF (providing/ USR/LIB/LIBBLAS.SO.3GF).
Selection Path Priority Status
------------------------------------------------------------
0/usr/lib/ openblas-base/libopenblas.so.0 Auto mode
1/USR/LIB/ATLAS-BASE/ATLAS/LIBBLAS.SO.3GF manual mode
2/usr/ LIB/LIBBLAS/LIBBLAS.SO.3GF Manual Mode
* 3/usr/lib/openblas-base/libopenblas.so.0 manual mode
And we can pull the same trick to choose between LAPACK. From the output we can do so Openblas does not provide a new LAPACK implementation, but ATLAS does:
$ sudo update-alternatives--config liblapack.so.3
There are 2 choices for the alternative LIBLAPACK.SO.3GF (providing /USR/LIB/LIBLAPACK.SO.3GF).
Selection Path Priority Status
------------------------------------------------------------
* 0/usr/lib/ ATLAS-BASE/ATLAS/LIBLAPACK.SO.3GF Auto mode
1/USR/LIB/ATLAS-BASE/ATLAS/LIBLAPACK.SO.3GF Manual mode
2/ USR/LIB/LAPACK/LIBLAPACK.SO.3GF Manual Mode
So we'll do the since openblas are supposed to use the reference implementation (which is already selec Ted). Checking that R are using the right BLAS
Now we can check this everything is working by starting R in a new terminal:
$ r
R version 3.0.1 (2013-05-16)--"good sport"
Copyright (C) 2013 the R Foundation for statistical computing
platform:x86_64-pc-linux-gnu (64-bit) ... snip ...
Type ' Q () ' to quit R.
>
Great. Let's the If R is using the BLAS and LAPACK libraries we selected. To did so, we open another terminal so we can run a few the more shell commands. We find the PID of the R process we just started. Your output would look something like this:
$ ps aux | grep exec/r
1000 18065 0.4 1.0 200204 87568 pts/1 sl+ 09:00 0:00/usr/lib/r/bin/exec/r
root 19250 0.0 0.0 9396 916 pts/0 s+ 09:03 0:00 grep--color=auto exec/r
The PID is the second number on the '/usr/lib/r/bin/exec/r ' line. to the
Which BLAS and LAPACK libraries are loaded with this R session, we use the "List open files" command:
$ lsof-p 18065 | grep ' Blas\|lapack '
r 18065 Nathanvan mem REG 8,1 9342808 12857980/usr/lib/lapack/liblapack.so.3gf.0
R 18065 NAT Hanvan mem REG 8,1 19493200 13640678/usr/lib/openblas-base/libopenblas.so.0
As expected, the R session is using the reference LAPACK (/usr/lib/lapack/liblapack.so.3gf.0) and Openblas (/usr/lib/openb las-base/libopenblas.so.0) Testing the different blas/lapack combinations
I used Simon Urbanek ' s most recent benchmark script. To follow along, the download it to your current working directory:
$ Curl Http://r.research.att.com/benchmarks/R-benchmark-25.R-O
And then run it:
$ Cat R-BENCHMARK-25.R | Time R--slave
Loading required Package:matrix
Loading required Package:lattice Loading required package:s
Uppdists
Warning message: In
Library (package, Lib.loc = Lib.loc, Character.only = True, Logical.return = True,:
there is no package called ' suppdists '
... snip ...
Ooops. I don ' t have the Suppdists package installed. I can easily load it via Michael Rutter ' s Ubuntu PPA:
$ sudo apt-get install r-cran-suppdists
Now Simon's script works wonderfully. Full output
$ Cat R-BENCHMARK-25.R | Time R--slave Loading required Package:matrix Loading required Package:lattice Loading required package:suppdists Warn
ing messages:1: In Remove ("A", "B"): Object ' A ' not found 2:in remove ("A", "B"): Object ' B ' not found R Benchmark 2.5 =============== number of times each of the test is run__________________________: 3 I. Matrix calculation-------------------- -Creation, TRANSP., deformation of a 2500x2500 matrix (sec): 1.36566666666667 2400x2400 normal distributed random matrix ^1000____ (sec): 0.959 sorting of 7,000,000 random values__________________ (sec): 1.061 2800x2800 cross-product Matrix (b = A ' * a ' _________ (sec): 1.777 Linear Regr. Over a 3000x3000 matrix (c = a \ B ') ___ (sec): 1.00866666666667--------------------------------------------trimmed geom. Mean (2 extremes eliminated): 1.13484335940626 Ii.
Matrix functions--------------------FFT over 2,400,000 random values____________________ (sec): 0.566999999999998 Eigenvalues of a 640x640 ranDom matrix______________ (sec): 1.379 determinant of a 2500x2500 random matrix________