Borrar filtros
Borrar filtros

Please speed up my code

2 visualizaciones (últimos 30 días)
inho seong
inho seong el 10 de Mzo. de 2021
Comentada: Jan el 13 de Mzo. de 2021
How can I speed up my code?
I know I can use parallel computing on while loop.
And I used gpuArray (quadro M6000) but runtime increased
I want to use CPU parallel computing or GPU
please modify my code which can run in the parallel computing tool
clear all
tic;
N = 1E5;
phi = linspace(0, 2 * pi, N);
V0 = 500;
Te = 3;
f =13.56E6;
w = f * 2 * pi;
tau = phi./w;
t = tau;
e=1.6E-19;
mi=40*1.6726E-27;
ni = 1E9*1E6;
eps0=8.8541878176E-12;
s0 = sqrt(eps0 * V0/ni/e/2);
% x = linspace(2 * s0,2 * s0, N);
x = 2 * s0 * ones(1,N);
sum_x = sum(x);
dt = 1E-10;
uB=sqrt(e*Te/mi);
% v = linspace(uB,uB,N);
v = -uB * ones(1, N);
le_i = [];
while sum_x > 0
s = s0 * (1 - sin(w * t));
ids1 = x >= s;
x_noE = x(ids1);
vx_no = v(ids1);
t_no = t(ids1);
ids2 = x < s;
x_E = x(ids2);
s_E = s(ids2);
t_E = t(ids2);
E = e * ni/eps0 * (x_E-s_E);
vx_E = v(ids2) + e*E/mi * dt;
v = [vx_no, vx_E];
x = [x_noE, x_E];
t = [t_no, t_E];
e_i = 0.5 * mi * v.^2;
x = x + v * dt;
t = t + dt;
idx = x<=0;
le_i = [le_i e_i(idx)./e];
idx = x>0;
x = x(idx);
t = t(idx);
if mod(1000*(N-length(x))/N,1) == 0
fprintf('Getting data... (%.1f %%)\n',100 * ((N-length(x)) / N));
end
sum_x = sum(x);
end
  8 comentarios
inho seong
inho seong el 12 de Mzo. de 2021
I've been appreciating everyone, always.
If you have any idea to speed up like parallelization, please feel free to contact me!
Jan
Jan el 13 de Mzo. de 2021
Create your own copy of ttest, e.g. as "myttest.m" and omit all stuff, which is not needed by your call of this function.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Programming en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by