]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Swap out burn() for sleep in an erratic test. 16086/head
authorDavid Wells <drwells@email.unc.edu>
Tue, 3 Oct 2023 20:23:25 +0000 (16:23 -0400)
committerDavid Wells <drwells@email.unc.edu>
Tue, 3 Oct 2023 20:23:25 +0000 (16:23 -0400)
I did some experiments and, under load, I can get a few percentage points of
difference between section 1 and section 2 when using burn(). These go
away (also under load) when I use sleep(), so that should make this test more
reliable.

tests/base/timer_03.cc

index 0b19eef0f76764b64b707fe0f535a733c054cd3a..8b6d5142b3f6664d69e8ef7e307805ff5d3b62c0 100644 (file)
 //
 // ---------------------------------------------------------------------
 
-
-
 #include <deal.II/base/timer.h>
 
+#include <thread>
+
 #include "../tests.h"
 
 // compute the ratio of two measurements and compare to
@@ -28,8 +28,9 @@ compare(double t1, double t2, double ratio)
   double r = t2 / t1;
   double d = std::fabs(r - ratio) / ratio;
 
-  // relative error < 25%?
-  if (d <= .25)
+  // use a really coarse tolerance to account for situations in which we are
+  // running the test suite with very high load
+  if (d <= 0.5)
     {
       deallog << "OK" << std::endl;
     }
@@ -53,36 +54,20 @@ match(double v1, double v2)
     }
 }
 
-// burn computer time
-
-double s = 0.;
-void
-burn(unsigned int n)
-{
-  for (unsigned int i = 0; i < n; ++i)
-    {
-      for (unsigned int j = 1; j < 100000; ++j)
-        {
-          s += 1. / j * i;
-        }
-    }
-}
-
-
 int
 main()
 {
   initlog();
 
   Timer       t1, t2;
-  TimerOutput tO(std::cout, TimerOutput::summary, TimerOutput::cpu_times);
+  TimerOutput tO(std::cout, TimerOutput::summary, TimerOutput::wall_times);
 
   tO.enter_subsection("Section1");
   tO.enter_subsection("Section2");
-  burn(50);
+  std::this_thread::sleep_for(std::chrono::seconds(2));
   tO.leave_subsection("Section2");
   tO.enter_subsection("Section2");
-  burn(50);
+  std::this_thread::sleep_for(std::chrono::seconds(2));
   tO.leave_subsection("Section2");
   tO.leave_subsection("Section1");
 

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.