]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Fix a crash in TimerOutput when MPI hasn't been initialized.
authorbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Tue, 18 Sep 2012 13:08:41 +0000 (13:08 +0000)
committerbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Tue, 18 Sep 2012 13:08:41 +0000 (13:08 +0000)
git-svn-id: https://svn.dealii.org/trunk@26473 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/doc/news/changes.h
deal.II/source/base/timer.cc
tests/base/timer_02.cc
tests/base/timer_02/cmp/generic

index 7ed9f6cc97b09b93a949f81c1d5fea69e522b636..3f6220907776a5224f60743aa62f9b8585a108fc 100644 (file)
@@ -53,6 +53,14 @@ DoFHandler, in particular removal of specializations.
 <h3>Specific improvements</h3>
 
 <ol>
+<li> Fixed: One can compile deal.II with MPI support but run programs
+that aren't intended to use parallel communications and that, in fact,
+do not call <code>MPI_Init</code> at all. They are nevertheless supposed
+to work but previously the TimerOutput would crash under these conditions.
+This is now fixed.
+<br>
+(Timo Heister, Wolfgang Bangerth, 2012/09/18)
+
 <li> Fixed: If you pipe content into the deallog object and there
 is no end-line or flush after this content, and if a file stream
 is associated to this object, and if that happens at the end of
index 86ad311fb0af6a2c5e792fc961374c0f3f98e36d..f6a13b2f57c420d40113992cdc69d1818bcbe420 100644 (file)
@@ -94,11 +94,11 @@ namespace
     {
       FILETIME cpuTime, sysTime, createTime, exitTime;
       if (GetProcessTimes(GetCurrentProcess(),  &createTime,
-                         &exitTime, &sysTime, &cpuTime))
-       {
-         return (double)(((unsigned long long)cpuTime.dwHighDateTime << 32)
-                         | cpuTime.dwLowDateTime) / 1e6;
-       }
+                          &exitTime, &sysTime, &cpuTime))
+        {
+          return (double)(((unsigned long long)cpuTime.dwHighDateTime << 32)
+                          | cpuTime.dwLowDateTime) / 1e6;
+        }
       return 0;
     }
   }
@@ -239,9 +239,9 @@ double Timer::wall_time () const
       struct timeval wall_timer;
       gettimeofday(&wall_timer, NULL);
       return (wall_timer.tv_sec
-             + 1.e-6 * wall_timer.tv_usec
-             - start_wall_time
-             + cumulative_wall_time);
+              + 1.e-6 * wall_timer.tv_usec
+              - start_wall_time
+              + cumulative_wall_time);
 #endif
     }
   else
@@ -394,7 +394,11 @@ TimerOutput::leave_subsection (const std::string &section_name)
                                        // 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);
+    += (Utilities::System::job_supports_mpi()
+        ?
+        Utilities::MPI::sum (cpu_time, mpi_communicator)
+        :
+        cpu_time);
 
                                    // in case we have to print out
                                    // something, do that here...
@@ -438,8 +442,12 @@ TimerOutput::print_summary () const
                                    // in case we want to write CPU times
   if (output_type != wall_times)
     {
-      double total_cpu_time = Utilities::MPI::sum (timer_all(),
-                                                   mpi_communicator);
+      double total_cpu_time = (Utilities::System::job_supports_mpi()
+                               ?
+                              Utilities::MPI::sum (timer_all(),
+                                                   mpi_communicator)
+                              :
+                              timer_all());
 
                                        // check that the sum of all times is
                                        // less or equal than the total
index 7648a2f9ec2fbb3c8678e2edc8eb98b39512b517..d10d2091c650086f14be41761e35af98d25f76fc 100644 (file)
@@ -1,8 +1,8 @@
 //----------------------------  timer.cc  ---------------------------
 //    $Id: timer.cc 23710 2011-05-17 04:50:10Z bangerth $
-//    Version: $Name$ 
+//    Version: $Name$
 //
-//    Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010 by the deal.II authors
+//    Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, 2012 by the deal.II authors
 //
 //    This file is subject to QPL and may not be  distributed
 //    without copyright and license information. Please refer
 
 int main ()
 {
-  std::ofstream logfile("timer/output");
+  std::ofstream logfile("timer_02/output");
   deallog.attach(logfile);
   deallog.depth_console(0);
   deallog.threshold_double(1.e-10);
 
-  TimerOutput t(std::cout, TimerOutput::summary, TimerOutput::cpu_times);
+  TimerOutput t(logfile, TimerOutput::summary, TimerOutput::cpu_times);
 
   t.enter_subsection("hi");
   t.leave_subsection("hi");
index 5f42bb230f11ca6753755403100d254e31356269..9c78100595c1fc58be09028650b745ffa9421f0d 100644 (file)
@@ -1,5 +1,22 @@
 
-DEAL::OK
-DEAL::OK
-DEAL::OK
-DEAL::OK
+
+
++---------------------------------------------+------------+------------+
+| Total CPU time elapsed since start          |      0.00s |            |
+|                                             |            |            |
+| Section                         | no. calls |  CPU time  | % of total |
++---------------------------------+-----------+------------+------------+
+| hi                              |         1 |      0.00s |      -nan% |
++---------------------------------+-----------+------------+------------+
+
+DEAL::ok
+
+
++---------------------------------------------+------------+------------+
+| Total CPU time elapsed since start          |      0.00s |            |
+|                                             |            |            |
+| Section                         | no. calls |  CPU time  | % of total |
++---------------------------------+-----------+------------+------------+
+| hi                              |         1 |      0.00s |      -nan% |
++---------------------------------+-----------+------------+------------+
+

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.