]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Exit the given subsection in TimerOutput::Scope. 5087/head
authorDavid Wells <wellsd2@rpi.edu>
Thu, 14 Sep 2017 18:24:29 +0000 (14:24 -0400)
committerDavid Wells <wellsd2@rpi.edu>
Thu, 14 Sep 2017 18:35:49 +0000 (14:35 -0400)
The current implementation doesn't work in a multithreaded context.
Consider the following sequence of events:

Thread 1: start and create Scope scope_1(timer_output, "1")
Thread 2: start and create Scope scope_2(timer_output, "2")
Thread 1: call ~scope_1() and join
Thread 2: call ~scope_2() and join

The current implementation of ~Scope() exits the most recent subsection,
so when ~scope_1() is called we leave subsection "2" and when ~scope_2()
is called we leave subsection "1". We can get around this by always
explicitly exiting the subsection in which we started.

doc/news/changes/minor/20170914DavidWells [new file with mode: 0644]
include/deal.II/base/timer.h

diff --git a/doc/news/changes/minor/20170914DavidWells b/doc/news/changes/minor/20170914DavidWells
new file mode 100644 (file)
index 0000000..cec71dc
--- /dev/null
@@ -0,0 +1,7 @@
+Fixed: The destructor of TimerOutput::Scope will now always exit the subsection
+it entered in its constructor, instead of just exiting the last subsection that
+was created in the provided TimerOutput object. This fixes timing output
+measurements for multithreaded applications and cases where subsections are
+nested.
+<br>
+(David Wells, 2017/09/14)
index 786c5077841bd7e0dd0d14e35331dd5a110d7301..77a532fb239d75fc0f312cc8a7040e2d111083e3 100644 (file)
@@ -586,6 +586,12 @@ public:
      * Reference to the TimerOutput object
      */
     dealii::TimerOutput &timer;
+
+    /**
+     * Name of the section we need to exit
+     */
+    const std::string section_name;
+
     /**
      * Do we still need to exit the section we are in?
      */
@@ -981,9 +987,12 @@ TimerOutput::exit_section (const std::string &section_name)
 }
 
 inline
-TimerOutput::Scope::Scope(dealii::TimerOutput &timer_, const std::string &section_name)
+TimerOutput::Scope::Scope(dealii::TimerOutput &timer_,
+                          const std::string &section_name_)
   :
-  timer(timer_), in(true)
+  timer(timer_),
+  section_name(section_name_),
+  in(true)
 {
   timer.enter_section(section_name);
 }
@@ -1006,7 +1015,7 @@ TimerOutput::Scope::stop()
   if (!in) return;
   in=false;
 
-  timer.exit_section();
+  timer.exit_section(section_name);
 }
 
 

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.