From 1b27ce1ea2227e170aab8c2ec3c94745bb9b882f Mon Sep 17 00:00:00 2001 From: Martin Kronbichler Date: Thu, 20 Nov 2014 15:47:24 +0100 Subject: [PATCH] Third attempt to fix uninitialized variable in MPI::MinMaxAvg --- include/deal.II/base/mpi.h | 4 ++-- source/base/mpi.cc | 18 +++++------------- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/include/deal.II/base/mpi.h b/include/deal.II/base/mpi.h index 75a5667f2f..da8b667f4d 100644 --- a/include/deal.II/base/mpi.h +++ b/include/deal.II/base/mpi.h @@ -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; diff --git a/source/base/mpi.cc b/source/base/mpi.cc index 3fc0077a91..c1bce6890e 100644 --- a/source/base/mpi.cc +++ b/source/base/mpi.cc @@ -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::max(), + -std::numeric_limits::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::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) -- 2.39.5