]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Convert a few places where we can now use Utilities::MPI::sum/max.
authorbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Mon, 26 Sep 2011 18:50:03 +0000 (18:50 +0000)
committerbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Mon, 26 Sep 2011 18:50:03 +0000 (18:50 +0000)
git-svn-id: https://svn.dealii.org/trunk@24435 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/include/deal.II/base/timer.h
deal.II/include/deal.II/base/utilities.h
deal.II/source/base/timer.cc
deal.II/source/base/utilities.cc
deal.II/source/dofs/dof_handler_policy.cc
deal.II/source/dofs/dof_tools.cc
deal.II/source/grid/grid_tools.cc

index c17a47b787330ed96a846f3d7dbbf9eaede5dbb8..d06546eef152c97ef37f99fb8187fe6d69d5dc1c 100644 (file)
@@ -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.
index f6e48b48fae15a0a0f9cf576260b8bb14814f083..3a3677197bba06a5784e454018a69c906a4ed64f 100644 (file)
@@ -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;
index 5b3b109b95dbabf3260205ce3a4313fa13e340a8..c10a3792422b90f36141633514f5e9195c7aec87 100644 (file)
@@ -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 &section_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
index 4c105a0c2132d599bebbd0949e7d5748c4953780..7174b321205cc1e9b37d2a67d5364e44b00f1975 100644 (file)
@@ -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);
index ed5c2ea32a1f9d093a507f9f9efca9002de3e595..1d03e7f2a594bb2fb27c463a3c95496c9ae2c7a1 100644 (file)
@@ -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
index 637bb7467c432c40813c89b2cc30b79c43a18bfe..de0e400b78ff6a00ce4f3027f940fa31fcf4a562 100644 (file)
@@ -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
   }
 
index 31fd6bfa7a1bd3b448b730d25c8a951ae71d9943..1cfd13be6577af965ffc4dc0739bec96edb6840b 100644 (file)
@@ -187,9 +187,7 @@ namespace GridTools
 #ifdef DEAL_II_COMPILER_SUPPORTS_MPI
     if (const parallel::distributed::Triangulation<dim,spacedim>* p_tria
        = dynamic_cast<const parallel::distributed::Triangulation<dim,spacedim>*>(&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

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.