3

I found that using one of BLAS/ATLAS/MKL/OPENBLAS will give improvement on speed in R. However, will it still improve the R Package that is written in C or C++? for example, R package Glmnet is implemented in FORTRAN and R package rpart is implemented in C++. Will it just installing BLAS/...etc will improve the execution time? or do we have to rebuild (building new C code) the package based on BLAS/...etc?

Tay Shin
  • 528
  • 4
  • 17
  • You have to compile everything against BLAS/ATLAS/MKL/OPENBLAS, i.e. R itself as well as all the packages that need compilation. –  May 01 '15 at 09:07
  • Thanks for the comment Pascal. So will it be speed improvement to use existing C/C++ code R package if I compile with BLAS/ATLAS etc? – Tay Shin May 01 '15 at 09:11
  • @Pascal: That is incorrect, and I provided a little more detail below. – Dirk Eddelbuettel May 01 '15 at 11:44
  • @DirkEddelbuettel Only incorrect for Debian-based Linux, right?. –  May 01 '15 at 12:05
  • Correct on every system where R is built to use the system-provided LAPACK and BLAS. I'd say "almost all but Windows". – Dirk Eddelbuettel May 01 '15 at 12:26

1 Answers1

10

It is frequently stated, including in a comment here, that "you have to recompile R" to use different BLAS or LAPACK library. That is wrong.

You do not have to recompile R provided it is build against the shared library versions of BLAS and LAPACK.

I have a package and vignette on CRAN which uses this fact to provide a benchmarking framework in which different BLAS and LAPACK version are timed against each just by installing different ones (one commmand in Debian/Ubuntu) and running benchmarks -- this is so straightforward that it can be automated in a package such as this.

The results in that package will provide an idea of the possible speed differences. Exactly how they pan out depends on your computer, your data (size), your problem etc. But if, say, your problem uses LAPACK functions which can run benefit from running multithreaded then installing OpenBLAS may help. That is true for any R package using LAPACK as they will use the same LAPACK installation accessed through are, and these can be changed.

Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725
  • Never Thought that the writer of package "gcbd" made a comment here. I read the vignette and your package before I asked a question though. I guess I didn't understand it very well. Anyway, thank you very much ! :D – Tay Shin May 01 '15 at 23:27