Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
These code snippets have been tested on R 3.1.0 and Mac OS 10.9.3. They presumably do *not* work on R 2.X!
## Enter these commands in the Mac OS Terminal
# use faster vecLib library
cd /Library/Frameworks/R.framework/Resources/lib
ln -sf /System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Versions/Current/libBLAS.dylib libRblas.dylib
# return to default settings
cd /Library/Frameworks/R.framework/Resources/lib
ln -sf libRblas.0.dylib libRblas.dylib
# R script for benchmarking:
# http://r.research.att.com/benchmarks/R-benchmark-25.R
# On 2011 Macbook Pro (2.7 GHz Core i7): 43 sec. (Rblas) vs. 9 sec. (vecLib)
@Feakster

This comment has been minimized.

Copy link

commented Apr 5, 2017

Do you know whether it's also possible to symlink the libLAPACK.dylib to R in place of the libRlapack.dylib?

I've tried:

cd /Library/Frameworks/R.framework/Resources/lib
mv libRlapack.dylib libRlapack.dylib.backup
ln -sf /System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Versions/Current/libLAPACK.dylib libRlapack.dylib

However R throws up an error upon launch.

@tvatter

This comment has been minimized.

Copy link

commented Jul 14, 2017

I tried the same thing and it also failed.

However, I am wondering whether linking to BLAS only may be enough.

On my computer, the default BLAS from R gives:

> d <- 2e3
> system.time({ x <- matrix(rnorm(d^2),d,d); tcrossprod(x) })
   user  system elapsed 
  3.648   0.031   3.682 
> 
> d <- 1e3
> system.time({ x <- matrix(rnorm(d^2),d,d); svd(x) })
   user  system elapsed 
  3.400   0.020   3.422 

And veclib's BLAS gives:

> d <- 2e3
> system.time({ x <- matrix(rnorm(d^2),d,d); tcrossprod(x) })
   user  system elapsed 
  0.871   0.028   0.517 
> 
> d <- 1e3
> system.time({ x <- matrix(rnorm(d^2),d,d); svd(x) })
   user  system elapsed 
  1.049   0.091   0.569 

Assuming that the crossprod is from BLAS and the SVD from LAPACK, I wonder how to interpret the results above...

@tvatter

This comment has been minimized.

Copy link

commented Jul 14, 2017

Actually, it seems that the brewed install points toward veclib's lapack:

> sessionInfo()
R version 3.4.1 (2017-06-30)
Platform: x86_64-apple-darwin16.6.0 (64-bit)
Running under: macOS Sierra 10.12.5

Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libLAPACK.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
[1] compiler_3.4.1 tools_3.4.1   
> d <- 5e3
> system.time({ x <- matrix(rnorm(d^2),d,d); tcrossprod(x) })
   user  system elapsed 
 10.088   0.227   3.766 
> system.time({ x <- matrix(rnorm(d^2),d,d); solve(x) })
   user  system elapsed 
 24.642   0.425   6.205 

However, when using the standard R with linking to veclib's BLAS only, I obtain comparable performances:

> sessionInfo()
R version 3.4.0 (2017-04-21)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Sierra 10.12.5

Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] tvmisc_0.1.0

loaded via a namespace (and not attached):
[1] compiler_3.4.0 tools_3.4.0    rstudioapi_0.6 fortunes_1.5-4
> d <- 5e3
> system.time({ x <- matrix(rnorm(d^2),d,d); tcrossprod(x) })
   user  system elapsed 
  9.464   0.243   3.568 
> system.time({ x <- matrix(rnorm(d^2),d,d); solve(x) })
   user  system elapsed 
 22.934   0.509   6.545 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.