Speed ​​up RcppArmadillo: how to connect to OpenBlas in R package

I am working on an R package that uses RcppArmadillo. I am trying to use the faster matrix multiplication found in OpenBLAS. The documentation library C ++ armadillo says that if we have OpenBLAS in our car, the Armadillo will be used instead OpenBLAS BLAS. However, when I compile my R package, I get something like this:

g++ -m64 -std=c++11 -shared -L/usr/lib64/R/lib -Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -o PackageTest.so class1.o class2.o class3.o class4.o class5.o class6.o class7.o RcppExports.o class8.o class9.o class10.o -L/usr/lib64/R/lib -lRlapack -L/usr/lib64/R/lib -lRblas -lgfortran -lm -lquadmath -L/usr/lib64/R/lib -lR

      

Therefore, it compiles with parameters -lRlapack

and -lRblas

. How to change the files correctly Makevars

and Makevars.win

so that RcppArmadillo compiles the package with the option -lopenblas

? My attempt to solve this problem was to modify the file Makevars

like this:

PKG_LIBS = $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)
PKG_CXXFLAGS =-fopenmp -std=c++11 -lopenblas
PKG_CXX1XFLAGS = $(PKG_CXXFLAGS)

      

The package compiled with -lopenblas

, but the best way to do this?

+3


source to share


1 answer


This is an issue with the RedHat installation, which relied on the internal LAPACK sources for R when installing R --- plus the fact that RcppArmadillo uses everything that uses R.

It works differently on my Debian / Ubuntu based machine. Those. for

R> library(Rcpp)
R> cppFunction("arma::mat foo(arma::mat x) { return x + x;} ", depends="RcppArmadillo", verbose=TRUE)

      



I receive (inter alia)

g++ -Wl,-S -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions \
    -Wl,-z,relro -o sourceCpp_4.so file677111d81351.o \
    -fopenmp -llapack -lblas -lgfortran -lm -lquadmath \
    -L/usr/lib/R/lib -lR

      

and we see -llapack -lblas -lgfortran

as expected.

+2


source







All Articles