你如何从多线程中阻止 numpy? [英] How do you stop numpy from multithreading?

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

问题描述

我必须在与部门其他人共享的计算服务器上定期运行作业,当我开始 10 个作业时,我真的希望它只需要 10 个内核而不是更多;我不在乎每次运行单个核心是否需要更长的时间:我只是不希望它侵占其他人的领土,这需要我重新安排工作等等.我只想拥有 10 个实心内核,仅此而已.

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.

我在 Redhat 上使用 Enthought 7.3-1,它基于 Python 2.7.3 和 numpy 1.6.1,但问题更笼统.

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.

推荐答案

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.

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

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.

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

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