How to speed up the simulation using gpu
이전 댓글 표시
Hi, I have to speed up my code. This is particle simulation in a sheath having strongly E-field. Sheath is moving varying time.
So sometimes, particles are not affected by E-field when escaping the sheath.
Abovementioned, I want to speed up this code so I vectorized this code using logical indexing.
And then, I use gpuArray function. As result, runtime except for gpuArray was slower than using gpuArray about ~10 times.
How can I use gpu in my code?
If this code will be modify a lot, please help me make nice code using gpu.
For example, if parallel computing doesn't support while loop, please help me avoid using while loop to obtain same result which use CPU.
p = 5E-3;
N = 5E3;
V0 = 500;
f = 13.56E6;
ni = 1E9*1E6;
phi = linspace(0, 2 * pi, N);
phi = gpuArray(phi);
Te = 3;
e=1.6E-19;
mi=40*1.6726E-27;
eps0=8.8541878176E-12;
k=1.38064852*1e-23;
w = f * 2 * pi;
tau = phi./w;
t = tau;
dt = 1E-10;
s0 = sqrt(eps0 * V0/ni/e/2);
uB=sqrt(e*Te/mi);
x = 2 * s0 * ones(1,N);
v = -uB * ones(1, N);
le_i = [];
while 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;
ids = x<=0;
le_i = [le_i e_i(ids)./e];
idx = x>0;
x = x(idx);
t = t(idx);
v = v(idx);
end
답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!