Suitability of parallel computing?

I want to make this code run as fast as possible:
f1=[50 20 3 -50 -27]*(1000000); %frequency
p1=[10 200 50 9 0]; %phase
a1=[1 0.2 0.7 0.5 0.1]; % amplitude
s=1000000;
tot=s/max(abs(f1))*2.5;
t=linspace(0 ,tot ,s);
x=zeros(length(f1),s);
x=f1'*t;
y=repmat(p1',1,s);
I=a1*sin((2*pi*x)+y);
Q=a1*cos((2*pi*x)+y);
Is this the sort of problem where using parallel computing could help?

回答(1 个)

You could use the gpuArray support from PCT to perform this calculation. On my machine, this runs about 15x faster. (I have a fairly old Tesla C2070 GPU, and a quad-core CPU). Here's what I timed:
d = gpuDevice();
tic
x=gpuArray(f1)' * gpuArray.linspace(0, tot, s);
y=gpuArray(p1');
I2=a1 * arrayfun(@(xx,yy) sin((2*pi*xx)+yy), x, y);
Q2=a1 * arrayfun(@(xx,yy) cos((2*pi*xx)+yy), x, y);
wait(d);
toc
Note that it's unlikely that using parfor or spmd will speed this computation up much since the CPU computation is already intrinsically multi-threaded by MATLAB.

此问题已关闭。

提问:

2015-3-27

关闭:

2021-8-20

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by