tags:

views:

52

answers:

4

Hi, I have a script doing some computation and save some invisible plots into image files inside a for-loop on a linux server.

When I run the script, it usually get stuck in somewhere in the middle. I am not sure where exactly it stopped, but I can know at which iteration of the for-loop it stops by print-out. if I rerun it from the iteration where it stopped, it could continue to run past that place. So it seems to me there is no bug.

I just wonder how I can identify at which line it stops?

what might be the cause of the problem and how I can run the whole script from the beginning till the end?

Thanks!


UPDATE:

I use dbstop

dbstop if error  
dbstop if warning  
run path2script

The running still gets stuck somewhre and no message is given regarding why.

A: 

What type of script is it?

Are you running out of memory? If you're exceeding the maximum allocated heap size, it could crash. When you re-launch it, it starts with all the memory it originally had and can run to completion before it might use all of its memory again.

I'd recommend checking for memory leaks.

Eli
Thanks! How to check for memory leaks?
Tim
What's `path2script`? To be honest, I don't know much about MATLAB. You might be able to give yourself more memory by doing something like this: http://www.mathworks.com/support/solutions/en/data/1-18I2C/index.html ... and if you paste some of your script, I can try to see if anything looks terribly inefficient.
Eli
A: 

What exactly happens when your script gets "stuck"? Does it exit back to the prompt, or does matlab simply hang? If it is the latter, then it sounds like you have an infinite loop in your code...

Dima
A: 

Difficult to tell without any knowledge about the script and the environment. Are you sure it is stuck and not just busy computing something or getting more memory? You could try to set a conditional breakpoint shortly before the iteration where the hang occurs and then interactively step through the following code using the debugger.

groovingandi
A: 

As groovingandi suggests, set a conditional breakpoint within your code at the start of the iteration where the for loop normally gets stuck. You can do this with a command like:

dbstop in runscript at 500 if iLoop==365 
% where 500 is the first line within the for loop,
% and 365 is the iteration causing problems

If your script gets stuck without breakpoints, but can continue happily past that point if you use breakpoints and then continue, this normally indicates you've got a sporadic failure that's time-dependent, perhaps a race condition. Perhaps you're writing a file to the operating system, and then immediately afterwards looking at the OS to figure out what the next file's name should be, but your filesystem is cacheing slightly? Things like that have caused similar problems for me.

Look carefully at what your code is doing each time round the loop, for anything that might depend on steps before it that might be running asynchronously.

AlexC

related questions