2014年5月24日土曜日

ubuntu14.04でnumpy&scipyをintel composer XE2013でbuild&install

この前インストールしたubuntu14.04にnumpyとscipyをintel composer XE2013でbuildしたのでメモ。

まずはソフトをダウンロード。intelコンパイラは例の如くnoncommercialをインストールする。
  • Intel parallel studio xe2013 noncommercial
  • numpy1.8.1
  • scipy0.14.0

numpyのインストール
numpyのインストールは少し設定とソースを書き換える必要がある。
参考はこちら。だけど、うまくいかない部分があり・・・、次にインストールした際のメモを。
https://software.intel.com/en-us/articles/numpyscipy-with-intel-mkl

まずnumpyのインストールの際にいくつかファイルを変更しなければならない。具体的な変更箇所は、
~/numpy-1.8.1/site.cfgの
[mkl]
library_dirs = /opt/intel/composer_xe_2013_sp1.2.144/mkl/lib/intel64
include_dirs = /opt/intel/mkl/include
mkl_libs = mkl_rt
lapack_libs =

そして'~/numpy-1.8.1/numpy/distutils/fcompiler/intel.py'の'IntelEM64TFCompiler'classを修正。-O3なんかも追加してみる。
この辺:
    def get_flags(self):
        #return ['-fPIC']
        return ['-O3 -g -xhost -openmp -fp-model strict -fPIC']
あとは少し詰まったのが、どうやらインストール時にintelコンパイラのバージョンをifort -vで調べているようで、日本語版だとうまく実行されない。そのために、実行環境を英語にしておく。
export LANG=C

これで普通にインストールしてゆく。
python3 setup.py config --compiler=intelem
python3 setup.py build_clib --compiler=intelem
python3 setup.py build_ext --compiler=intelem
sudo python3 setup.py install

scipyのインストール
scipyのインストールは、numpyのsite.cfgが自動で引き継がれるので楽。

python3 setup.py config --compiler=intelem --fcompiler=intelem
python3 setup.py build_clib --compiler=intelem --fcompiler=intelem
python3 setup.py build_ext  --compiler=intelem --fcompiler=intelem
sudo python3 setup.py install

ここで、最後のinstallの部分でなぜかintel compilerとmklの共有ライブラリにパスが通っていない。LD_LIBRARY_PATHには入っているんだけど・・・。そこで、インストールスクリプトの中身を変えるのは面倒なので、場当たり的に対処。
/etc/ld.so.confに次のパスを追加しておく。
# for scipy
/opt/intel/composer_xe_2013_sp1.2.144/compiler/lib/intel64/
/opt/intel/composer_xe_2013_sp1.2.144/mkl/lib/intel64/

あとは、次のコマンドで有効に。
sudo /sbin/ldconfig

どうやらこんな感じでうまくインストールできた。
意外と面倒だったけど、これで爆速numpy&scipyが使えるぞお。

余談:
ALOS2、打ち上げ成功おめでとうございます。