time measurements

Anything that doesn't fit elsewhere.
Post Reply
mattnolan
Posts: 8
Joined: Thu Mar 05, 2009 11:39 am

time measurements

Post by mattnolan »

How do I accurately access the actual time from within neuron? E.g. To use as a timestamp or to benchmark simulation times.

Thanks,

Matt
ted
Site Admin
Posts: 6289
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: time measurements

Post by ted »

Read about startsw() and stopsw() in the Programmer's Reference list of functions
http://www.neuron.yale.edu/neuron/stati ... #functions
If you are using UNIX/Linux/OS X you can instead use system() to execute your OS's date function; you'll find a link to documentation about system() in the same list of functions.
mattnolan
Posts: 8
Joined: Thu Mar 05, 2009 11:39 am

Re: time measurements

Post by mattnolan »

Thanks for the pointer.

startsw() / stopsw() appears to be reset on exit from run(). Is there a way to switch this off?


Example code:
startsw()
for j=0, 10000000 {x = sin(.2)}
print stopsw()


startsw()
for j=0, 10000000 {x = sin(.2)}
run()
print stopsw()
ted
Site Admin
Posts: 6289
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: time measurements

Post by ted »

mattnolan wrote:startsw() / stopsw() appears to be reset on exit from run().
No, resetting the stopwatch is one of the first things that run() does (by calling finitialize()). This seems reasonable for benchmarking runs.
Is there a way to switch this off?
Not unless you tinker with the innards of the standard run system's initialization code, which is not advisable.

However, once you call run() and let the simulation finish, you can resume the simulation, without having the side-effect of executing finitialize() and resetting the stopwatch, by calling continuerun() like so:
{continuerun(t + extratime) stoprun=1}
The simulation will then run for another "extratime" ms in model time.
mattnolan
Posts: 8
Joined: Thu Mar 05, 2009 11:39 am

Re: time measurements

Post by mattnolan »

stopsw() gives me a value of zero immediately after a call to run() that takes several minutes to complete. This makes me think the stopwatch is reset towards the end of the run() call.

Not sure what to try next. Am I missing something?

Thanks,

Matt
ted
Site Admin
Posts: 6289
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: time measurements

Post by ted »

mattnolan wrote:stopsw() gives me a value of zero immediately after a call to run() that takes several minutes to complete. This makes me think the stopwatch is reset towards the end of the run() call.
That sounds more like a bug than a feature, but perhaps there is a sound reason for it.
Not sure what to try next.
realtime is what you want. finitialize() resets realtime to 0. At the end of a run, realtime stays nonzero until you intialize (or run) again. Documentation of RunControl panel's RealTime button
http://www.neuron.yale.edu/neuron/stati ... l#RealTime
says resolution is 1 s, but on my Linux box it seems to be 0.01 s.

How to discover useful stuff about NEURON's run time system:
1. save a RunControl panel to a ses file, then analyze the ses file, draw inferences from what you see, and test them.
2. take the plunge and examine the contents of c:/nrnxx/lib/hoc/stdrun.hoc (under *nix and OS X this is nrn/share/nrn/lib/hoc/stdrun.hoc). Don't change the contents of that file; but if you find something interesting, it's OK to copy it and use it in a toy hoc program of your own, modify it there, and run some tests to verify that your inferences are correct. Note that, since hoc is an interpreter, any func or proc can be redefined by executing new code. This means your test program can be
load_file("nrngui.hoc") // among other stuff, loads stdrun.hoc (the standard run library)
. . . anything else you need to load or define . . .
load_file("customstuff.hoc") // contains your custom redefinitions of stuff, based on code lifted from stdrun.hoc
mattnolan
Posts: 8
Joined: Thu Mar 05, 2009 11:39 am

Re: time measurements

Post by mattnolan »

Thanks. I've cobbled something together using startsw() and realtime.
Post Reply