]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Added get_lap_time() to Timer; returning the time taken between the last start()... 240/head
authorFahad Alrashed <fahad@keylock.net>
Mon, 10 Nov 2014 14:58:08 +0000 (08:58 -0600)
committerFahad Alrashed <fahad@keylock.net>
Mon, 10 Nov 2014 16:58:04 +0000 (10:58 -0600)
doc/news/changes.h
include/deal.II/base/timer.h
source/base/timer.cc

index 00194caf27f94ae5949ad8e22db524a26d7d80f5..9c43d0ff518a7d3c95f5df321abd74572c32e46c 100644 (file)
@@ -333,6 +333,12 @@ inconvenience this causes.
 <h3>Specific improvements</h3>
 
 <ol>
+  <li> New: Timer now has get_lap_time() which returns the time
+  lapsed between the last start()/stop() cycle.
+  <br>
+  (Fahad Alrashed, 2014/11/09)
+  </li>
+
   <li> New: TableHandler objects can be cleared - i.e. reset to a 
   zero-sized state.
   <br>
index c41877d2213f9cb3fe52a622ac0f71c1f44066db..bdd0c7a9894fa3ff90932e20941ce170dd9fffd0 100644 (file)
@@ -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.
index 7a24d3aabeac2c383444664ea55836a5c8eaec5c..e28a0b01466f9683f7557d0e91bfa4ef4a88f1f8 100644 (file)
@@ -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;

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.