diff options
author | Erik Schnetter <schnetter@gmail.com> | 2013-03-14 09:55:36 -0400 |
---|---|---|
committer | Erik Schnetter <schnetter@gmail.com> | 2013-03-14 09:55:36 -0400 |
commit | b4c64637c5373aaf7cec12a3ecd43e480a1aa318 (patch) | |
tree | d60d74ee1fe2a5640173c0059d65c40f89d72ca6 | |
parent | 14093d59320939dbf81bfa0e331a9be8e3a40d54 (diff) |
Carpet: Add CactusTimer functions to get all clock values of a timer
-rw-r--r-- | Carpet/Carpet/src/CactusTimer.cc | 72 | ||||
-rw-r--r-- | 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 <cassert> #include <cstdio> #include <cstring> -#include <list> #include <iomanip> +#include <list> +#include <string> +#include <utility> +#include <vector> #include <cctk.h> #include <cctk_Parameters.h> @@ -99,30 +102,57 @@ namespace Carpet val = -1; } - // for (int i=0; i<timer->n_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<pair<string,string> > CactusTimer::getAllTimerNames() const + { + DECLARE_CCTK_PARAMETERS; + + static cTimerData *timer = NULL; + if (not timer) timer = CCTK_TimerCreateData(); + assert(timer); + + CCTK_TimerI(handle, timer); + + vector<pair<string,string> > names(timer->n_vals); + for (int i=0; i<timer->n_vals; ++i) { + names[i].first = timer->vals[i].heading; + names[i].second = timer->vals[i].units; + } + + return names; + } + + vector<double> 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<double> vals(timer->n_vals); + for (int i=0; i<timer->n_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 <cctk.h> + #include <iostream> #include <list> #include <string> -#include <cctk.h> +#include <utility> +#include <vector> 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<pair<string,string> > getAllTimerNames() const; + + /// Return all clock values of the timer as double + vector<double> getAllTimerValues(); + + /// Print timer data + void printData (); + ostream& serialise(ostream &os); private: |