1.获取Intel Parallel Studio XE
Intel免费软件工具提供免费的软件包,其中包括完整的Intel编译器和计算库及其激活码,软件和激活码一一对应。注意需要使用教育邮箱注册,否则不予通过。
2. 安装过程
解压后在终端进入./install_GUI.sh
,按照提示进行就好,其中激活的步骤需要联网,且最多只能激活5次。最后整个库会安装在\opt\intel
路径下,重要的是配置环境变量。
- 首先加入Intel编译器icc的路径
export INTELCOMP=/opt/intel/bin
export PATH=$INTELCOMP:$PATH
- 接着加入共享库的路径,其中库的名称一定要有对应的版本号,这里是
.1.132
export MKLHOME=/opt/intel/mkl/lib/intel64
export LIB1=/opt/intel/compilers_and_libraries_2017.1.132/linux/mkl/lib/intel64_lin
export LIB2=/opt/intel/compilers_and_libraries_2017.1.132/linux/compiler/lib/intel64_lin
export LD_LIBRARY_PATH=$MKLHOME:$LIB1:$LIB2:$LD_LIBRARY_PATH
注意:如果使用中还有一些.so
库找不到,则可以定位这些库然后加入到LD_LIBRARY_PATH
中。如果需要有全局的作用,则可以编辑/etc/ld.so.conf
文件,增加这些路径,并用ldconfig
刷新。
3. 构建numpy和scipy
主要依据Numpy/Scipy with Intel® MKL and Intel® Compilers官网提示。总结起来就是在numpy的安装路径下增加site.cfg文件,内容如下:
[mkl]
library_dirs = /opt/intel/compilers_and_libraries_2017.1.132/linux/mkl/lib/intel64
include_dirs = /opt/intel/compilers_and_libraries_2017.1.132/linux/mkl/include
mkl_libs = mkl_rt
lapack_libs =
接着更改numpy/distutils/intelccompiler.py
文件中的self.cc_exe
语句,如果是64位,则在IntelEM64TCCompiler
类中将之改为self.cc_exe = 'icc -O3 -g -fPIC -fp-model strict -fomit-frame-pointer -openmp -xhost'
。然后就可以编译安装numpy了
$ python setup.py config --compiler=intelem build_clib --compiler=intelem build_ext --compiler=intelem install
构建安装scipy可以直接进行
$ python setup.py config --compiler=intelem --fcompiler=intelem build_clib --compiler=intelem --fcompiler=intelem build_ext --compiler=intelem --fcompiler=intelem install
4. 关于一些错误
- 构建中编译器和共享库路径找不到
c编译器一定需要icc,所以一定要将icc定位后加入到系统变量PATH
中 ,共享库路径可以加入LD_LIBRARY_PATH
或者编辑/etc/ld.so.conf
文件。同时,还需要fortran编译器,而它集成在gcc中,因此在编译之前一定要确保已经安装了gcc。
还有错误就是找不到系统的编译器,例如ld: cannot find -lstdc++
的错误,这是说系统找不到libstdc++.so
文件,但是在/usr/lib64
中会有libstdc++.so.6
文件,因此要创建软链接才能正常编译
$ ln -s /usr/lib64/libstdc++.so.6 /usr/lib64/libstdc++.so
- 使用numpy/scipy时找不到共享库
共享库路径同样要加入LD_LIBRARY_PATH
或者编辑/etc/ld.so.conf
文件
- 安装其他基于numpy的库时,出现未定义的符号undefined symbols的错误
在当前环境中缺少共享库路径,可以暂时添加错误中缺少的路径到LD_LIBRARY_PATH
中,即
export LD_LIBRARY_PATH=[the needed path]:$LD_LIBRARY_PATH
这样重新安装就可以了。