]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Update the explanations of Timer in the tutorials. 5025/head
authorDavid Wells <wellsd2@rpi.edu>
Mon, 4 Sep 2017 23:29:38 +0000 (19:29 -0400)
committerDavid Wells <wellsd2@rpi.edu>
Mon, 4 Sep 2017 23:29:38 +0000 (19:29 -0400)
examples/step-28/step-28.cc
examples/step-29/step-29.cc
examples/step-37/step-37.cc
include/deal.II/base/timer.h

index 100d7d52514336261df537d90ad7ea87474d40b7..a91988d8ae1124662263a2ca6ffdeb913aceb0f8 100644 (file)
 // @sect3{Include files}
 
 // We start with a bunch of include files that have already been explained in
-// previous tutorial programs:
+// previous tutorial programs. One new one is <code>timer.h</code>: This is
+// the first example program that uses the Timer class. The Timer keeps track
+// of both the elapsed wall clock time (that is, the amount of time that a
+// clock mounted on the wall would measure) and CPU clock time (the amount of
+// time that the current process uses on the CPUs). We will use a Timer below
+// to measure how much CPU time each grid refinement cycle takes.
 #include <deal.II/base/timer.h>
 #include <deal.II/base/quadrature_lib.h>
 #include <deal.II/base/function.h>
@@ -1640,11 +1645,15 @@ namespace Step28
 
     double k_eff_old = k_eff;
 
-    Timer timer;
-    timer.start ();
-
     for (unsigned int cycle=0; cycle<parameters.n_refinement_cycles; ++cycle)
       {
+        // We will measure the CPU time that each cycle takes below. The
+        // constructor for Timer calls Timer::start(), so once we create a
+        // timer we can query it for information. Since we use a thread pool
+        // to assemble the system matrices, the CPU time we measure (if we run
+        // with more than one thread) will be larger than the wall time.
+        Timer timer;
+
         std::cout << "Cycle " << cycle << ':' << std::endl;
 
         if (cycle == 0)
@@ -1717,6 +1726,10 @@ namespace Step28
         for (unsigned int group=0; group<parameters.n_groups; ++group)
           energy_groups[group]->output_results (cycle);
 
+        // Print out information about the simulation as well as the elapsed
+        // CPU time. We can call Timer::cpu_time() without first calling
+        // Timer::stop() to get the elapsed CPU time at the point of calling
+        // the function.
         std::cout << std::endl;
         std::cout << "   Cycle=" << cycle
                   << ", n_dofs=" << energy_groups[0]->n_dofs() + energy_groups[1]->n_dofs()
index 42a64566ec6e812e5fb6dcdca80992f60cf52719..b3a210ee580e5fee26b63ff030229b28c1053289 100644 (file)
@@ -433,7 +433,6 @@ namespace Step29
     // compute execution time when this function is done:
     deallog << "Generating grid... ";
     Timer timer;
-    timer.start ();
 
     // Then we query the values for the focal distance of the transducer lens
     // and the number of mesh refinement steps from our ParameterHandler
@@ -525,7 +524,6 @@ namespace Step29
   {
     deallog << "Setting up system... ";
     Timer timer;
-    timer.start();
 
     dof_handler.distribute_dofs (fe);
 
@@ -558,7 +556,6 @@ namespace Step29
   {
     deallog << "Assembling system matrix... ";
     Timer timer;
-    timer.start ();
 
     // First we query wavespeed and frequency from the ParameterHandler object
     // and store them in local variables, as they will be used frequently
@@ -805,7 +802,6 @@ namespace Step29
   {
     deallog << "Solving linear system... ";
     Timer timer;
-    timer.start ();
 
     // The code to solve the linear system is short: First, we allocate an
     // object of the right type. The following <code>initialize</code> call
@@ -843,7 +839,6 @@ namespace Step29
   {
     deallog << "Generating output... ";
     Timer timer;
-    timer.start ();
 
     // Define objects of our <code>ComputeIntensity</code> class and a DataOut
     // object:
index 99267758d8b64e88b5d53900412a2cfcd9d5d5fe..9f3f6f42d6597947fd1ea6826dc7e59207c057f0 100644 (file)
@@ -804,7 +804,6 @@ namespace Step37
   void LaplaceProblem<dim>::setup_system ()
   {
     Timer time;
-    time.start ();
     setup_time = 0;
 
     system_matrix.clear();
index 7696d284b35da780747ce46eb37c5760e01280f5..8aa7bdbec81f76119f41c2815cfb064a4b056303 100644 (file)
@@ -84,8 +84,7 @@ struct CPUClock
  * as well as the total time elapsed over all laps. Here is an example:
  *
  * @code
- *   Timer timer;
- *   timer.start();
+ *   Timer timer; // creating a timer also starts it
  *
  *   // do some complicated computations here
  *   // ...
@@ -102,7 +101,10 @@ struct CPUClock
  * Alternatively, you can also restart the timer instead of resetting it. The
  * times between successive calls to start() and stop() (i.e., the laps) will
  * then be accumulated. The usage of this class is also explained in the
- * step-28, step-29 and step-30 tutorial programs.
+ * step-28 tutorial program.
+ *
+ * @note The TimerOutput (combined with TimerOutput::Scope) class provide a
+ * convenient way to time multiple named sections and summarize the output.
  *
  * @note Implementation of this class is system dependent. In particular, CPU
  * times are accumulated from summing across all threads and will usually
@@ -540,8 +542,8 @@ private:
  *                      TimerOutput::wall_times);
  * @endcode
  * Here, <code>pcout</code> is an object of type ConditionalOStream that makes
- * sure that we only generate output on a single processor. See the step-32
- * and step-40 tutorial programs for this kind of usage of this class.
+ * sure that we only generate output on a single processor. See the step-32,
+ * step-40, and step-42 tutorial programs for this kind of usage of this class.
  *
  * @ingroup utilities
  * @author M. Kronbichler, 2009.

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.