I am in the process of converting parallel network code from HOC to Python. The HOC code installs a handler via FInitializeHandler that compares the elapsed wall time with the maximum time for the job, estimates whether there is sufficient time to complete the simulation, and reduces tstop if necessary (code below). The HOC version of the code used psolve and it seemed that whenever the handler modified tstop, psolve accordingly only integrated until that new value of tstop. But it looks like when calling psolve and FInitializeHandler from Python, but still using the HOC handler, psolve keeps using the original tstop value. What is the correct way to port this code? Should the handler routine be written in Python as well? Thanks!
Python invocation of FInitializeHandler:
Code: Select all
...
h('objref fi_status')
if pc.id() == 0:
h.fi_status = h.FInitializeHandler("simstatus()")
h.stdinit()
pc.psolve(h.tstop)
Code: Select all
walltime = 0
dt_status = 1.0
proc simstatus() { local wt
wt = startsw()
if (walltime > 0) {
printf("*** computation time at t=%g ms was %g s\n", t, wt-walltime)
checksimtime(wt, wt-walltime)
}
walltime = wt
if (t + dt_status < tstop) {
cvode.event(t + dt_status, "simstatus()")
}
}
tcsum = 0
tcma = 0
nsimsteps = 0
proc checksimtime() { local wt, tt, trem, tsimrem, tsimneeded, tstop1
wt = $1
tt = $2
// cumulative moving average simulation time per time step
tcma = tcma + (tt - tcma) / (nsimsteps + 1)
tcsum = tcsum + tt
// remaining physical time
trem = tstop - t
// remaining simulation time
tsimrem = max_walltime_hrs*3600 - tcsum - mkcellstime - connectcellstime - connectgjstime
// simulation time necessary to complete the simulation
tsimneeded = trem*tcma+results_write_time
printf("*** remaining computation time is %g s and remaining simulation time is %g ms\n", tsimrem, trem)
printf("*** estimated computation time to completion is %g s\n", tsimneeded)
if (tsimneeded > tsimrem) {
tstop1 = int((tsimrem - results_write_time)/tt) + t
printf ("*** not enough time to complete %g ms simulation, simulation will likely stop around %g ms\n", tstop, tstop1)
tstop = tstop1
}
nsimsteps = nsimsteps + 1
}