Matlab slows down after few iterations
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I am running a matlab code for time evolving a system by von neumann equation, Euler method or Rk2, or Rk4.
- Euler method is faster than the other two considering the matrix operations involved(but will have to use smaller steps and more runs).
- If I make my matrix sparse the memory used is significantly less(since most of the elements are zero) and the code is faster in my PC(8 threads, i5 8th gen).
- It seems that when computing using sparse matrix, matlab doesn't use parallel computing(I checked resource monitor), if I use full-matrix all cores are equally being used.
- I kind of verified this by running it in a server with 64 cores and 1TB ram, Sparse calculations were running with similar speeds as my PC!, but operations with full matrix were lot better(but kind of still not as good as sparse calculations).
All those things I am evaluating in my iterations are pre allocated.
Spinz is a pre allocated vector, rhoT and H are matrix defined before, I can make these matrix sparse, to speed up.
for nt=1:Nt
Spinz(nt)=trace(rhoT*LSpinz)
rhoT = rhoT -(1i*dt*(H*rhoT - rhoT*H)/hbar);
end
My issue is if I run it for very long iterations(30000) the code is becoming slow, not like exponentially slow, but still.
Can anyone help me with ways to identify a method to make the program faster for such long iterations.
*sample H=diag(ones(1600,1),1);
*when sparse, H=sparse(H);
4 Kommentare
Walter Roberson
am 24 Mär. 2019
It would be more efficient to not display all of Spinz each time. I suggest something closer to
interval = 100;
for nt = 1 : Nt
if mod(nt, interval) == 0; fprintf('.'); end %no newline!!
Spinz(nt) = trace(rhot*LSpinz);
rhoT = rhoT - (1i*dt*(H*rhoT - rhot*H)/hbar);
end
fprintf('\n');
This would display one period every interval iterations, which should be much more efficient than dumping all of Spinz each time.
Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!