高性能Numpy/Scipy加速:使用Intel MKL和Intel Compilers或OpenBLAS(待续)
Numpy/Scipy加速:使用Intel MKL和Intel Compilers
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接著加入共享庫的路徑,其中庫的名稱一定要有對應的版本號,這里是.2.174
export MKLHOME=/opt/intel/mkl/lib/intel64 export LIB1=/opt/intel/compilers_and_libraries_2017.2.174/linux/mkl/lib/intel64_lin export LIB2=/opt/intel/compilers_and_libraries_2017.2.174/linux/compiler/lib/intel64_lin export LD_LIBRARY_PATH=$MKLHOME:$LIB1:$LIB2:$LD_LIBRARY_PATH注意:如果使用中還有一些.so庫找不到,則可以定位這些庫然后加入到LD_LIBRARY_PATH中。如果需要有全局的作用,則可以編輯/etc/ld.so.conf文件,增加這些路徑,并用ldconfig刷新。
構建numpy和scipy
下載 NumPy & SciPy libraries
git clone https://github.com/numpy/numpy.git numpy git clone https://github.com/scipy/scipy.git scipyBuild instructions
Building From Source on Linux
主要依據Numpy/Scipy with Intel? MKL and Intel? Compilers官網提示。總結起來就是在numpy的安裝路徑下增加site.cfg文件,內容如下:
cd numpy sudo gedit site.cfg
添加如下代碼
[mkl] library_dirs = /opt/intel/compilers_and_libraries_2017.2.174/linux/mkl/lib/intel64 include_dirs = /opt/intel/compilers_and_libraries_2017.2.174/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 installNumpy/Scipy加速:使用OpenBLAS
1. Install OpenBLAS
~$ git clone git://github.com/xianyi/OpenBLAS ~$ cd OpenBLAS && make FC=gfortran ~$ sudo make PREFIX=/opt/OpenBLAS install
2. 配置環境變量
sudo gedit ~/.bashrc
添加
export LD_LIBRARY_PATH=/opt/OpenBLAS/lib:$LD_LIBRARY_PATHThe LD_LIBRARY_PATH environment variable will be updated when you start a new terminal session
source ~/.bashrcto force an update within the same session
sudo gedit /etc/profile
添加
export LD_LIBRARY_PATH=/opt/OpenBLAS/lib:$LD_LIBRARY_PATH生效
source /etc/profileanother option that will work for multiple users is to create a .conf file
~$ sudo -s "echo '/opt/OpenBLAS/lib' > /etc/ld.so.conf.d/openblas.conf"生成鏈接
sudo ldconfig -v3. 安裝numpy
~$ git clone https://github.com/numpy/numpy ~$ cd numpyCopy site.cfg.example to site.cfg and edit the copy
~$ cp site.cfg.example site.cfg ~$ nano site.cfgCheck configuration, build, install (optionally in a virutalenv)
~$ python setup.py configThen just build and install:
~$ python setup.py build && python setup.py install參考文獻
Numpy/Scipy with Intel? MKL and Intel? Compilers
高性能Numpy/Scipy:使用Intel MKL和Intel Compilers
如何在 Linux* 中安裝英特爾? 數據分析加速庫(英特爾? DAAL)的 Python* 版本
caffe 上OpenBLAS的安裝使用
安裝OpenBlas(ubuntu 14.04)
OpenBLAS,Numpy,Scipy For Linux
安裝線性計算庫、numPy和sciPy的編譯方法(推薦)
Python accelerated (using Intel? MKL)
Intel Distribution for Python 正式版windows
官網Intel? Distribution for Python
Numpy使用MKL庫提升計算性能
總結
以上是生活随笔為你收集整理的高性能Numpy/Scipy加速:使用Intel MKL和Intel Compilers或OpenBLAS(待续)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: wap2.0浏览器兼容性小结
- 下一篇: 谷歌拼音输入法(google pinyi