Ubuntu下使用icc/ifort/MKL编译R及性能实测

1 基本环境Ubuntu 11.04 32-bitR 32-bit 2.13.0Intel 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 tar -xf R-2.13.0.tar.gzcd R-2.13.0./configuremakesudo make install

这次具体指定一下参数就好了.

卸载原有的R:

sudo apt-get remove r-basesudo apt-get autoremove

设以下为foo.sh

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

export CC=iccexport CFLAGS=”-g -O2 -wd188 -ip -std=c99″export F77=ifortexport FFLAGS=”-g -O3″export CXX=icpcexport CXXFLAGS=”-g -O3″export FC=ifortexport FCFLAGS=”-g -O3″export ICC_LIBS=/opt/intel/composerxe-2011.3.174/compiler/lib/ia32export IFC_LIBS=/opt/intel/composerxe-2011.3.174/compiler/lib/ia32export SHLIB_CXXLD=icpcexport SHLIB_CXXLDFLAGS=-shared

MKL_LIB_PATH=/opt/intel/composerxe-2011.3.174/mkl/lib/ia32export 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 tar -xf R-2.13.0.tar.gzcd 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=c99Fortran 77 compiler: ifort -g -O3

C++ compiler: icpc -g -O3Fortran 90/95 compiler: ifort -g -O3Obj-C compiler:

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

Recommended packages: yes

然后

makemake checksudo 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

,不论你在什么时候结束,重要的是结束之后就不要悔恨

Ubuntu下使用icc/ifort/MKL编译R及性能实测

相关文章:

你感兴趣的文章:

标签云: