From 8fa5afd66c780f74a93d002da11abf9c7975e9e7 Mon Sep 17 00:00:00 2001 From: Norbert Podhorszki Date: Fri, 2 Oct 2020 14:36:37 -0400 Subject: [PATCH] Fix sign errors in handling integer parameters --- .../toolkit/aggregator/mpi/MPIAggregator.cpp | 4 +- source/adios2/toolkit/format/bp/BPBase.cpp | 51 +++++++++++-------- 2 files changed, 32 insertions(+), 23 deletions(-) diff --git a/source/adios2/toolkit/aggregator/mpi/MPIAggregator.cpp b/source/adios2/toolkit/aggregator/mpi/MPIAggregator.cpp index 5d00e9741b..7df033f849 100644 --- a/source/adios2/toolkit/aggregator/mpi/MPIAggregator.cpp +++ b/source/adios2/toolkit/aggregator/mpi/MPIAggregator.cpp @@ -130,9 +130,9 @@ void MPIAggregator::InitCommOnePerNode(helper::Comm const &parentComm) /* Identify parent rank of aggregator process within each group */ if (!m_Rank) { - m_ConsumerRank = static_cast(parentComm.Rank()); + m_ConsumerRank = parentComm.Rank(); } - m_ConsumerRank = m_Comm.BroadcastValue(m_ConsumerRank, 0); + m_ConsumerRank = m_Comm.BroadcastValue(m_ConsumerRank, 0); } void MPIAggregator::HandshakeRank(const int rank) diff --git a/source/adios2/toolkit/format/bp/BPBase.cpp b/source/adios2/toolkit/format/bp/BPBase.cpp index b586186ac5..b4788e725c 100644 --- a/source/adios2/toolkit/format/bp/BPBase.cpp +++ b/source/adios2/toolkit/format/bp/BPBase.cpp @@ -155,35 +155,44 @@ void BPBase::Init(const Params ¶meters, const std::string hint, } else if (key == "substreams" || key == "numaggregators") { - parsedParameters.NumAggregators = - static_cast(helper::StringTo( - value, " in Parameter key=SubStreams " + hint)); + int n = static_cast(helper::StringTo( + value, " in Parameter key=" + key + " " + hint)); - if (parsedParameters.NumAggregators > m_SizeMPI) + if (n < 0) { - parsedParameters.NumAggregators = m_SizeMPI; + n = 0; } + if (n > m_SizeMPI) + { + n = m_SizeMPI; + } + parsedParameters.NumAggregators = n; } else if (key == "aggregatorratio") { - unsigned int ratio = static_cast(helper::StringTo( + int ratio = static_cast(helper::StringTo( value, " in Parameter key=AggregatorRatio " + hint)); - parsedParameters.NumAggregators = m_SizeMPI / ratio; - if ((m_SizeMPI % ratio)) - { - throw std::invalid_argument( - "ERROR: value for Parameter key=AggregatorRatio must be " - "an integer divisor of the number of processes (" + - std::to_string(m_SizeMPI) + hint); - } - - if (parsedParameters.NumAggregators < 1) - { - parsedParameters.NumAggregators = 1; - } - else if (parsedParameters.NumAggregators > m_SizeMPI) + if (ratio > 0) { - parsedParameters.NumAggregators = m_SizeMPI; + int n = m_SizeMPI / ratio; + if ((m_SizeMPI % ratio)) + { + throw std::invalid_argument( + "ERROR: value for Parameter key=AggregatorRatio=" + + std::to_string(ratio) + " must be " + + "an integer divisor of the number of processes=" + + std::to_string(m_SizeMPI) + " " + hint); + } + + if (n < 1) + { + n = 1; + } + else if (n > m_SizeMPI) + { + n = m_SizeMPI; + } + parsedParameters.NumAggregators = n; } } else if (key == "node-local" || key == "nodelocal")