Matlab的fftn在多线程中变慢了吗? [英] Matlab's fftn gets slower with multithreading?
问题描述
我可以使用12核计算机和一些严重依赖于fftn的matlab代码.我想加快我的代码.
I have access to a 12 core machine and some matlab code that relies heavily on fftn. I would like to speed up my code.
由于fft可以并行化,我认为更多的内核会有所帮助,但我看到相反的情况.
Since the fft can be parallelized I would think that more cores would help but I'm seeing the opposite.
这是一个例子:
X = peaks(1028);
ncores = feature('numcores');
ntrials = 20;
mtx_power_times = zeros(ncores,ntrials);
fft_times = zeros(ncores, ntrials);
for i=1:ncores
for j=1:ntrials
maxNumCompThreads(i);
tic;
X^2;
mtx_power_times(i,j) = toc;
tic
fftn(X);
fft_times(i,j) = toc;
end
end
subplot(1,2,1);
plot(mtx_power_times,'x-')
title('mtx power time vs number of cores');
subplot(1,2,2);
plot(fft_times,'x-');
title('fftn time vs num of cores');
哪个给我这个:
矩阵乘法的速度非常快,但是当我使用所有内核时,我的fft看起来慢了将近3倍.发生了什么事?
The speedup for matrix multiplication is great but it looks like my ffts go almost 3x slower when I use all my cores. What's going on?
供参考,我的版本是7.12.0.635(R2011a)
For reference my version is 7.12.0.635 (R2011a)
在采用1D变换的大型2D阵列上,我遇到了相同的问题:
On large 2D arrays taking 1D transforms I get the same problem:
问题似乎是fftw没有看到maxNumCompThreads强制执行的线程限制.无论我将maxNumCompThreads设置为什么,我都将使cpus全速运转.
The problem appears to be that fftw is not seeing the thread limiting that maxNumCompThreads enforces. I'm getting all the cpus going full speed no matter what I set maxNumCompThreads at.
那么...有什么办法可以指定要在Matlab中的fft使用多少个处理器?
So... is there a way I can specify how many processors I want to use for an fft in Matlab?
:如果没有对.mex文件进行一些细致的工作,我似乎无法做到这一点. http://www. mathworks.com/matlabcentral/answers/35088-how-to-to-control-of-threads-in-fft 有一个答案.如果有人可以轻松解决问题,那就太好了……
Looks like I can't do this without some careful work in .mex files. http://www.mathworks.com/matlabcentral/answers/35088-how-to-control-number-of-threads-in-fft has an answer. It would be nice if someone has an easy fix...
推荐答案
在没有对.mex文件进行一些仔细工作的情况下,我无法做到这一点. http://www.mathworks .com/matlabcentral/answers/35088-how-to-to-control-number-of-threads-in-fft 有一个答案.如果有人可以轻松解决问题,那就太好了……
Looks like I can't do this without some careful work in .mex files. http://www.mathworks.com/matlabcentral/answers/35088-how-to-control-number-of-threads-in-fft has an answer. It would be nice if someone has an easy fix...
这篇关于Matlab的fftn在多线程中变慢了吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!