gusl: (Default)
[personal profile] gusl
Right now, I have some Matlab code running, which has been going for 10 minutes. It's in a loop, iterating over many values of a parameter i. Since I didn't think of putting prints, I can't tell how far along it is.

I'd like to interrupt it, query the value of i, and tell it go back, wasting at most one iteration's worth of work. It's not asking much, since it's easy to make another loop starting at the interrupted value of i and going until the end.

Unfortunately, I'd have to do this by hand.

(no subject)

Date: 2008-11-23 08:20 am (UTC)
From: [identity profile] gwillen.livejournal.com
In lisp you could do this.

(no subject)

Date: 2008-11-23 09:27 am (UTC)
From: [identity profile] peamasii.livejournal.com
i don't know anything about matlab, but couldn't you write it so that it pauses on keyboard input and prints out i value? alternately have it log i ever 1000 iterations or so?

(no subject)

Date: 2008-11-23 09:54 am (UTC)
From: [identity profile] gustavolacerda.livejournal.com
<< couldn't you write it so that it pauses on keyboard input and prints out i value? >>

This involves concurrent programming. Overkill.


Yes, of course you can make it log. The point is that it's usually too late by the time you notice it.

What I'm saying is there's no reason for the language require the execution be uninterruptible. As [livejournal.com profile] gwillen said, Lisp allows this (which is news to me, though).

(no subject)

Date: 2008-11-23 10:14 am (UTC)
From: (Anonymous)
In Mathematica, you can trap the execution interrupt and inspect the variables at any point. Perhaps Matlab has something like it.

(no subject)

Date: 2008-11-23 10:29 am (UTC)
From: [identity profile] gustavolacerda.livejournal.com
hi. Who is this?

(no subject)

Date: 2008-11-23 12:37 pm (UTC)
From: [identity profile] stepleton.livejournal.com
If you type dbstop if error, MATLAB will drop to the debug prompt with your ctrl-C. Unfortunately, you cannot resume your program this way. ctrl-C is an error. Errors stop programs.

So here is what else you can do:

Within your loop, test for the existence of a file. If it's there, call keyboard. This gives you a debug prompt you can resume from with dbcont.

Or, within your loop, save your state to a .mat file with save. Start a second MATLAB and load the .mat file, inspect, etc.

(no subject)

Date: 2008-11-23 12:52 pm (UTC)
From: [identity profile] en-ki.livejournal.com
With a general Unix process, I would use gdb or strace to attach to the process. Are you able to run a second MATLAB instance and have it trace a running process?

(no subject)

Date: 2008-11-23 01:59 pm (UTC)
From: [identity profile] altamira16.livejournal.com
Are you going to be running this code again? Is the number of loop iterations a known value? If so you can stick an if statement in there like
if (mod(i, N/k) == 0) 
 i 
end


where k is smaller than N and N is divisible by k multiple times at least.

(no subject)

Date: 2008-11-23 06:51 pm (UTC)
From: [identity profile] gwillen.livejournal.com
Press control-C or otherwise interrupt the computation. You will be dropped into a debugger. You can move up to the stack frame you care about, inspect the variable you're interested in, then tell it to continue.

February 2020

S M T W T F S
      1
2345678
9101112131415
16171819202122
23242526272829

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags