CentOS8安装R使用Openblas库提高速度

R虽然自带了blas库,但为了保持最大的兼容性,性能不是最优的,Linux下安装R的一个好处是你可以自行编译Openblas库,这样能极大的提供矩阵运算速度。

先来看看结果,没开启OpenBLAS库之前测试运行速度是23秒,安装之后速度提高到4.5秒:
上面的结果是安装Shared BLAS库,下面是安装了OpenBlas库的结果,运算速度提高了5-6倍

这是安装默认ShardeBLAS库运行R benchmark脚本的结果:
SharedBLAS Performace

这是安装OpenBLAS库之后运行R benchmark脚本的结果:
OpenBlas Performance

下面说说安装方法,经过摸索测试,再编译之前需要安装这些依赖:

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了。

安装好之后测试方法同上。

完。

发布了6 篇原创文章 · 获赞 0 · 访问量 602

猜你喜欢

转载自blog.csdn.net/weixin_42205230/article/details/104767482