]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Clean up initialization of MinMaxAvg values. 5022/head
authorDavid Wells <wellsd2@rpi.edu>
Mon, 4 Sep 2017 17:13:42 +0000 (13:13 -0400)
committerDavid Wells <wellsd2@rpi.edu>
Mon, 4 Sep 2017 17:13:42 +0000 (13:13 -0400)
source/base/timer.cc
tests/base/timer_05.cc

index 164016c396a5db1bdd6cdf0b08d0a00dfecd3248..ab8825498d3382362d46f3af6be04974fa6cf79c 100644 (file)
@@ -84,6 +84,19 @@ namespace internal
         return Period::num*double(duration.count())/Period::den;
       }
 
+      /**
+       * Fill a MinMaxAvg struct with default values.
+       */
+      void
+      clear_timing_data(Utilities::MPI::MinMaxAvg &data)
+      {
+        data.sum = numbers::signaling_nan<double>();
+        data.min = numbers::signaling_nan<double>();
+        data.max = numbers::signaling_nan<double>();
+        data.avg = numbers::signaling_nan<double>();
+        data.min_index = numbers::invalid_unsigned_int;
+        data.max_index = numbers::invalid_unsigned_int;
+      }
     }
   }
 }
@@ -151,11 +164,7 @@ Timer::Timer(MPI_Comm mpi_communicator,
   mpi_communicator (mpi_communicator),
   sync_wall_time(sync_wall_time_)
 {
-  last_lap_data.sum = last_lap_data.min = last_lap_data.max = last_lap_data.avg = numbers::signaling_nan<double>();
-  last_lap_data.min_index = last_lap_data.max_index = numbers::invalid_unsigned_int;
-  accumulated_wall_time_data.sum = accumulated_wall_time_data.min = accumulated_wall_time_data.max = accumulated_wall_time_data.avg = 0.;
-  accumulated_wall_time_data.min_index = accumulated_wall_time_data.max_index = 0;
-
+  reset();
   start();
 }
 
@@ -275,11 +284,9 @@ void Timer::reset ()
 {
   wall_times.reset();
   cpu_times.reset();
-  running         = false;
-  last_lap_data.sum = last_lap_data.min = last_lap_data.max = last_lap_data.avg = numbers::signaling_nan<double>();
-  last_lap_data.min_index = last_lap_data.max_index = numbers::invalid_unsigned_int;
-  accumulated_wall_time_data.sum = accumulated_wall_time_data.min = accumulated_wall_time_data.max = accumulated_wall_time_data.avg = 0.;
-  accumulated_wall_time_data.min_index = accumulated_wall_time_data.max_index = 0;
+  running = false;
+  internal::Timer::clear_timing_data(last_lap_data);
+  internal::Timer::clear_timing_data(accumulated_wall_time_data);
 }
 
 
index 8c385751844cadde7075eac5c113e7f2feac0d40..493640bd2c811346a1287d523e3a49eec2ab7b03 100644 (file)
@@ -32,6 +32,33 @@ void burn (unsigned int n)
     }
 }
 
+// check that the MinMaxAvg is set to a default, unpopulated state.
+void
+assert_min_max_avg_invalid(const Utilities::MPI::MinMaxAvg &data)
+{
+  // we want to explicitly check that some things are signaling NaNs, so
+  // disable FP exceptions if they are on
+#if defined(DEBUG) && defined(DEAL_II_HAVE_FP_EXCEPTIONS)
+  fedisableexcept(FE_INVALID);
+#endif
+
+  AssertThrow(std::isnan(data.min), ExcInternalError());
+  AssertThrow(std::isnan(data.max), ExcInternalError());
+  AssertThrow(std::isnan(data.avg), ExcInternalError());
+  AssertThrow(data.min_index == numbers::invalid_unsigned_int, ExcInternalError());
+  AssertThrow(data.max_index == numbers::invalid_unsigned_int, ExcInternalError());
+}
+
+// check that the MinMaxAvg values are reasonable.
+void
+assert_min_max_avg_valid(const Utilities::MPI::MinMaxAvg &data)
+{
+  AssertThrow(data.min > 0., ExcInternalError());
+  AssertThrow(data.max >= data.min, ExcInternalError());
+  AssertThrow(data.avg >= data.min, ExcInternalError());
+  AssertThrow(data.min_index != numbers::invalid_unsigned_int, ExcInternalError());
+  AssertThrow(data.max_index != numbers::invalid_unsigned_int, ExcInternalError());
+}
 
 
 void
@@ -43,22 +70,30 @@ test_timer(Timer &t)
   AssertThrow(old_wall_time > 0., ExcInternalError());
   const double old_cpu_time = t.wall_time();
   AssertThrow(old_cpu_time > 0., ExcInternalError());
-  AssertThrow(t.get_total_data().max == 0., ExcInternalError());
+  assert_min_max_avg_invalid(t.get_data());
+  assert_min_max_avg_invalid(t.get_total_data());
+  assert_min_max_avg_invalid(t.get_last_lap_data());
+  assert_min_max_avg_invalid(t.get_accumulated_wall_time_data());
 
   burn(50);
   AssertThrow(t.stop() > 0., ExcInternalError());
+  assert_min_max_avg_valid(t.get_data());
+  assert_min_max_avg_valid(t.get_total_data());
+  assert_min_max_avg_valid(t.get_last_lap_data());
+  assert_min_max_avg_valid(t.get_accumulated_wall_time_data());
 
   AssertThrow(t.wall_time() > old_wall_time, ExcInternalError());
   AssertThrow(t.cpu_time() > old_cpu_time, ExcInternalError());
   AssertThrow(t.last_wall_time() > 0., ExcInternalError());
   AssertThrow(t.last_cpu_time() > 0., ExcInternalError());
-  AssertThrow(t.get_data().min > 0., ExcInternalError());
-  AssertThrow(t.get_total_data().min > 0., ExcInternalError());
 
   t.reset();
   AssertThrow(t.wall_time() == 0., ExcInternalError());
   AssertThrow(t.cpu_time()== 0., ExcInternalError());
-  AssertThrow(t.get_total_data().max == 0, ExcInternalError());
+  assert_min_max_avg_invalid(t.get_data());
+  assert_min_max_avg_invalid(t.get_total_data());
+  assert_min_max_avg_invalid(t.get_last_lap_data());
+  assert_min_max_avg_invalid(t.get_accumulated_wall_time_data());
 
   deallog << "OK" << std::endl;
 }
@@ -76,4 +111,3 @@ int main (int argc, char **argv)
   test_timer(t1);
   test_timer(t2);
 }
-

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.