]> https://gitweb.dealii.org/ - dealii.git/commitdiff
fix cpu time collection on MPI system for class TimerOutput. 799/head
authorLei Qiao <qiaol618@gmail.com>
Tue, 14 Apr 2015 22:16:14 +0000 (17:16 -0500)
committerLei Qiao <qiaol618@gmail.com>
Mon, 20 Apr 2015 00:00:04 +0000 (19:00 -0500)
doc/news/changes.h
source/base/timer.cc

index ce4f8efc1a929f894ca5554f02a6fbdb39f58b6c..bbe1d8dff5d700dabc321cc36fb0ddf34780039d 100644 (file)
@@ -460,6 +460,12 @@ inconvenience this causes.
 <h3>Specific improvements</h3>
 
 <ol>
+  <li> Fixed: The TimerOutput class reported abnormally large cpu time when run
+  with more than one process with MPI. Now this is fixed.
+  <br>
+  (Lei Qiao, 2015/04/19)
+  </li>
+
   <li> New: TrilinosWrappers::BlockSparseMatrix now has member functions
   TrilinosWrappers::BlockSparseMatrix::domain_paritioner() and
   TrilinosWrappers::BlockSparseMatrix::range_partitioner() that return a
@@ -468,6 +474,7 @@ inconvenience this causes.
   (Matthias Maier, 2015/04/08)
 
   </li>
+
   <li> Fixed: The class SymmetricTensor<2,dim> is now usable also for dim>3.
   <br>
   (Martin Kronbichler, 2015/04/14)
index 821e130b4a9116ef4a99d4addb45285b65649eb3..f5680f43ffcfb6bfd8b50ddb7fd0825921eb75d1 100644 (file)
@@ -356,7 +356,10 @@ TimerOutput::enter_subsection (const std::string &section_name)
           // create a new timer for this section. the second argument
           // will ensure that we have an MPI barrier before starting
           // and stopping a timer, and this ensures that we get the
-          // maximum run time for this section over all processors
+          // maximum run time for this section over all processors.
+          // The mpi_communicator from TimerOutput is passed to the
+          // Timer here, so this Timer will collect timing information
+          // among all processes inside mpi_communicator.
           sections[section_name].timer = Timer(mpi_communicator, true);
         }
 #endif
@@ -403,12 +406,12 @@ TimerOutput::leave_subsection (const std::string &section_name)
   sections[actual_section_name].total_wall_time
   += sections[actual_section_name].timer.wall_time();
 
-  // get cpu time. on MPI systems, add the local contributions. we
-  // could do that also in the Timer class itself, but we didn't
-  // initialize the Timers here according to that
-  double cpu_time = sections[actual_section_name].timer();
-  sections[actual_section_name].total_cpu_time
-  += Utilities::MPI::sum (cpu_time, mpi_communicator);
+  // Get cpu time. On MPI systems, if constructed with an mpi_communicator
+  // like MPI_COMM_WORLD, then the Timer will sum up the CPU time between
+  // processors among the provided mpi_communicator. Therefore, no
+  // communication is needed here.
+  const double cpu_time = sections[actual_section_name].timer();
+  sections[actual_section_name].total_cpu_time += cpu_time;
 
   // in case we have to print out something, do that here...
   if ((output_frequency == every_call || output_frequency == every_call_and_summary)
@@ -464,7 +467,8 @@ TimerOutput::print_summary () const
            i = sections.begin(); i!=sections.end(); ++i)
         check_time += i->second.total_cpu_time;
 
-      if (check_time > total_cpu_time)
+      const double time_gap = check_time-total_cpu_time;
+      if (time_gap > 0.0)
         total_cpu_time = check_time;
 
       // generate a nice table
@@ -512,9 +516,10 @@ TimerOutput::print_summary () const
                  << "------------+------------+\n"
                  << std::endl;
 
-      if (check_time > total_cpu_time)
+      if (time_gap > 0.0)
         out_stream << std::endl
-                   << "Note: The sum of counted times is larger than the total time.\n"
+                   << "Note: The sum of counted times is " << time_gap
+                   << " seconds larger than the total time.\n"
                    << "(Timer function may have introduced too much overhead, or different\n"
                    << "section timers may have run at the same time.)" << 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.