Python:如何停止多线程的numpy? [英] Python: How do you stop numpy from multithreading?

查看:414
本文介绍了Python:如何停止多线程的numpy?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这似乎是一个荒谬的问题,但是我必须在与部门中其他人共享的计算服务器上定期运行作业,当我开始10个作业时,我真的希望只占用10个作业核心而不是更多;我不在乎每次运行一个内核所需的时间是否更长:我只是不想让它侵犯其他人的领土,这将需要我放弃工作等等.我只想拥有10个坚实的核心,就这些.

I know this might seem like a ridiculous question, but I have to run jobs on a regular basis on compute servers that I share with others in the department and when I start 10 jobs, I really would like it to just take 10 cores and not more; I don't care if it takes a bit longer with a single core per run: I just don't want it to encroach on the others' territory, which would require me to renice the jobs and so on. I just want to have 10 solid cores and that's all.

更具体地说,我在基于Python 2.7.3和numpy 1.6.1的Redhat上使用Enthought 7.3-1,但问题更笼统.数小时以来,我一直在搜寻该问题的某种答案,但无济于事,因此,如果有人知道numpy中的开关可能会关闭多线程,请告诉我.

More specifically, I am using Enthought 7.3-1 on Redhat, which is based on Python 2.7.3 and numpy 1.6.1, but the question is more general. I've been googling for some kind of an answer to this question for hours to no avail, so if someone knows of a switch in numpy that could turn off the multi-threading, please let me know.

推荐答案

MKL_NUM_THREADS环境变量设置为1.您可能已经猜到了,该环境变量控制着Math Kernel Library的行为,该库包含在其中. Enthought的numpy构建.

Set the MKL_NUM_THREADS environment variable to 1. As you might have guessed, this environment variable controls the behavior of the Math Kernel Library which is included as part of Enthought's numpy build.

我只是使用export MKL_NUM_THREADS=1在启动文件.bash_profile中执行此操作.您还应该能够从脚本内部执行此操作,以使其具有特定于进程的作用.

I just do this in my startup file, .bash_profile, with export MKL_NUM_THREADS=1. You should also be able to do it from inside your script to have it be process specific.

这篇关于Python:如何停止多线程的numpy?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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