Why does Matlab not complete if the runtime for a computation is too long?

29 views (last 30 days)
(edited)
I've noticed that Matlab (2012b) won't complete a simulation I run if it lasts longer than about 10 hours. Why is this and what can I do about it?
i.e
An iteration may take 3 minutes. If I run 500 iterations, it should take 25 hours to solve. Instead Matlab runs on my PC for 3 days and doesn't finish. But, if I run 150 iterations, matlab finishes it happily in about 7.5 hours.
If I don't turn Matlab off manually (the x button) it will run for a week or more just going nowhere.
The clear() command can't be used after each iteration because i'm trying to make graphs that require lengthy computation times per point.
More details:
Desktop PC, I run Windows 7, I saw this issue on windows XP as well as on earlier versions of Matlab; all on the same PC. Ram usage never goes above about 500 megs. Core 2 duo, 3.0 gig processor. Machine is about 5 years old. 8 gigs ram. When I run simulations I don't use the machine for anything else, I switch to a laptop.
Also, when this has happened, I can still use other applications without a problem.
Part of what I'm not sure on, is it normal for Matlab do not like running computations beyond a certain time limit?
edit I believe these are all the required files if anyone wants to see what my code looks like. This is for an Ensemble Kalman Filter on the Lorenz (3D) system.
  1 Comment
C V Ambarish
C V Ambarish on 14 Jun 2017
Hey Max,
You've probably forgotten about this by now :P, but were you able to find out the root cause? Have almost exactly the same problem and I have no clue at this point. Thanks.
My question if you want to take a look. Any comments/suggestions appreciated.

Sign in to comment.

Answers (3)

Image Analyst
Image Analyst on 20 Oct 2013
We don't know. How could we? What operating system? How, EXACTLY, does MATLAB "die"? Are you managing memory well? Maybe you're running out of memory, though MATLAB will usually tell you that and not just die in a fiery steaming crash. Maybe you can explicitly use clear() at the end of functions to force it to clear variables immmediately. Maybe you can use cla('reset') before plotting to axes. It's hard to say exactly since we have no information other than you saying your program crashes after a long time.
  3 Comments
Image Analyst
Image Analyst on 21 Oct 2013
Edited: Image Analyst on 21 Oct 2013
Can you answer my other questions? And try my suggestions? But I suspect you may have to send the code to the Mathworks if it's a real crash: "MATLAB.exe has encountered an error and needs to close".
Max
Max on 21 Oct 2013
It's not a real crash. It just keeps running and running far beyond the normal computation times expected. It's not a memory leak, I can run other applications without a problem if I want to.

Sign in to comment.


Cedric
Cedric on 21 Oct 2013
Edited: Cedric on 21 Oct 2013
You should output all the information that you can, i.e. loop counters, branch of conditional statements, etc. If it's slowing down your simulation too much, start outputting it after e.g. 200 iterations (at least for inner loops). This will allow you to pinpoint the region of your code where MATLAB is stuck and refine your tests.
For example
t_start = tic ;
t_last = tic ;
for mainCnt = 1 : 500
fprintf( ['\n=== mainCnt = %d, %.2fmin from start, last it. took', ...
' %.2fmin.\n\n'], mainCnt, toc(t_start)/60, toc(t_last)/60 ) ;
if mainCnt >= 200
whos
[userview, systemview] = memory ;
fprintf( ' Sys memory: phys.-> avail. = %.2e, total = %.2e\n', ...
systemview.PhysicalMemory.Available, ...
systemview.PhysicalMemory.Total ) ;
fprintf( ' Usr memory: used by MATLAB = %.2e\n\n', ...
userview.MemUsedMATLAB ) ;
end
t_last = tic ;
for k = 1 : 40
if mainCnt >= 200
fprintf( ' - Inner loop: k = %d\n', k ) ;
end
...
end
if ...
fprintf( ' - Outer loop, if statement: true\n' ) ;
...
else
fprintf( ' - Outer loop, if statement: false\n' ) ;
...
end
end
  7 Comments
Max
Max on 23 Oct 2013
Matlab is still running at this point. Computation time is roughly linearly increasing as the iteration increases. Your comment makes sense though, each iteration runs the EnKF over the Lorenz system with more error/noise and then stores a bunch of results and error measurements I'm interested in.
I'll do some plots tomorrow when it's done.
Cedric
Cedric on 23 Oct 2013
Edited: Cedric on 23 Oct 2013
Ok, then add figure(1) before the tocs plot
% Plot tocs
figure(1) ;
plot( tocBuffer ) ;
grid on ;
xlabel( 'Iteration #' ) ;
ylabel( 'toc() 1-4' ) ;
and plot e.g. the size (1st dimension) of the output of relevant solver(s) using the same mechanism but figure(2) before the plot.
You could also test a few other solvers.

Sign in to comment.


Walter Roberson
Walter Roberson on 21 Oct 2013
You are slowly running out of RAM and your system is set to use virtual swap (to write to harddisk). When it starts needing to write to harddisk, everything will slow down by a factor of 10 to 100, but it will keep running.
  2 Comments
Cedric
Cedric on 21 Oct 2013
Edited: Cedric on 21 Oct 2013
The original question (before the edit) mentioned that the OP could still use other applications when MATLAB seemed to be stuck. When a MATLAB run leads to memory swap on my system, I can almost not use any other application; the UI becomes unresponsive and I can't close MATLAB by clicking on [x]. It is so annoying that I setup a memory watchdog with ProcessLasso which kills MATLAB before swap happens. I agree that it could be swap though, maybe in a context different than mine (a lot of small arrays(?) whereas I am generally dealing with a few large arrays).
Walter Roberson
Walter Roberson on 21 Oct 2013
I suppose another possibility is that with the increased iterations, the user is encountering an infinite loop, such as expecting that (X + 1) is always greater than X, which is not true for any of the numeric data types MATLAB uses.

Sign in to comment.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!