]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add a simple output option.
authorMartin Kronbichler <kronbichler@lnm.mw.tum.de>
Sat, 8 Aug 2009 13:03:00 +0000 (13:03 +0000)
committerMartin Kronbichler <kronbichler@lnm.mw.tum.de>
Sat, 8 Aug 2009 13:03:00 +0000 (13:03 +0000)
git-svn-id: https://svn.dealii.org/trunk@19213 0785d39b-7218-0410-832d-ea1e28bc413d

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

index 172ba51df41a60c241c6e2497ccad7b68917163b..6dd3f05bad898d2625b845a5ebe88e28a781c6af 100644 (file)
@@ -364,6 +364,30 @@ class TimerOutput
                                      */
     void print_summary () const;
 
+                                    /**
+                                     * By calling this function, all output
+                                     * can be disabled. This function
+                                     * together with enable_output() can be
+                                     * useful if one wants to control the
+                                     * output in a flexible way without
+                                     * putting a lot of <tt>if</tt> clauses
+                                     * in the program.
+                                     */
+    void disable_output ();
+
+                                    /**
+                                     * This function re-enables output of
+                                     * this class if it was previously
+                                     * disabled with disable_output(). This
+                                     * function together with
+                                     * disable_output() can be useful if
+                                     * one wants to control the output in a
+                                     * flexible way without putting a lot
+                                     * of <tt>if</tt> clauses in the
+                                     * program.
+                                     */
+    void enable_output ();
+
   private:
                                     /**
                                      * A timer object for the overall
@@ -398,6 +422,13 @@ class TimerOutput
                                      */
     ConditionalOStream out_stream;
 
+                                    /**
+                                     * A boolean variable that sets whether
+                                     * output of this class is currently on
+                                     * or off.
+                                     */
+    bool output_is_enabled;
+
                                     /**
                                      * A list of the sections that
                                      * have been entered and not
@@ -424,7 +455,6 @@ class TimerOutput
                                      * class gives reasonable results even
                                      * when used with several threads.
                                      */
-
     Threads::ThreadMutex mutex;
 };
 
index 281370c31701c72804f56746bcc61bd7cfd1405c..1fdef24ef0ec08b26d8de8bd0a30a9ff0f0a1c20 100644 (file)
@@ -206,7 +206,8 @@ TimerOutput::TimerOutput (std::ostream &stream,
                           :
                           output_frequency (output_frequency),
                          output_type (output_type),
-                          out_stream (stream, true)
+                          out_stream (stream, true),
+                         output_is_enabled (true)
 #ifdef DEAL_II_COMPILER_SUPPORTS_MPI
                          , mpi_communicator (MPI_COMM_SELF)
 #endif
@@ -220,7 +221,8 @@ TimerOutput::TimerOutput (ConditionalOStream &stream,
                           :
                           output_frequency (output_frequency),
                          output_type (output_type),
-                          out_stream (stream)
+                          out_stream (stream),
+                         output_is_enabled (true)
 #ifdef DEAL_II_COMPILER_SUPPORTS_MPI
                          , mpi_communicator (MPI_COMM_SELF)
 #endif
@@ -236,7 +238,8 @@ TimerOutput::TimerOutput (MPI_Comm      mpi_communicator,
                           :
                           output_frequency (output_frequency),
                          output_type (output_type),
-                          out_stream (stream, true), 
+                          out_stream (stream, true),
+                         output_is_enabled (true), 
                          mpi_communicator (mpi_communicator)
 {}
 
@@ -250,6 +253,7 @@ TimerOutput::TimerOutput (MPI_Comm      mpi_communicator,
                           output_frequency (output_frequency),
                          output_type (output_type),
                           out_stream (stream),
+                         output_is_enabled (true),
                          mpi_communicator (mpi_communicator)
 {}
 
@@ -261,7 +265,7 @@ TimerOutput::~TimerOutput()
   while (active_sections.size() > 0)
     exit_section();
 
-  if (output_frequency != every_call)
+  if (output_frequency != every_call && output_is_enabled == true)
     print_summary();
 }
 
@@ -298,6 +302,9 @@ TimerOutput::enter_section (const std::string &section_name)
 void 
 TimerOutput::exit_section (const std::string &section_name)
 {
+  Assert (active_sections.size() > 0,
+         ExcMessage("Cannot exit any section because none has been entered!"));
+
   Threads::ThreadMutex::ScopedLock lock (mutex);
 
   if (section_name != "")
@@ -347,7 +354,7 @@ TimerOutput::exit_section (const std::string &section_name)
 
                                   // in case we have to print out
                                   // something, do that here...
-  if (output_frequency != summary)
+  if (output_frequency != summary && output_is_enabled == true)
     {
       std::string output_time;
       std::ostringstream cpu;
@@ -532,4 +539,20 @@ TimerOutput::print_summary () const
 }
 
 
+
+void 
+TimerOutput::disable_output ()
+{
+  output_is_enabled = false;
+}
+
+
+
+void
+TimerOutput::enable_output ()
+{
+  output_is_enabled = true;
+}
+
+
 DEAL_II_NAMESPACE_CLOSE

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.