From: bangerth Date: Tue, 18 Sep 2012 13:08:41 +0000 (+0000) Subject: Fix a crash in TimerOutput when MPI hasn't been initialized. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9c60db8b78b19a96a94573009bb697433e0b8ba3;p=dealii-svn.git Fix a crash in TimerOutput when MPI hasn't been initialized. git-svn-id: https://svn.dealii.org/trunk@26473 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/doc/news/changes.h b/deal.II/doc/news/changes.h index 7ed9f6cc97..3f62209077 100644 --- a/deal.II/doc/news/changes.h +++ b/deal.II/doc/news/changes.h @@ -53,6 +53,14 @@ DoFHandler, in particular removal of specializations.

Specific improvements

    +
  1. 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 MPI_Init at all. They are nevertheless supposed +to work but previously the TimerOutput would crash under these conditions. +This is now fixed. +
    +(Timo Heister, Wolfgang Bangerth, 2012/09/18) +
  2. 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 diff --git a/deal.II/source/base/timer.cc b/deal.II/source/base/timer.cc index 86ad311fb0..f6a13b2f57 100644 --- a/deal.II/source/base/timer.cc +++ b/deal.II/source/base/timer.cc @@ -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 §ion_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 diff --git a/tests/base/timer_02.cc b/tests/base/timer_02.cc index 7648a2f9ec..d10d2091c6 100644 --- a/tests/base/timer_02.cc +++ b/tests/base/timer_02.cc @@ -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 @@ -26,12 +26,12 @@ 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"); diff --git a/tests/base/timer_02/cmp/generic b/tests/base/timer_02/cmp/generic index 5f42bb230f..9c78100595 100644 --- a/tests/base/timer_02/cmp/generic +++ b/tests/base/timer_02/cmp/generic @@ -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% | ++---------------------------------+-----------+------------+------------+ +