LoginSignup
2
1

More than 5 years have passed since last update.

condaでいれたnumpyのスレッド数管理

Last updated at Posted at 2018-11-06

環境

Miniconda(Anaconda)を使用して環境構築を行っていることが前提

miniconda.sh
$ conda create -n [new_env] python=3.7
$ conda install numpy
$ pip install chainer  # 別にやらなくても良い. conda経由でやろうとするとpythonのバージョンが3.6に下がる

$ conda activate [new_env]
$ python -V
Python3.7.1

問題

chainer.iterators.MultithreadIteratorchainer.iterators.MultiprocessIterator使用時にCPU使用率が跳ね上がる

解決策

conda install numpyでビルドされるnumpyはmklを用いて並列処理によって高速化されるようになっている.
故に,環境変数MKL_NUM_THREADSを適切な値にすることで,同時スレッド数を制限する必要がある.

注意すべきはMultithreadIteratorMultiprocessIteratorによって立ち上がる各スレッドがMKL_NUM_THREADS分のスレッドを立て得ることである.

そのため,n_threadsもしくはn_processesMKL_NUM_THREADSの掛け算の値が,使用したいスレッド数と同じになるようにお互いを設定する必要がある

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1