Skip to content

Commit

Permalink
Add ReturnData::cpu_time_total to track total time spent in runAmic…
Browse files Browse the repository at this point in the history
…iS… (#1743)

Add `ReturnData::cpu_time_total` to track total time spent in `runAmiciSimulation`
  • Loading branch information
dweindl authored Mar 25, 2022
1 parent 3bbf6e4 commit 3683d3e
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 2 deletions.
3 changes: 3 additions & 0 deletions include/amici/rdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,9 @@ class ReturnData: public ModelDimensions {
/** computation time of backward solve [ms] */
double cpu_timeB = 0.0;

/** total CPU time from entering runAmiciSimulation until exiting [ms] */
double cpu_time_total = 0.0;

/** flags indicating success of steady state solver (preequilibration) */
std::vector<SteadyStateStatus> preeq_status;

Expand Down
1 change: 1 addition & 0 deletions include/amici/serialization.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ void serialize(Archive &ar, amici::ReturnData &r, const unsigned int /*version*/
ar &r.order;
ar &r.cpu_time;
ar &r.cpu_timeB;
ar &r.cpu_time_total;
ar &r.preeq_cpu_time;
ar &r.preeq_cpu_timeB;
ar &r.preeq_status;
Expand Down
2 changes: 1 addition & 1 deletion python/amici/numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ class ReturnDataView(SwigPtrView):
'posteq_cpu_timeB', 'numsteps', 'numrhsevals',
'numerrtestfails', 'numnonlinsolvconvfails', 'order', 'cpu_time',
'numstepsB', 'numrhsevalsB', 'numerrtestfailsB',
'numnonlinsolvconvfailsB', 'cpu_timeB'
'numnonlinsolvconvfailsB', 'cpu_timeB', 'cpu_time_total'
]

def __init__(self, rdata: Union[ReturnDataPtr, ReturnData]):
Expand Down
2 changes: 1 addition & 1 deletion python/tests/test_pysb.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def test_compare_to_sbml_import(pysb_example_presimulation_module,
skip_attrs = ['ptr', 'preeq_t', 'numsteps', 'preeq_numsteps',
'numrhsevals', 'numerrtestfails', 'order', 'J', 'xdot',
'preeq_wrms', 'preeq_cpu_time', 'cpu_time',
'cpu_timeB', 'w']
'cpu_timeB', 'cpu_time_total', 'w']

for field in rdata_pysb:
if field in skip_attrs:
Expand Down
5 changes: 5 additions & 0 deletions src/amici.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ AmiciApplication::runAmiciSimulation(Solver& solver,
Model& model,
bool rethrow)
{
auto start_time_total = clock();
solver.startTimer();

/* Applies condition-specific model settings and restores them when going
Expand Down Expand Up @@ -233,6 +234,10 @@ AmiciApplication::runAmiciSimulation(Solver& solver,
preeq.get(), fwd.get(),
bwd_success ? bwd.get() : nullptr,
posteq.get(), model, solver, edata);

rdata->cpu_time_total = static_cast<double>(clock() - start_time_total)
* 1000.0 / CLOCKS_PER_SEC;

return rdata;
}

Expand Down
3 changes: 3 additions & 0 deletions src/hdf5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,9 @@ void writeReturnDataDiagnosis(const ReturnData &rdata,
H5LTset_attribute_double(file.getId(), hdf5Location.c_str(),
"cpu_timeB", &rdata.cpu_timeB, 1);

H5LTset_attribute_double(file.getId(), hdf5Location.c_str(),
"cpu_time_total", &rdata.cpu_time_total, 1);

if (!rdata.J.empty())
createAndWriteDouble2DDataset(file, hdf5Location + "/J", rdata.J,
rdata.nx, rdata.nx);
Expand Down

0 comments on commit 3683d3e

Please sign in to comment.