Borrar filtros
Borrar filtros

gpu computing and parallel computing (vectorize code)

1 visualización (últimos 30 días)
inho seong
inho seong el 15 de Abr. de 2021
Editada: Matt J el 15 de Abr. de 2021
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

Respuestas (1)

Matt J
Matt J el 15 de Abr. de 2021
Editada: Matt J el 15 de Abr. de 2021
b=max(0, floor( (1e4-S)/dt) )*dt + S;

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by