歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Ubuntu下使用icc/ifort/MKL編譯R及性能實測

Ubuntu下使用icc/ifort/MKL編譯R及性能實測

日期:2017/2/28 15:46:02   编辑:Linux教程

1 基本環境
Ubuntu 11.04 32-bit
R 32-bit 2.13.0
Intel Composer XE 2011.3.174(含icc/ifort/MKL)
MKL(Intel Math Kernel Library), 號稱"provides extremely well-tuned BLAS and LAPACK implementations that deliver significant performance leadership over alternative math libraries". 在特定的計算情境下會帶來一定的性能提升. 記得哪裡看到過Revolution R和MATLAB就有用到MKL. 這裡嘗試用Intel提供的C和Fortran編譯器結合其MKL庫編譯R, 以期盡量發揮現有硬件的性能. Intel的Composer XE中自帶了MKL, 而且icc/ifort基本是傻瓜化安裝, 這裡不再贅述.

2 編譯過程
假設icc/ifort/MKL安裝在默認的 /opt/intel/composerxe-2011.3.174/ 目錄下.

通常我們會這樣簡單編譯安裝:

wget http://ftp.ctex.org/mirrors/CRAN/src/base/R-2/R-2.13.0.tar.gz
tar -xf R-2.13.0.tar.gz
cd R-2.13.0
./configure
make
sudo make install

這次具體指定一下參數就好了.


卸載原有的R:

sudo apt-get remove r-base
sudo apt-get autoremove

設以下為foo.sh

source /opt/intel/composerxe-2011.3.174/bin/iccvars.sh ia32
source /opt/intel/composerxe-2011.3.174/bin/ifortvars.sh ia32
source /opt/intel/composerxe-2011.3.174/mkl/bin/mklvars.sh ia32

export CC=icc
export CFLAGS="-g -O2 -wd188 -ip -std=c99"
export F77=ifort
export FFLAGS="-g -O3"
export CXX=icpc
export CXXFLAGS="-g -O3"
export FC=ifort
export FCFLAGS="-g -O3"
export ICC_LIBS=/opt/intel/composerxe-2011.3.174/compiler/lib/ia32
export IFC_LIBS=/opt/intel/composerxe-2011.3.174/compiler/lib/ia32
export SHLIB_CXXLD=icpc
export SHLIB_CXXLDFLAGS=-shared

MKL_LIB_PATH=/opt/intel/composerxe-2011.3.174/mkl/lib/ia32
export LD_LIBRARY_PATH=$MKL_LIB_PATH

OMP_NUM_THREADS=2

export LDFLAGS="-L${MKL_LIB_PATH},-Bdirect,--hash-style=both,-Wl,-O1 -L$ICC_LIBS -L$IFC_LIBS -L/usr/local/lib"

export SHLIB_LDFLAGS="-lpthread"
export MAIN_LDFLAGS="-lpthread"

MKL="-L${MKL_LIB_PATH} -lmkl_blas95 -lmkl_lapack95 -Wl,--start-group -lmkl_intel -lmkl_intel_thread -lmkl_core -Wl,--end-group -openmp -lpthread"

source一下foo.sh:

source foo.sh

下載解壓和configure:

wget http://ftp.ctex.org/mirrors/CRAN/src/base/R-2/R-2.13.0.tar.gz
tar -xf R-2.13.0.tar.gz
cd R-2.13.0
./configure --enable-R-shlib --with-blas="$MKL" --with-lapack

最後的configure結果大概會是這樣的:

R is now configured for i686-pc-linux-gnu

Source directory: .
Installation directory: /usr/local

C compiler: icc -g -O2 -wd188 -ip -std=c99
Fortran 77 compiler: ifort -g -O3

C++ compiler: icpc -g -O3
Fortran 90/95 compiler: ifort -g -O3
Obj-C compiler:

Interfaces supported: X11
External libraries: readline, BLAS(generic), LAPACK(in blas)
Additional capabilities: PNG, JPEG, NLS, cairo
Options enabled: shared R library, R profiling, Java

Recommended packages: yes

然後

make
make check
sudo make install

Bingo.

三點說明:

make到中間出現找不到/usr/include/asm/errno.h的情況. 加一個符號鏈接, 解決:
sudo ln -s /usr/include/asm-generic /usr/include/asm
參考網站[1]給出的中CFLAGS等4處帶有參數 -mieee-fp , make時過不去. 在此去掉此參數以後, make通過, 後果未知.
make install時提示

icc -I. -I../../src/include -I../../src/include -I/usr/local/include -DHAVE_CONFIG_H -openmp -fpic -g -O2 -wd188 -ip -std=c99 -DR_HOME='"/usr/local/lib/R"' -o Rscript \
./Rscript.c
/bin/bash: icc: 未找到命令
make[2]: *** [install-Rscript] 錯誤 127

建立符號鏈接, 解決:
sudo ln -s /opt/intel/composerxe-2011.3.174/bin/ia32/icc /bin/icc

Copyright © Linux教程網 All Rights Reserved