Skip to content

Commit

Permalink
Fix sign errors in handling integer parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
pnorbert committed Oct 2, 2020
1 parent 8b3390b commit 8fa5afd
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 23 deletions.
4 changes: 2 additions & 2 deletions source/adios2/toolkit/aggregator/mpi/MPIAggregator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<size_t>(parentComm.Rank());
m_ConsumerRank = parentComm.Rank();
}
m_ConsumerRank = m_Comm.BroadcastValue<size_t>(m_ConsumerRank, 0);
m_ConsumerRank = m_Comm.BroadcastValue<int>(m_ConsumerRank, 0);
}

void MPIAggregator::HandshakeRank(const int rank)
Expand Down
51 changes: 30 additions & 21 deletions source/adios2/toolkit/format/bp/BPBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,35 +155,44 @@ void BPBase::Init(const Params &parameters, const std::string hint,
}
else if (key == "substreams" || key == "numaggregators")
{
parsedParameters.NumAggregators =
static_cast<int>(helper::StringTo<uint32_t>(
value, " in Parameter key=SubStreams " + hint));
int n = static_cast<int>(helper::StringTo<int32_t>(
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<int>(helper::StringTo<int32_t>(
int ratio = static_cast<int>(helper::StringTo<int32_t>(
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")
Expand Down

0 comments on commit 8fa5afd

Please sign in to comment.