Logo Icon

For Faster R on a Mac, Use Veclib

Inspired by this post, I decided to try using OpenBLAS for R on my mac. However, it turns out there’s a simpler option, using the vecLib BLAS library, which is provided by Apple as part of the accelerate framework.

If you are using R 2.15, follow these instructions to change your BLAS from the default to vecLib:

cd /Library/Frameworks/R.framework/Resources/lib

# for vecLib use
ln -sf libRblas.vecLib.dylib libRblas.dylib

# for R reference BLAS use
ln -sf libRblas.0.dylib libRblas.dylib

However, as noted in r-sig-mac, these instructions do not work for R 3.0. You have to directly link to the accelerate framework’s version of vecLib:

cd /Library/Frameworks/R.framework/Resources/lib

# for vecLib use
ln -sf /System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Versions/Current/libBLAS.dylib /Library/Frameworks/R.framework/Resources/lib/libRblas.dylib

# for R reference BLAS use
ln -sf libRblas.0.dylib libRblas.dylib

Finally, test your new blas using this script:

Rscript -e 'source("http://r.research.att.com/benchmarks/R-benchmark-25.R")'

On my system (a retina macbook pro), the default BLAS takes 141 seconds and vecLib takes 43 seconds, which is a significant speedup. If you plan to use vecLib, note the following warning from the R development team “Although fast, it is not under our control and may possibly deliver inaccurate results.”

So far, I have not encountered any issues using vecLib, but it’s only been a few hours :-).

UPDATE: you can also install OpenBLAS on a mac:

brew install r

Homebrew uses openblas by default! On my modern M2 mac, the profiling script now takes 27 seconds.

stay in touch