From: bangerth Date: Mon, 26 Sep 2011 18:50:03 +0000 (+0000) Subject: Convert a few places where we can now use Utilities::MPI::sum/max. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e7f554413f71d7ab7521474cc5964163217ce2d4;p=dealii-svn.git Convert a few places where we can now use Utilities::MPI::sum/max. git-svn-id: https://svn.dealii.org/trunk@24435 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/include/deal.II/base/timer.h b/deal.II/include/deal.II/base/timer.h index c17a47b787..d06546eef1 100644 --- a/deal.II/include/deal.II/base/timer.h +++ b/deal.II/include/deal.II/base/timer.h @@ -1,7 +1,7 @@ //--------------------------------------------------------------------------- // $Id$ // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009, 2010 by the deal.II authors +// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009, 2010, 2011 by the deal.II authors // // This file is subject to QPL and may not be distributed // without copyright and license information. Please refer @@ -110,7 +110,7 @@ class Timer * information. Filled after calling * stop(). */ - const Utilities::System::MinMaxAvg & get_data() const; + const Utilities::MPI::MinMaxAvg & get_data() const; /** * Prints the data to the given stream. @@ -227,13 +227,13 @@ class Timer */ bool running; -#ifdef DEAL_II_COMPILER_SUPPORTS_MPI /** * Store whether the timer is presently * running. */ MPI_Comm mpi_communicator; +#ifdef DEAL_II_COMPILER_SUPPORTS_MPI /** * Store whether the wall time is * synchronized between machines. diff --git a/deal.II/include/deal.II/base/utilities.h b/deal.II/include/deal.II/base/utilities.h index f6e48b48fa..3a3677197b 100644 --- a/deal.II/include/deal.II/base/utilities.h +++ b/deal.II/include/deal.II/base/utilities.h @@ -1012,12 +1012,24 @@ namespace Utilities } + inline MPI_Datatype mpi_type_id (const long int *) + { + return MPI_LONG; + } + + inline MPI_Datatype mpi_type_id (const unsigned int *) { return MPI_UNSIGNED; } + inline MPI_Datatype mpi_type_id (const unsigned long int *) + { + return MPI_UNSIGNED_LONG; + } + + inline MPI_Datatype mpi_type_id (const float *) { return MPI_FLOAT; diff --git a/deal.II/source/base/timer.cc b/deal.II/source/base/timer.cc index 5b3b109b95..c10a379242 100644 --- a/deal.II/source/base/timer.cc +++ b/deal.II/source/base/timer.cc @@ -156,46 +156,12 @@ double Timer::operator() () const // in case we just want to have the time // of a single thread, since then the // communicator is MPI_COMM_SELF -#ifdef DEAL_II_COMPILER_SUPPORTS_MPI - double local_time = dtime - start_time + dtime_children - - start_time_children + cumulative_time; - - int mpiInitialized; - MPI_Initialized(&mpiInitialized); - - if ( mpiInitialized ) - { - double global_time = 0.; - MPI_Allreduce (&local_time, &global_time, 1, MPI_DOUBLE, MPI_SUM, - mpi_communicator); - return global_time; - } - else - return local_time; -#else - return dtime - start_time + dtime_children - start_time_children + cumulative_time; -#endif + return Utilities::MPI::sum (dtime - start_time + dtime_children + - start_time_children + cumulative_time, + mpi_communicator); } else -#ifdef DEAL_II_COMPILER_SUPPORTS_MPI - { - int mpiInitialized; - MPI_Initialized(&mpiInitialized); - - if ( mpiInitialized ) - { - double local_time = cumulative_time; - double global_time = 0.; - MPI_Allreduce (&local_time, &global_time, 1, MPI_DOUBLE, MPI_SUM, - mpi_communicator); - return global_time; - } - else - return cumulative_time; - } -#else - return cumulative_time; -#endif + return Utilities::MPI::sum (cumulative_time, mpi_communicator); } @@ -358,25 +324,8 @@ TimerOutput::leave_subsection (const std::string §ion_name) // itself, but we didn't initialize // the Timers here according to that double cpu_time = sections[actual_section_name].timer(); - { - - // On MPI, sum up all the local CPU - // times. -#ifdef DEAL_II_COMPILER_SUPPORTS_MPI - double total_cpu_time = 0.; - int mpiInitialized; - MPI_Initialized(&mpiInitialized); - - if( mpiInitialized ) - { - MPI_Allreduce (&cpu_time, &total_cpu_time, 1, MPI_DOUBLE, MPI_SUM, - mpi_communicator); - cpu_time = total_cpu_time; - } -#endif - sections[actual_section_name].total_cpu_time += cpu_time; - } - + sections[actual_section_name].total_cpu_time + += Utilities::MPI::sum (cpu_time, mpi_communicator); // in case we have to print out // something, do that here... @@ -419,25 +368,8 @@ TimerOutput::print_summary () const // in case we want to write CPU times if (output_type != wall_times) { - double total_cpu_time; - -#ifdef DEAL_II_COMPILER_SUPPORTS_MPI - { - double my_cpu_time = timer_all(); - int mpiInitialized; - MPI_Initialized(&mpiInitialized); - - if( mpiInitialized ) - { - MPI_Allreduce (&my_cpu_time, &total_cpu_time, 1, MPI_DOUBLE, - MPI_SUM, mpi_communicator); - } - else - total_cpu_time = my_cpu_time; - } -#else - total_cpu_time = timer_all(); -#endif + double total_cpu_time = Utilities::MPI::sum (timer_all(), + mpi_communicator); // check that the sum of all times is // less or equal than the total diff --git a/deal.II/source/base/utilities.cc b/deal.II/source/base/utilities.cc index 4c105a0c21..7174b32120 100644 --- a/deal.II/source/base/utilities.cc +++ b/deal.II/source/base/utilities.cc @@ -520,11 +520,8 @@ namespace Utilities // communicate the maximal // number of destinations they // have - unsigned int my_n_destinations = destinations.size(); - unsigned int max_n_destinations = 0; - - MPI_Allreduce (&my_n_destinations, &max_n_destinations, 1, MPI_UNSIGNED, - MPI_MAX, mpi_comm); + const unsigned int max_n_destinations + = Utilities::MPI::max (destinations.size(), mpi_comm); // now that we know the number // of data packets every @@ -638,7 +635,7 @@ namespace Utilities AssertThrow(ierr == MPI_SUCCESS, ExcInternalError()); ierr = MPI_Type_commit(&type); - ierr = MPI_Allreduce ( &in, &result, 1, type, op, mpi_communicator ); + ierr = MPI_Allreduce (&in, &result, 1, type, op, mpi_communicator); AssertThrow(ierr == MPI_SUCCESS, ExcInternalError()); ierr = MPI_Type_free (&type); diff --git a/deal.II/source/dofs/dof_handler_policy.cc b/deal.II/source/dofs/dof_handler_policy.cc index ed5c2ea32a..1d03e7f2a5 100644 --- a/deal.II/source/dofs/dof_handler_policy.cc +++ b/deal.II/source/dofs/dof_handler_policy.cc @@ -1505,9 +1505,8 @@ namespace internal unsigned int my_size = oss_str.size(); // determine maximum size of IndexSet - unsigned int max_size; - - MPI_Allreduce(&my_size, &max_size, 1, MPI_UNSIGNED, MPI_MAX, tr->get_communicator()); + const unsigned int max_size + = Utilities::MPI::max (my_size, tr->get_communicator()); // as we are reading past the end, we // need to increase the size of the diff --git a/deal.II/source/dofs/dof_tools.cc b/deal.II/source/dofs/dof_tools.cc index 637bb7467c..de0e400b78 100644 --- a/deal.II/source/dofs/dof_tools.cc +++ b/deal.II/source/dofs/dof_tools.cc @@ -4653,8 +4653,7 @@ namespace DoFTools ExcInternalError()); // reduce information from all CPUs -#ifdef DEAL_II_USE_P4EST -#ifdef DEAL_II_COMPILER_SUPPORTS_MPI +#if defined(DEAL_II_USE_P4EST) && defined(DEAL_II_COMPILER_SUPPORTS_MPI) const unsigned int dim = DH::dimension; const unsigned int spacedim = DH::space_dimension; @@ -4667,7 +4666,6 @@ namespace DoFTools MPI_Allreduce ( &local_dof_count[0], &dofs_per_component[0], n_target_components, MPI_UNSIGNED, MPI_SUM, tria->get_communicator()); } -#endif #endif } diff --git a/deal.II/source/grid/grid_tools.cc b/deal.II/source/grid/grid_tools.cc index 31fd6bfa7a..1cfd13be65 100644 --- a/deal.II/source/grid/grid_tools.cc +++ b/deal.II/source/grid/grid_tools.cc @@ -187,9 +187,7 @@ namespace GridTools #ifdef DEAL_II_COMPILER_SUPPORTS_MPI if (const parallel::distributed::Triangulation* p_tria = dynamic_cast*>(&triangulation)) - MPI_Allreduce (&local_volume, &global_volume, 1, MPI_DOUBLE, - MPI_SUM, - p_tria->get_communicator()); + global_volume = Utilities::MPI::sum (local_volume, p_tria->get_communicator()); else global_volume = local_volume; #else