阻止Python使用多个cpu [英] Stop Python from using more than one cpu

查看:190
本文介绍了阻止Python使用多个cpu的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用python运行脚本时出现问题.我没有在python中完成任何并行化操作,也没有调用任何mpi来运行脚本.我只执行"python myscript.py",它只能使用1个CPU.

I have a problem when I run a script with python. I haven't done any parallelization in python and don't call any mpi for running the script. I just execute "python myscript.py" and it should only use 1 cpu.

但是,当我查看命令"top"的结果时,我发现python使用了几乎390%的cpus.我有一个四核,所以有8个线程.我认为这不会帮助我的脚本更快地运行.因此,我想了解为什么python使用多个cpu,并阻止它这样做.

However, when I look at the results of the command "top", I see that python is using almost 390% of my cpus. I have a quad core, so 8 threads. I don't think that this is helping my script to run faster. So, I would like to understand why python is using more than one cpu, and stop it from doing so.

有趣的是,当我运行第二个脚本时,该脚本也占用了390%.如果我运行第三个脚本,则每个脚本的CPU使用率将降至250%.不久前,我在matlab上遇到了类似的问题,而解决该问题的方法是使用-singlecompthread启动matlab,但是我不知道该如何处理python.

Interesting thing is when I run a second script, that one also takes up 390%. If I run a 3rd script, the cpu usage for each of them drops to 250%. I had a similar problem with matlab a while ago, and the way I solved it was to launch matlab with -singlecompthread, but I don't know what to do with python.

如果有帮助,我正在脚本中求解泊松方程(根本没有并行化).

If it helps, I'm solving the Poisson equation (which is not parallelized at all) in my script.

更新: 我的朋友在自己的计算机上运行了该代码,只占用了100%的cpu.我不使用任何BLAS,MKL或其他任何东西.我仍然不知道cpu使用率达到400%的原因是什么. 库SLATEC中有一个fortran算法,可以解决Ax = b系统.我认为那部分使用了大量的cpu.

UPDATE: My friend ran the code on his own computer and it only takes 100% cpu. I don't use any BLAS, MKL or any other thing. I still don't know what the cause for 400% cpu usage is. There's a piece of fortran algorithm from the library SLATEC, which solves the Ax=b system. That part I think is using a lot of cpu.

推荐答案

您的代码可能正在调用某些使用C/C ++/etc的函数.下.在这种情况下,可能会使用多个线程.

Your code might be calling some functions that uses C/C++/etc. underneath. In that case, it is possible for multiple thread usage.

您是否正在调用仅是与某些更高效实现的函数进行python绑定的任何库?

Are you calling any libraries that are only python bindings to some more efficiently implemented functions?

这篇关于阻止Python使用多个cpu的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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