# [R] Does R use the ATLAS linear algebra library?

Douglas Bates bates at stat.wisc.edu
Sat May 5 05:20:08 CEST 2001

```Thomas Lumley <tlumley at u.washington.edu> writes:

> On Fri, 4 May 2001, M. Edward (Ed) Borasky wrote:
>
> > I was visiting the ATLAS home page and they claim that the R project uses
> > the ATLAS libraries. ATLAS is an adaptive linear algebra library. Is this true?
> > It would save me a *lot* of time if it is :-).
>
> ./configure will detect and use ATLAS if it is present on your system.
> ATLAS is not included with the R distribution, though.

The differences between ATLAS and regular BLAS are most noticeable
when working with large matrices and when using level 3 BLAS.

(The BLAS are Basic Linear Algebra Subroutines.  Level 1 BLAS are
vector-vector operations; level 2 are matrix-vector operations; and
level 3 are matrix-matrix operations.)

Current versions of R use only level 1 BLAS so using ATLAS does not
result in much of a speedup.  Today I did some experiments on the
development (1.3.0) version of R that involved replacing the internals
of the matrix multiplication operator and the crossprod function by a
call to a level 3 BLAS routine (dgemm).

The results are nothing short of astonishing.

Using R-1.2.2 (no level 3 BLAS but with ATLAS)

> mm <- matrix(rnorm(10^6), ncol = 10^3)
> dim(mm)
[1] 1000 1000
> gc()
used (Mb) gc trigger (Mb)
Ncells  174137  4.7     350000  9.4
Vcells 1889966 14.5    3429835 26.2
> system.time(mm %*% mm)
[1] 59.07  0.04 69.32  0.00  0.00
> system.time(crossprod(mm))
[1] 25.76  0.02 30.27  0.00  0.00

Using R-1.3.0 with level 3 BLAS for %*% but without ATLAS

> system.time(mm %*% mm)
[1] 28.09  0.03 33.14  0.00  0.00
> system.time(crossprod(mm))
[1] 27.97  0.07 32.94  0.00  0.00

Using R-1.3.0 with level 3 BLAS for %*% and ATLAS

> system.time(mm %*% mm)
[1] 2.81 0.03 3.30 0.00 0.00
> system.time(mm %*% mm)
[1] 2.83 0.05 3.58 0.00 0.00
> system.time(crossprod(mm))
[1] 2.84 0.03 3.35 0.00 0.00

We see that using level 3 BLAS results in a 2-fold increase in speed
for %*% and slows crossprod a bit.  However, using level 3 BLAS
and ATLAS results in a 20-fold increase in speed for %*% and about a
10-fold increase in speed for crossprod.

Such speed increases are most noticeable for large matrices.  With
small matrices the time spend in "housekeeping" tasks dominates the
time spent in numerical calculation.

We will incorporate the level 3 BLAS into R-1.3.0.  If you have ATLAS
installed so it can be detected during the configuration of R it
should make linear algebra operations on large matrices faster.
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

```