LoginSignup
12
7

More than 5 years have passed since last update.

pythonで1スレッドで流してるつもりなのにcpu使用率が100%になっている時の対処法

Posted at

はまった状況

複数コアで並列計算をやろうとしたら全然速くならない。試しに並列数を1にして流すとcpuが100%使われていた。

解決策

どうやらnumpyが並列計算で全スレッド使っているらしい。
numpyやscipyをimportする前に使えるスレッド数を制限すれば解決する。

test.py
import os
os.environ["OMP_NUM_THREADS"] = "1"

私の場合、importしたモジュールにnumpyを使っていたが、メインモジュールに書くだけで良いらしい。
参考:https://github.com/numpy/numpy/issues/11826

12
7
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
12
7