suddenly MATLAB process is too slow
Show older comments
I am using windows 10 and Matlab 2018b. I have a code was run fast, but suddenly it become so slow. The pseudo code of my code is as follows:
for i=1 : 200
for j=1 : 200
for k=1 : 200
NewMatrix = Archive(i,j)*Archive(k,j) + Archive(j,k)
end
end
end
where the Archive is a matrix of [200,6]
I don't know where is the problem. I am using CPU. could you help me please ?
19 Comments
Adam Danz
on 6 Feb 2021
> suddenly it become so slow
Does that mean it became slow durring evaluation of the loops or one day you ran this in Matlab and the whole process was slower that previously, using the same inputs?
Rahim Rahim
on 6 Feb 2021
Adam Danz
on 6 Feb 2021
That's helpful to know but I still have the same quesiton.
The running became slow during the evaluation (i.e, after the first 1000 iterations) or the entire process from iteration #1 became slower compared to previous days?
Rahim Rahim
on 6 Feb 2021
Rahim Rahim
on 6 Feb 2021
I was just having the same conversaion a couple of days ago with another user and volunteer in the thread below. There are 3 relevant points to check out in that thread:
- How to hone in on the problem using tic/toc timing or profiling.
- The possibilty that the size of your variables are changing and requiring more resources as interations increase.
- File compression, if you're saving any of the data.
Rahim Rahim
on 6 Feb 2021
Adam Danz
on 6 Feb 2021
I haven't emailed you; maybe you meant my comment.
Does the timing jump around between 2-6 seconds or is there a pattern in certain sections of the loops?
Did you preallocate the NewMatrix array? That's very important.
Rahim Rahim
on 6 Feb 2021
Edited: Rahim Rahim
on 6 Feb 2021
Rahim Rahim
on 6 Feb 2021
Adam Danz
on 6 Feb 2021
I didn't understand that last question. But you haven't answered this one:
Did you preallocate the NewMatrix array? That's very important.
If you haven't preallocated, it will drastically slow down your code.
Rahim Rahim
on 7 Feb 2021
Rahim Rahim
on 7 Feb 2021
Rahim Rahim
on 7 Feb 2021
Adam Danz
on 7 Feb 2021
> I used preallocate but without any differences.
I highly doubt there was no difference between with/without preallocation if you're storing something within the nested loops. If you're not storing anything, then that's more believable.
> I used my code in another laptop, it run without delay
> Yes, the running became slow during the evaluation.
It sounds like the slow-down is caused both by the machine you're using and the sequence of iterations within the nested loops. The link I provided may help to explain why the process is slowing down during the loops. If there's a difference between machines and you're using the exact same version of code, version of Matlab, and inputs. then obviously the machine is causing the difference. There could be a difference in processors, RAM, etc.
Adam Danz
on 7 Feb 2021
Here's my recommendation.
Run matlab's profiler on your code on both computers using the exact same version of the code, the exact same inputs and the the exact same release of Matlab. Then compare the reports.
Rahim Rahim
on 8 Feb 2021
David Goodmanson
on 8 Feb 2021
Hi Rahim,
One thing worth checking is, with windows 10 bring up the task mananger, click the Perfomance tab, start the program and see what the memory, disk and possibly cpu activity looks like as a function of time.
Adam Danz
on 8 Feb 2021
Please spend some time reading the documentation for that function.
You need to follow the second example, "Profile Function and Save Results as HTML".
Then you need to view the reports and compare them.
And don't forget to take time to formally accept answers that were helpful to you so you can give credit to the volunteers who gave their time to you. This isn't an answer, it's just a comment, but you can go into your profile and see many questions that have been answered and none accepted.
Answers (0)
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!