1 基本环境R>Ubuntu 11.04 32-bitR>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
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
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