MATLAB Answers

Why GPU computation does not scale linearly with the number of loops ?

3 views (last 30 days)
gdgc on 19 Dec 2017
Commented: Joss Knight on 20 Dec 2017
Good evening everyone,
I'm currently trying to speed up my code by converting it to GPU computation. But I'm facing a problem I didn't have with CPU : The time doesn't scale linearly with the number of loops.
Here is the code :
Nloops = 500;
dt=1e-1; % time step
n=3e3; % number of vortices
z1=complex(gpuArray.randn(1,n),gpuArray.randn(1,n)); % vortices position
C1=repmat(1e-2*gpuArray.randn(n,1),1,n); % circulation
for ii=1:Nloops
Z1 = repmat(z1,n,1);
z1 = z1 + (dt*0.5i/pi) * (sum((C1.*nD)./(Z1-Z1.'+D),1));
The result is quite surprising
Nloops = 100 : Elapsed time is 0.014950 seconds.
Nloops = 500 : Elapsed time is 17.072178 seconds.
While on CPU it scales well ( 3 and 15 seconds respectively ), do you have an idea why it scales so badly on GPU ?

Accepted Answer

Matt J
Matt J on 19 Dec 2017
tic and toc are not accurate measures of GPU execution time. Use gputimeit() instead.
Joss Knight
Joss Knight on 20 Dec 2017
Try removing the repmat from your loop, with automatic scalar expansion you don't need it: Z1-Z1.' == z1-z1.'

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by