matlab 中ftn,Matlab's fftn gets slower with multithreading?

阅读: 评论:0

matlab 中ftn,Matlab's fftn gets slower with multithreading?

matlab 中ftn,Matlab's fftn gets slower with multithreading?

问题

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.

Since the fft can be parallelized I would think that more cores would help but I'm seeing the opposite.

Here's an example:

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');

Which gives me this:

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?

For reference my version is 7.12.0.635 (R2011a)

Edit: On large 2D arrays taking 1D transforms I get the same problem:

Edit: 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.

< is there a way I can specify how many processors I want to use for an fft in Matlab?

Edit: Looks like I can't do this without some careful work in .mex files. has an answer. It would be nice if someone has an

回答1:

Looks like I can't do this without some careful work in .mex files. has an answer. It would be nice if someone has an

回答2:

To use different cores, you should use the Parallel Computing Toolbox. For instance, you could use a parfor loop, and you have to pass the functions as a list of handles:

function x = f(n, i)

...

end

m = ones(8);

parfor i=1:8

m(i,:) = f(m(i,:), i);

end

More info is available at:

High performance computing

Multithreaded computation

Multithreading

来源:

本文发布于:2024-02-01 06:13:36,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/170673921834472.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:Matlab   ftn   matlab   multithreading   slower
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23