Matlab slows down after few iterations

4 Ansichten (letzte 30 Tage)
Abhin Suresh
Abhin Suresh am 24 Mär. 2019
Bearbeitet: Abhin Suresh am 24 Mär. 2019
I am running a matlab code for time evolving a system by von neumann equation, Euler method or Rk2, or Rk4.
  1. Euler method is faster than the other two considering the matrix operations involved(but will have to use smaller steps and more runs).
  2. 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).
  3. 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.
  4. 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
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.
Abhin Suresh
Abhin Suresh am 24 Mär. 2019
Bearbeitet: Abhin Suresh am 24 Mär. 2019
Oh, sorry. I am not displaying Spinz at all(i missed to put semicolon in the comment).
I am only displaying Nt*dt each iteration.
Thank you for the replying.
Also matlab by itself uses parallel processing in matrix operations, but when I defined them to be sparse matix, it seems matlab is not using parallel computing.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Produkte


Version

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by