]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Make TimerOutput really thread-safe.
authorkronbichler <kronbichler@0785d39b-7218-0410-832d-ea1e28bc413d>
Fri, 17 Apr 2009 09:50:18 +0000 (09:50 +0000)
committerkronbichler <kronbichler@0785d39b-7218-0410-832d-ea1e28bc413d>
Fri, 17 Apr 2009 09:50:18 +0000 (09:50 +0000)
git-svn-id: https://svn.dealii.org/trunk@18639 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/base/include/base/timer.h
deal.II/base/source/timer.cc

index ada33f40569a2a391c4d07897d20b6a9f2183a7d..ca90e4f76514b21253314f2e5a6056c03f96cace 100644 (file)
@@ -15,6 +15,7 @@
 
 #include <base/config.h>
 #include <base/conditional_ostream.h>
+#include <base/thread_management.h>
 
 #ifdef DEAL_II_COMPILER_SUPPORTS_MPI
 #include <mpi.h>
@@ -370,6 +371,14 @@ class TimerOutput
                                      */
     MPI_Comm            mpi_communicator;
 #endif
+
+                                    /**
+                                     * A lock that makes sure that this
+                                     * class gives reasonable results even
+                                     * when used with several threads.
+                                     */
+
+    Threads::ThreadMutex mutex;
 };
 
 DEAL_II_NAMESPACE_CLOSE
index b442e66345a4bec66481c22a25b0209d4847860d..48d91776a60237ce09351475d2828be42b2e52b1 100644 (file)
@@ -22,8 +22,6 @@
 #include <sys/time.h>
 #include <sys/resource.h>
 
-#include <base/thread_management.h>
-
 
 // on SunOS 4.x, getrusage is stated in the man pages and exists, but
 // is not declared in resource.h. declare it ourselves
@@ -272,8 +270,7 @@ TimerOutput::~TimerOutput()
 void 
 TimerOutput::enter_section (const std::string &section_name)
 {
-  Threads::Mutex mutex;
-  Threads::Mutex::ScopedLock lock (mutex);
+  Threads::ThreadMutex::ScopedLock lock (mutex);
 
   Assert (section_name.empty() == false,
          ExcMessage ("Section string is empty."));
@@ -301,8 +298,7 @@ TimerOutput::enter_section (const std::string &section_name)
 void 
 TimerOutput::exit_section (const std::string &section_name)
 {
-  Threads::Mutex mutex;
-  Threads::Mutex::ScopedLock lock (mutex);
+  Threads::ThreadMutex::ScopedLock lock (mutex);
 
   if (section_name != "")
     {
@@ -430,7 +426,7 @@ TimerOutput::print_summary ()
       std::cout.width(10);
       std::cout.precision(3);
       out_stream << "  CPU time "  << " | % of total |\n";
-      out_stream << "+---------------------------------------------+------------"
+      out_stream << "+---------------------------------+-----------+------------"
                 << "+------------+";
       for (std::map<std::string, Section>::const_iterator
             i = sections.begin(); i!=sections.end(); ++i)
@@ -455,7 +451,7 @@ TimerOutput::print_summary ()
          out_stream << i->second.total_cpu_time/total_cpu_time * 100 << "% |";
        }
       out_stream << std::endl
-                << "+---------------------------------------------+"
+                << "+---------------------------------+-----------+"
                 << "------------+------------+\n"
                 << std::endl;
 
@@ -488,7 +484,7 @@ TimerOutput::print_summary ()
       out_stream << "\n\n"
                 << "+---------------------------------------------+------------"
                 << "+------------+\n"
-                << "| Total wallclock time elapsed from start     |";
+                << "| Total wallclock time elapsed since start    |";
       std::cout.width(10);
       std::cout.precision(3);
       out_stream << total_wall_time << "s |            |\n";
@@ -498,7 +494,7 @@ TimerOutput::print_summary ()
       std::cout.width(10);
       std::cout.precision(3);
       out_stream << "  wall time | % of total |\n";
-      out_stream << "+---------------------------------------------+------------"
+      out_stream << "+---------------------------------+-----------+------------"
                 << "+------------+";
       for (std::map<std::string, Section>::const_iterator
             i = sections.begin(); i!=sections.end(); ++i)
@@ -523,7 +519,7 @@ TimerOutput::print_summary ()
          out_stream << i->second.total_wall_time/total_wall_time * 100 << "% |";
        }
       out_stream << std::endl
-                << "+---------------------------------------------+"
+                << "+---------------------------------+-----------+"
                 << "------------+------------+\n"
                 << std::endl;
 

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.