Info

This question is closed. Reopen it to edit or answer.

Suitability of parallel computing?

2 views (last 30 days)
Eliza
Eliza on 27 Mar 2015
Closed: MATLAB Answer Bot on 20 Aug 2021
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?

Answers (1)

Edric Ellis
Edric Ellis on 30 Mar 2015
Edited: Edric Ellis on 30 Mar 2015
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.

Community Treasure Hunt

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

Start Hunting!