PyFFTW多线程不起作用 [英] PyFFTW multithreading not working

查看:320
本文介绍了PyFFTW多线程不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在基于FFTW3库的PyFFTW包装器运行代码.在PyFFTW的计划函数调用中,有一个参数"thread"用于指定要使用的线程数.我使用基本的判断器Activity Monitor来判断多线程是否有效.事实证明,即使我指定thread = 4,以下代码也可以在一个CPU上运行.我的笔记本电脑是具有8核的Mac.这是我的代码.

I am running my codes based on PyFFTW wrapper for FFTW3 library. In the plan function call of PyFFTW, there is a parameter "thread" to specify the number of threads to use. I use a fundamental judge, Activity Monitor, to tell whether multithreading works or not. It turns out that the following code runs on one CPU even when I specify thread=4. My laptop is a Mac with 8 cores. Here is my code.

import pyfftw
n_cpu = 4
flags = ('FFTW_MEASURE','FFTW_DESTROY_INPUT')
x_buffer = pyfftw.n_byte_align_empty((8192,8192,), 16, 'complex128')
f_buffer = pyfftw.n_byte_align_empty((8192,8192,), 16, 'complex128')
fftObj  = pyfftw.FFTW(x_buffer, f_buffer,  axes=(-2,-1), direction='FFTW_FORWARD',  flags=flags, thread=n_cpu)
fftObj()

当我运行fftObj()时,计算机似乎在一个CPU上运行(CPU利用率为99%,而预期值为400%).我想要的是将FFT任务分配到笔记本电脑的CPU之间.

When I run fftObj(), the computer seems to run on one CPU (CPU usage 99% whereas the expected should be 400%). What I want is to have the FFT task distributed among CPUs my laptop has.

除了尝试使用pyfftw之外,我还尝试使用OpenMP在C语言中编写其他代码,并且从活动监视器中看到CPU使用率超过100%.这意味着C代码可以在多个CPU上运行,并且我的机器确实具有多核功能.

Other than trying pyfftw, I have tried writing some other codes in C with OpenMP, and I see from the Activity Monitor that the CPU usage is above 100%. It means that the C code runs on multiple CPUs and my machine does have the multicore feature.

打开fffftw的多线程时我有什么想念的吗?还是我误解了参数的含义?

Is there anything that I missed to turn on the multithreading of pyfftw? Or do I misunderstand the meaning of the parameter?

存在与相关的问题.

推荐答案

参数是threads而不是thread.多余的和无效的参数可能应该被选择.想在 github 上留下问题吗?

The argument is threads not thread. Superfluous and invalid arguments should probably be picked up. Fancy going and leaving an issue on github?

这篇关于PyFFTW多线程不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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