R虽然自带了blas库,但为了保持最大的兼容性,性能不是最优的,Linux下安装R的一个好处是你可以自行编译Openblas库,这样能极大的提供矩阵运算速度。
先来看看结果,没开启OpenBLAS库之前测试运行速度是23秒,安装之后速度提高到4.5秒:
这是安装默认ShardeBLAS库运行R benchmark脚本的结果:
这是安装OpenBLAS库之后运行R benchmark脚本的结果:
下面说说安装方法,经过摸索测试,再编译之前需要安装这些依赖:
sudo yum install -y openblas openblas-threads openblas-openmp cairo-devel tcl-devel tk-devel
然后configure:
./configure --enable-R-shlib --enable-byte-compiled-packages \
--enable-BLAS-shlib --enable-memory-profiling \
--with-blas="-lopenblas"
如果一切正常你会看到如下结果:
R is now configured for x86_64-pc-linux-gnu
Source directory: .
Installation directory: /usr/local
C compiler: gcc -g -O2
Fortran fixed-form compiler: gfortran -fno-optimize-sibling-calls -g -O2
Default C++ compiler: g++ -std=gnu++11 -g -O2
C++98 compiler: g++ -std=gnu++98 -g -O2
C++11 compiler: g++ -std=gnu++11 -g -O2
C++14 compiler: g++ -std=gnu++14 -g -O2
C++17 compiler: g++ -std=gnu++17 -g -O2
Fortran free-form compiler: gfortran -fno-optimize-sibling-calls -g -O2
Obj-C compiler:
Interfaces supported: X11
External libraries: readline, BLAS(OpenBLAS), curl
Additional capabilities: PNG, JPEG, TIFF, NLS, cairo, ICU
Options enabled: shared R library, shared BLAS, R profiling, memory profiling
Capabilities skipped:
Options not enabled:
Recommended packages: yes
可以看到重要的库:PNG, JPEG, TIFF, NLS, cairo, ICU,还有外部库OpenBLAS都已经配置好了,之后就可以make && make install了。
安装好之后测试方法同上。
完。