suddenly MATLAB process is too slow

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

> 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?
I used the same code, the same input, the same output but the runing is become slow
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?
Yes, the running became slow during the evaluation. In the past, it take 1 minutes to run but he become take 30 minutes !!!
During iterations yes !
Adam Danz
Adam Danz on 6 Feb 2021
Edited: Adam Danz 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:
  1. How to hone in on the problem using tic/toc timing or profiling.
  2. The possibilty that the size of your variables are changing and requiring more resources as interations increase.
  3. File compression, if you're saving any of the data.
@Adam Danz thank you for your email,
I used tic/toc and the time of each iteration have different time, for example iteration 10: Elapsed time is 5.993782 seconds and iteration 20 : 2.00082 seconds .
I don't understand what's the problem right now, please help me
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
Rahim Rahim on 6 Feb 2021
Edited: Rahim Rahim on 6 Feb 2021
I did not change anything, 3 days ago the timing was 1 second. Now, between 2 and 6, yes it jumps
I think is a problem of size, who can I give a big space to my code ?
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.
@Adam Danz I used preallocate but without any differences.
@Adam Danz If my code requir more resources, what can I do ?
@Adam Danz I used my code in another laptop, it run without delay ( run fast ). so the problem in my laptop, I don't exactly know what is the problem !!
> 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.
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.
Also, I noticed you haven't accepts any answers (link). Why is that?
@Adam Danz I am so sorry, I putted a lot of questions, and I am begginer on matlab.
This is the results of profile('status')
ProfilerStatus: 'off'
DetailLevel: 'mmex'
Timer: 'performance'
HistoryTracking: 'timestamp'
HistorySize: 1000000
and this the results of profile('info')
FunctionTable: [0×1 struct]
FunctionHistory: [4×0 double]
ClockPrecision: 1.000000000000000e-07
ClockSpeed: 2.592000000000000e+09
Name: 'MATLAB'
Overhead: 0
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.
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.

Sign in to comment.

Answers (0)

Categories

Products

Release

R2018b

Asked:

on 6 Feb 2021

Commented:

on 8 Feb 2021

Community Treasure Hunt

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

Start Hunting!