Python中的意外多线程(scikit-learn) [英] Unintended multithreading in Python (scikit-learn)

查看:70
本文介绍了Python中的意外多线程(scikit-learn)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将sklearn模块的混合物子模块用于高斯混合模型...当我在多核系统上运行代码时,即使我在代码中没有要求,它也会使用多个核.这是默认行为吗?更重要的是,如何禁用它?

I'm using mixture submodule of sklearn module for Gaussian Mixture Model... When I run my code on a multicore system, it uses multiple cores even though I do not ask for it in the code. Is this a default behavior? And more important, how can I disable it?

谢谢

推荐答案

如果您使用的是MKL,请尝试

If you are using MKL then try

export MKL_NUM_THREADS=1

对于使用OpenBLAS的Numpy:

For Numpy with OpenBLAS:

export OPENBLAS_NUM_THREADS=1

对于某些版本的Numpy,建议使用此变体:

For some versions of Numpy this variation has been suggested:

export NUMEXPR_NUM_THREADS=1

必须在运行脚本之前设置环境变量(在脚本内部进行设置不会产生预期的效果).有关在运行时设置线程的信息,请参见:设置最大线程数在numpy/openblas上运行时

The environment variable has to be set before the script is run (setting inside the script itself does not have the desired effect). For setting threads at runtime see: Set max number of threads at runtime on numpy/openblas

请参阅以下内容,确定如何设置numpy:如何检查numpy/scipy中的blas/lapack链接?

See the following for identifying how your numpy is setup: How to check blas/lapack linkage in numpy/scipy?

这篇关于Python中的意外多线程(scikit-learn)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆