I am trying to solve SBS equations but they are taking too much memory and hence the code is slow
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
globalize_vars;
p=zeros(Nz,Nt);
%% initial conditions
if Is_stationary
EL=El_s.*ones(Nz,Nt);
ES=Es_s.*ones(Nz,Nt);
else
EL =El_s.*ones(Nz,Nt);
ES = Es_s.*ones(Nz,Nt);
EL(1,:)=El_s(1)*exp(1i*phi);
ES(Nz,:)=zeros;
roh=sqrt(n*Q/c/GAMMAb)*(randn(Nz,Nt)+1i*randn(Nz,Nt));
end
ES0_T=zeros(1,iterationsNum); %Es(0,t) Stokes field in z=0
EL_L_T=ES0_T; %El(L,t) Stokes field in z=L
%% Numerical Process
ELnew=EL;
ESnew=ES;
rohnew=roh;
pnew=p;
for index=1:iterationsNum
croh=conj(roh);
ELz=(EL(2:end,index)-EL(1:end-1,index))/dz;
ESz=(ES(2:end,index)-ES(1:end-1,index))/dz;
ELnew(2:end,index+1)=EL(2:end,index)+dt*c/n*(1i*sigma*roh(2:end,index).*ES(2:end,index)-ELz); %final equation for EL
ESnew(1:end-1,index+1)=ES(1:end-1,index)+dt*c/n*(1i*sigma*croh(1:end-1,index).*EL(1:end-1,index)+ESz); %final equation for ES
rohnew(:,index)=roh(:,index)+(dt*p(:,index)); %substitution for second derivative p=droh/dt
pnew(:,index)=p(:,index)+dt*((-GAMMAb+2*1i*Omega)*p(:,index)+1i*Omega*GAMMAb*roh(:,index)+eps0*gammaE*q^2*EL(:,index).*conj(ES(:,index))-2*1i*Omega*f(index));
EL=ELnew;
ES=ESnew;
roh=rohnew;
pnew=p
In the above code each variable is defined for 10000*10000 matrix and hence the computation time is high.
I am looking to make the code efficient and hence less memory consuming.
1 comentario
Shivam
el 19 de Mzo. de 2024
Hi Yogesh,
Could you attach your whole code snippet for me to debug it?
Thanks
Respuestas (1)
Umang Pandey
el 21 de Mayo de 2024
Hi Yogesh,
Given the partial nature of the code you've provided, pinpointing specific bottlenecks is challenging. I can see that your code is vectorized, which is the recommended practice for faster performance.
For further optimization, you can consult the following MATLAB documentation on "Techniques to Improve Performance":
Additionally, profiling your code can offer valuable insights into which sections are running slower than others. This information can help you in making targeted modifications to boost performance. For more details on profiling, you can visit the following MATLAB documentation page highlighting the steps for the same:
Hope this helps!
Best,
Umang
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!