gpu computing and parallel computing (vectorize code)

Hi, again I am coming back as having simple example.
At first, I want to speed up using parallel tool box like CPU multicore and GPU computing(Quadro M6000)
But I can't improve my code to speed up using them
I think the reasion is while loop (iteration) .
Please give me genious idea
N Particles simultaneously are computed in the while loop
If you have nice idea about speeding up using GPU (Euler method computing through while loop),
overall, you can modify this code; remove while loop or use good function to solve Euler with gpu.
tic;
gd = gpuDevice();
S = gpuArray(linspace(0, 100, 1E3));
% S = linspace(0, 100, 1E3);
b = arrayfun(@(x) plus_(x),S);
toc;
function b = plus_(a)
dt = 1E-1;
j = 0;
while a < 1E4
j = j + 1;
a = a + j * dt;
end
b = a;
end

답변 (1개)

Matt J
Matt J 2021년 4월 15일
편집: Matt J 2021년 4월 15일
b=max(0, floor( (1e4-S)/dt) )*dt + S;

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2021년 4월 15일

편집:

2021년 4월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by