]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Third attempt to fix uninitialized variable in MPI::MinMaxAvg 259/head
authorMartin Kronbichler <kronbichler@lnm.mw.tum.de>
Thu, 20 Nov 2014 14:47:24 +0000 (15:47 +0100)
committerMartin Kronbichler <kronbichler@lnm.mw.tum.de>
Thu, 20 Nov 2014 17:06:09 +0000 (18:06 +0100)
include/deal.II/base/mpi.h
source/base/mpi.cc

index 75a5667f2f3a1b022eede5d819ede937fe564e31..da8b667f4dbcf5e47d661883a6db8f65da1ef2f4 100644 (file)
@@ -216,8 +216,8 @@ namespace Utilities
      */
     struct MinMaxAvg
     {
-      MinMaxAvg();
-
+      // Note: We assume a POD property of this struct in the MPI calls in
+      // min_max_avg
       double sum;
       double min;
       double max;
index 3fc0077a919cc348dff053293b209f4771958840..c1bce6890e1229b67bee6771d69b73d6027f82b0 100644 (file)
@@ -230,7 +230,11 @@ namespace Utilities
     min_max_avg(const double my_value,
                 const MPI_Comm &mpi_communicator)
     {
-      MinMaxAvg result;
+      // To avoid uninitialized values on some MPI implementations, provide
+      // result with a default value already...
+      MinMaxAvg result = { 0., std::numeric_limits<double>::max(),
+                           -std::numeric_limits<double>::max(), 0, 0, 0.
+                         };
 
       const unsigned int my_id
         = dealii::Utilities::MPI::this_mpi_process(mpi_communicator);
@@ -310,18 +314,6 @@ namespace Utilities
 
 
 
-    MinMaxAvg::MinMaxAvg ()
-      :
-      sum (0.),
-      min (std::numeric_limits<double>::max()),
-      max (-min),
-      min_index (0),
-      max_index (0),
-      avg (0)
-    {}
-
-
-
     MPI_InitFinalize::MPI_InitFinalize (int    &argc,
                                         char ** &argv,
                                         const unsigned int max_num_threads)

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.