MLK【numpy/scipyの設定】

本家はこちらです。インストールします。

Installing Intel® Performance Libraries and Intel® Distribution for Python* Using APT Repository | Intel® Software

MKLのインストール

$ sudo apt install -y wget apt-transport-https
$ wget https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS-2019.PUB
$ sudo apt-key add GPG-PUB-KEY-INTEL-SW-PRODUCTS-2019.PUB

$ sudo wget https://apt.repos.intel.com/setup/intelproducts.list -O /etc/apt/sources.list.d/intelproducts.list

$ sudo apt update
$ sudo apt install intel-mkl-20xx.x-xxx

仮想環境の設定

仮想環境で設定しました。詳細は別記事参照。

numpyの再コンパイル

~/.numpy-site.cfgを作成し、以下記載します。

[mkl]
library_dirs = /opt/intel/mkl/lib/intel64/
include_dirs = /opt/intel/mkl/include
mkl_libs = mkl_rt
lapack_libs =

numpyでcythonが必要と怒られたので、cythonをインストールします。

(.venv) $pip install cython

mklを呼びたいので、下記コマンドでpipしておきます。

(.venv) $ pip install --no-binary :all: numpy
(.venv) $ pip install --no-binary :all: scipy

インストールした後に一応確認します。

>>> import numpy as np
>>> np.show_config()

mklの参照先が設定されていればok

mklに変えたことで計算速度が速くなるかどうかは未検証です。

参考にしました。

https://insilico-notebook.com/python-blas-performance/

Intel MKL を apt からインストールする - Qiita

Arbitrary arbitrage

[悲報] numpy, scipyをIntel MKLで転生させたけどそんなに早くならなかった | KYgraphy

numpy で MKL を使う - Qiita

NumPy/SciPy で Intel MKL を利用する (2019年11月版) - Qiita