From b4c64637c5373aaf7cec12a3ecd43e480a1aa318 Mon Sep 17 00:00:00 2001 From: Erik Schnetter Date: Thu, 14 Mar 2013 09:55:36 -0400 Subject: Carpet: Add CactusTimer functions to get all clock values of a timer --- Carpet/Carpet/src/CactusTimer.cc | 72 ++++++++++++++++++++++++++++------------ Carpet/Carpet/src/CactusTimer.hh | 18 +++++++--- 2 files changed, 64 insertions(+), 26 deletions(-) diff --git a/Carpet/Carpet/src/CactusTimer.cc b/Carpet/Carpet/src/CactusTimer.cc index 7e13115be..966fe9d7e 100644 --- a/Carpet/Carpet/src/CactusTimer.cc +++ b/Carpet/Carpet/src/CactusTimer.cc @@ -1,8 +1,11 @@ #include #include #include -#include #include +#include +#include +#include +#include #include #include @@ -99,30 +102,57 @@ namespace Carpet val = -1; } - // for (int i=0; in_vals; ++i) { - // switch (timer->vals[i].type) { - // case val_int: - // val = timer->vals[i].val.i; - // break; - // case val_long: - // val = timer->vals[i].val.l; - // break; - // case val_double: - // val = timer->vals[i].val.d; - // break; - // case val_none: - // val = 0; // ?? - // break; - // default: - // assert (0); - // } - // } - if (was_running) start(); return val; } - + + vector > CactusTimer::getAllTimerNames() const + { + DECLARE_CCTK_PARAMETERS; + + static cTimerData *timer = NULL; + if (not timer) timer = CCTK_TimerCreateData(); + assert(timer); + + CCTK_TimerI(handle, timer); + + vector > names(timer->n_vals); + for (int i=0; in_vals; ++i) { + names[i].first = timer->vals[i].heading; + names[i].second = timer->vals[i].units; + } + + return names; + } + + vector CactusTimer::getAllTimerValues() + { + DECLARE_CCTK_PARAMETERS; + + bool const was_running = running; + if (was_running) stop(); + + static cTimerData *timer = NULL; + if (not timer) timer = CCTK_TimerCreateData(); + assert(timer); + + CCTK_TimerI(handle, timer); + + vector vals(timer->n_vals); + for (int i=0; in_vals; ++i) { + switch (timer->vals[i].type) { + case val_int: vals[i] = timer->vals[i].val.i; break; + case val_long: vals[i] = timer->vals[i].val.l; break; + case val_double: vals[i] = timer->vals[i].val.d; break; + default: CCTK_BUILTIN_UNREACHABLE(); + } + } + + if (was_running) start(); + + return vals; + } // Print timer data void CactusTimer::printData () diff --git a/Carpet/Carpet/src/CactusTimer.hh b/Carpet/Carpet/src/CactusTimer.hh index 071ffc9ac..851bf7ca5 100644 --- a/Carpet/Carpet/src/CactusTimer.hh +++ b/Carpet/Carpet/src/CactusTimer.hh @@ -1,11 +1,13 @@ - #ifndef CACTUSTIMER_HH #define CACTUSTIMER_HH +#include + #include #include #include -#include +#include +#include namespace Carpet { @@ -39,12 +41,18 @@ namespace Carpet { /// Timer name string name () const; - /// Print timer data - void printData (); - /// Return the current time of the timer as a double double getTime(); + /// Return all clock names + vector > getAllTimerNames() const; + + /// Return all clock values of the timer as double + vector getAllTimerValues(); + + /// Print timer data + void printData (); + ostream& serialise(ostream &os); private: -- cgit v1.2.3