From: bangerth Date: Wed, 28 Sep 2011 02:36:28 +0000 (+0000) Subject: Make the Timer class work even if we have configured for MPI but haven't initialized... X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=772633f94a5a846972e8373e9a09a4d10b0f455c;p=dealii-svn.git Make the Timer class work even if we have configured for MPI but haven't initialized the MPI sub-system. git-svn-id: https://svn.dealii.org/trunk@24453 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/source/base/timer.cc b/deal.II/source/base/timer.cc index c10a379242..d366f954dc 100644 --- a/deal.II/source/base/timer.cc +++ b/deal.II/source/base/timer.cc @@ -118,8 +118,7 @@ double Timer::stop () double time = wall_timer.tv_sec + 1.e-6 * wall_timer.tv_usec - start_wall_time; -#ifdef DEAL_II_COMPILER_SUPPORTS_MPI - if (sync_wall_time) + if (sync_wall_time && Utilities::System::job_supports_mpi()) { this->mpi_data = Utilities::MPI::min_max_avg (time, mpi_communicator); @@ -128,9 +127,6 @@ double Timer::stop () } else cumulative_wall_time += time; -#else - cumulative_wall_time += time; -#endif } return cumulative_time; } @@ -150,18 +146,27 @@ double Timer::operator() () const const double dtime_children = usage_children.ru_utime.tv_sec + 1.e-6 * usage_children.ru_utime.tv_usec; + const double running_time = dtime - start_time + dtime_children + - start_time_children + cumulative_time; + + if (Utilities::System::job_supports_mpi()) // in case of MPI, need to get the time // passed by summing the time over all // processes in the network. works also // in case we just want to have the time // of a single thread, since then the // communicator is MPI_COMM_SELF - return Utilities::MPI::sum (dtime - start_time + dtime_children - - start_time_children + cumulative_time, - mpi_communicator); + return Utilities::MPI::sum (running_time, mpi_communicator); + else + return running_time; } else - return Utilities::MPI::sum (cumulative_time, mpi_communicator); + { + if (Utilities::System::job_supports_mpi()) + return Utilities::MPI::sum (cumulative_time, mpi_communicator); + else + return cumulative_time; + } }