From fb7f86683a89699db021b6ec34e94c3074bb480e Mon Sep 17 00:00:00 2001 From: Fahad Alrashed Date: Mon, 10 Nov 2014 08:58:08 -0600 Subject: [PATCH] Added get_lap_time() to Timer; returning the time taken between the last start()/stop() cycle. --- doc/news/changes.h | 6 ++++++ include/deal.II/base/timer.h | 13 +++++++++++++ source/base/timer.cc | 31 ++++++++++++++++++++++++------- 3 files changed, 43 insertions(+), 7 deletions(-) diff --git a/doc/news/changes.h b/doc/news/changes.h index 00194caf27..9c43d0ff51 100644 --- a/doc/news/changes.h +++ b/doc/news/changes.h @@ -333,6 +333,12 @@ inconvenience this causes.

Specific improvements

    +
  1. New: Timer now has get_lap_time() which returns the time + lapsed between the last start()/stop() cycle. +
    + (Fahad Alrashed, 2014/11/09) +
  2. +
  3. New: TableHandler objects can be cleared - i.e. reset to a zero-sized state.
    diff --git a/include/deal.II/base/timer.h b/include/deal.II/base/timer.h index c41877d221..bdd0c7a989 100644 --- a/include/deal.II/base/timer.h +++ b/include/deal.II/base/timer.h @@ -169,6 +169,13 @@ public: */ double wall_time () const; + /** + * Returns the last lap time; the + * time taken between the last start()/stop() + * call. + */ + double get_lap_time () const; + private: /** @@ -225,6 +232,12 @@ private: */ double cumulative_wall_time; + /** + * Stores the last lap time; the time + * between the last start()/stop() cycle. + */ + double last_lap_time; + /** * Store whether the timer is presently * running. diff --git a/source/base/timer.cc b/source/base/timer.cc index 7a24d3aabe..e28a0b0146 100644 --- a/source/base/timer.cc +++ b/source/base/timer.cc @@ -160,10 +160,10 @@ double Timer::stop () struct timeval wall_timer; gettimeofday(&wall_timer, NULL); - double time = wall_timer.tv_sec + 1.e-6 * wall_timer.tv_usec - - start_wall_time; + last_lap_time = wall_timer.tv_sec + 1.e-6 * wall_timer.tv_usec + - start_wall_time; #elif defined(DEAL_II_MSVC) - double time = windows::wall_clock() - start_wall_time; + last_lap_time = windows::wall_clock() - start_wall_time; cumulative_time += windows::cpu_clock() - start_time; #else # error Unsupported platform. Porting not finished. @@ -173,19 +173,35 @@ double Timer::stop () if (sync_wall_time && Utilities::System::job_supports_mpi()) { this->mpi_data - = Utilities::MPI::min_max_avg (time, mpi_communicator); - - cumulative_wall_time += this->mpi_data.max; + = Utilities::MPI::min_max_avg (last_lap_time, mpi_communicator); + last_lap_time = this->mpi_data.max; + cumulative_wall_time += last_lap_time; } else #endif - cumulative_wall_time += time; + cumulative_wall_time += last_lap_time; } return cumulative_time; } +double Timer::get_lap_time() const +{ + // time already has the difference + // between the last start()/stop() + // cycle. +#ifdef DEAL_II_WITH_MPI + if (Utilities::System::job_supports_mpi()) + return Utilities::MPI::max (last_lap_time, mpi_communicator); + else +#endif + return last_lap_time; + +} + + + double Timer::operator() () const { if (running) @@ -255,6 +271,7 @@ double Timer::wall_time () const void Timer::reset () { + last_lap_time = 0.; cumulative_time = 0.; cumulative_wall_time = 0.; running = false; -- 2.39.5