Skip to content

Commit

Permalink
Clean up type conversion warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Chuck Atkins committed Dec 30, 2019
1 parent 09eef1c commit 534770d
Show file tree
Hide file tree
Showing 21 changed files with 60 additions and 49 deletions.
4 changes: 2 additions & 2 deletions examples/heatTransfer/read/ReadSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
static unsigned int convertToUint(std::string varName, char *arg)
{
char *end;
int retval = std::strtoll(arg, &end, 10);
long retval = std::strtol(arg, &end, 10);
if (end[0] || errno == ERANGE)
{
throw std::invalid_argument("Invalid value given for " + varName +
Expand All @@ -30,7 +30,7 @@ static unsigned int convertToUint(std::string varName, char *arg)
throw std::invalid_argument("Negative value given for " + varName +
": " + std::string(arg));
}
return (unsigned int)retval;
return static_cast<unsigned int>(retval);
}

ReadSettings::ReadSettings(int argc, char *argv[], int rank, int nproc)
Expand Down
4 changes: 2 additions & 2 deletions examples/heatTransfer/read/heatRead.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ int main(int argc, char *argv[])
// nor add new variables
reader.LockReaderSelections();

unsigned int gndx = vTin.Shape()[0];
unsigned int gndy = vTin.Shape()[1];
unsigned int gndx = static_cast<unsigned int>(vTin.Shape()[0]);
unsigned int gndy = static_cast<unsigned int>(vTin.Shape()[1]);

if (rank == 0)
{
Expand Down
2 changes: 1 addition & 1 deletion examples/heatTransfer/read_fileonly/PrintData.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include <string>

template <class T>
void printData(double *xy, T *size, T *offset, int rank, int steps)
void printData(double *xy, T *size, T *offset, int rank, size_t steps)
{
std::ofstream myfile;
std::string filename = "data." + std::to_string(rank);
Expand Down
4 changes: 2 additions & 2 deletions examples/heatTransfer/write/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
static unsigned int convertToUint(std::string varName, char *arg)
{
char *end;
int retval = std::strtoll(arg, &end, 10);
long retval = std::strtol(arg, &end, 10);
if (end[0] || errno == ERANGE)
{
throw std::invalid_argument("Invalid value given for " + varName +
Expand All @@ -30,7 +30,7 @@ static unsigned int convertToUint(std::string varName, char *arg)
throw std::invalid_argument("Negative value given for " + varName +
": " + std::string(arg));
}
return (unsigned int)retval;
return static_cast<unsigned int>(retval);
}

Settings::Settings(int argc, char *argv[], int rank, int nproc) : rank{rank}
Expand Down
2 changes: 1 addition & 1 deletion examples/hello/bpFWriteCRead/CppWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ int main(int argc, char *argv[])
{
for (size_t j = 0; j < ny; ++j)
{
data[i * ny + j] = rank * nx * ny + i * ny + j;
data[i * ny + j] = static_cast<float>(rank * nx * ny + i * ny + j);
}
}

Expand Down
2 changes: 1 addition & 1 deletion examples/hello/bpFlushWriter/helloBPFlushWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ int main(int argc, char *argv[])
for (unsigned int t = 0; t < 100; ++t)
{
/** values to time step */
myFloats.assign(myFloats.size(), t);
myFloats.assign(myFloats.size(), static_cast<float>(t));
/** Write variable for buffering */
bpWriter.Put<float>(bpFloats, myFloats.data());
}
Expand Down
5 changes: 3 additions & 2 deletions examples/hello/bpReader/helloBPReaderHeatMap2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@ int main(int argc, char *argv[])
std::vector<unsigned int> temperatures(Nx * Ny);
for (unsigned int i = 0; i < Nx; ++i)
{
const unsigned int iGlobal = start[0] + i;
const unsigned int iGlobal = static_cast<unsigned int>(start[0] + i);

for (unsigned int j = 0; j < Ny; ++j)
{
const unsigned int value = iGlobal * shape[1] + j;
const unsigned int value =
static_cast<unsigned int>(iGlobal * shape[1] + j);
temperatures[i * Ny + j] = value;
}
}
Expand Down
6 changes: 3 additions & 3 deletions examples/hello/bpReader/helloBPReaderHeatMap3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ int main(int argc, char *argv[])
std::vector<unsigned int> temperatures(Nx * Ny * Nz);
for (unsigned int i = 0; i < count[0]; ++i)
{
const unsigned int iGlobal = start[0] + i;
const unsigned int iGlobal = static_cast<unsigned int>(start[0] + i);

for (unsigned int j = 0; j < count[1]; ++j)
{
for (unsigned int k = 0; k < count[2]; ++k)
{
const unsigned int value =
iGlobal * shape[1] * shape[2] + j * shape[2] + k;
const unsigned int value = static_cast<unsigned int>(
iGlobal * shape[1] * shape[2] + j * shape[2] + k);

const std::size_t linearIndex =
i * count[1] * count[2] + j * count[2] + k;
Expand Down
4 changes: 2 additions & 2 deletions examples/hello/insituMPI/HelloInsituArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ static void printUsage(bool isWriter)
static unsigned int convertToUint(std::string varName, char *arg)
{
char *end;
int retval = std::strtoll(arg, &end, 10);
long retval = std::strtol(arg, &end, 10);
if (end[0] || errno == ERANGE)
{
throw std::invalid_argument("Invalid value given for " + varName +
Expand All @@ -48,7 +48,7 @@ static unsigned int convertToUint(std::string varName, char *arg)
throw std::invalid_argument("Negative value given for " + varName +
": " + std::string(arg));
}
return (unsigned int)retval;
return static_cast<unsigned int>(retval);
}

HelloInsituArgs::HelloInsituArgs(bool isWriter, int argc, char *argv[],
Expand Down
4 changes: 4 additions & 0 deletions examples/hello/insituMPI/HelloInsituArgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ class HelloInsituArgs
HelloInsituArgs(bool isWriter, int argc, char *argv[], int rank, int nproc);

void DecomposeArray(int NX, int NY);
void DecomposeArray(size_t NX, size_t NY)
{
DecomposeArray(static_cast<int>(NX), static_cast<int>(NY));
}
};

#endif /* HELLOINSITUARGS_H_s */
6 changes: 3 additions & 3 deletions source/adios2/engine/insitumpi/InSituMPIFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ std::vector<int> FindPeers(const MPI_Comm comm, const std::string &name,
std::vector<int> AssignPeers(const int rank, const int nproc,
const std::vector<int> &allPeers)
{
int nAllPeers = allPeers.size();
int nAllPeers = static_cast<int>(allPeers.size());

std::vector<int> directPeers;

Expand Down Expand Up @@ -254,8 +254,8 @@ std::vector<MPI_Status> CompleteRequests(std::vector<MPI_Request> &requests,
{
std::vector<MPI_Status> statuses(requests.size());

const auto ierr =
MPI_Waitall(requests.size(), requests.data(), statuses.data());
const auto ierr = MPI_Waitall(static_cast<int>(requests.size()),
requests.data(), statuses.data());

if (ierr == MPI_ERR_IN_STATUS)
{
Expand Down
16 changes: 9 additions & 7 deletions source/adios2/engine/insitumpi/InSituMPIReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ StepStatus InSituMPIReader::BeginStep(const StepMode mode,
/* Have timeout: do a collective wait for a step within timeout.
Make sure every writer comes to the same conclusion */
int haveStepMsg = 0;
uint64_t nanoTO = timeoutSeconds * 1000000000.0;
uint64_t nanoTO = static_cast<uint64_t>(timeoutSeconds * 1e9);
if (nanoTO < 1)
{
nanoTO = 1; // avoid 0
Expand Down Expand Up @@ -377,7 +377,8 @@ int InSituMPIReader::Statistics(uint64_t bytesInPlace, uint64_t bytesCopied)
{
if (bytesInPlace == 0)
return 0;
return ((bytesInPlace + bytesCopied) * 100) / bytesInPlace;
return static_cast<int>(((bytesInPlace + bytesCopied) * 100) /
bytesInPlace);
}

void InSituMPIReader::EndStep()
Expand Down Expand Up @@ -412,8 +413,8 @@ void InSituMPIReader::SendReadSchedule(
TAU_SCOPED_TIMER("InSituMPIReader::SendReadSchedule");
// Serialized schedules, one per-writer
std::map<int, std::vector<char>> serializedSchedules =
insitumpi::SerializeLocalReadSchedule(m_RankAllPeers.size(),
variablesSubFileInfo);
insitumpi::SerializeLocalReadSchedule(
static_cast<int>(m_RankAllPeers.size()), variablesSubFileInfo);

// Writer ID -> number of peer readers
std::vector<int> nReaderPerWriter(m_RankAllPeers.size());
Expand Down Expand Up @@ -441,7 +442,8 @@ void InSituMPIReader::SendReadSchedule(
// Reader root sends nReaderPerWriter to writer root
if (m_ReaderRootRank == m_ReaderRank)
{
MPI_Send(nReaderPerWriter.data(), nReaderPerWriter.size(), MPI_INT,
MPI_Send(nReaderPerWriter.data(),
static_cast<int>(nReaderPerWriter.size()), MPI_INT,
m_WriteRootGlobalRank, insitumpi::MpiTags::NumReaderPerWriter,
m_CommWorld);
}
Expand All @@ -456,7 +458,7 @@ void InSituMPIReader::SendReadSchedule(
{
const auto peerID = schedulePair.first;
const auto &schedule = schedulePair.second;
rsLengths[i] = schedule.size();
rsLengths[i] = static_cast<int>(schedule.size());

if (m_Verbosity == 5)
{
Expand Down Expand Up @@ -514,7 +516,7 @@ void InSituMPIReader::AsyncRecvAllVariables()
void InSituMPIReader::ProcessReceives()
{
TAU_SCOPED_TIMER("InSituMPIReader::ProcessReceives");
const int nRequests = m_OngoingReceives.size();
const int nRequests = static_cast<int>(m_OngoingReceives.size());

TAU_START("InSituMPIReader::CompleteRequests");
insitumpi::CompleteRequests(m_MPIRequests, false, m_ReaderRank);
Expand Down
11 changes: 6 additions & 5 deletions source/adios2/engine/insitumpi/InSituMPIReader.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ void InSituMPIReader::AsyncRecvVariable(
const auto &seek = sfi.Seeks;
const size_t blockSize = seek.second - seek.first;
m_MPIRequests.emplace_back();
const int index = m_MPIRequests.size() - 1;
const int index = static_cast<int>(m_MPIRequests.size()) - 1;
size_t elementOffset, dummy;

// Do we read a contiguous piece from the source?
Expand All @@ -154,7 +154,8 @@ void InSituMPIReader::AsyncRecvVariable(
char *ptr = reinterpret_cast<char *>(ptrT);
m_OngoingReceives.emplace_back(sfi, &variable.m_Name, ptr);
MPI_Irecv(m_OngoingReceives[index].inPlaceDataArray,
blockSize, MPI_CHAR, m_RankAllPeers[writerRank],
static_cast<int>(blockSize), MPI_CHAR,
m_RankAllPeers[writerRank],
insitumpi::MpiTags::Data, m_CommWorld,
m_MPIRequests.data() + index);
if (m_Verbosity == 5)
Expand All @@ -174,9 +175,9 @@ void InSituMPIReader::AsyncRecvVariable(
blockSize);
MPI_Irecv(
m_OngoingReceives[index].temporaryDataArray.data(),
blockSize, MPI_CHAR, m_RankAllPeers[writerRank],
insitumpi::MpiTags::Data, m_CommWorld,
m_MPIRequests.data() + index);
static_cast<int>(blockSize), MPI_CHAR,
m_RankAllPeers[writerRank], insitumpi::MpiTags::Data,
m_CommWorld, m_MPIRequests.data() + index);
if (m_Verbosity == 5)
{
std::cout << "InSituMPI Reader " << m_ReaderRank
Expand Down
3 changes: 2 additions & 1 deletion source/adios2/engine/insitumpi/InSituMPISchedules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ SerializeLocalReadSchedule(const int nWriters,
// <writer, <steps, <SubFileInfo>>>
for (const auto &subFileIndexPair : variableNamePair.second)
{
const size_t subFileIndex = subFileIndexPair.first; // writer
const int subFileIndex =
static_cast<int>(subFileIndexPair.first); // writer
// <steps, <SubFileInfo>> but there is only one step
for (const auto &stepPair : subFileIndexPair.second)
{
Expand Down
11 changes: 6 additions & 5 deletions source/adios2/engine/insitumpi/InSituMPIWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ void InSituMPIWriter::PerformPuts()

// store length long enough to survive Isend() completion
// so don't move this into the next if branch
unsigned long mdLen = m_BP3Serializer.m_Metadata.m_Position;
size_t mdLen = m_BP3Serializer.m_Metadata.m_Position;

// Send the metadata to all reader peers, asynchronously
// we don't care about keeping these requests because
Expand Down Expand Up @@ -201,9 +201,9 @@ void InSituMPIWriter::PerformPuts()
MPI_Isend(&mdLen, 1, MPI_UNSIGNED_LONG, peerRank,
insitumpi::MpiTags::MetadataLength, m_CommWorld,
&request);
MPI_Isend(m_BP3Serializer.m_Metadata.m_Buffer.data(), mdLen,
MPI_CHAR, peerRank, insitumpi::MpiTags::Metadata,
m_CommWorld, &request);
MPI_Isend(m_BP3Serializer.m_Metadata.m_Buffer.data(),
static_cast<int>(mdLen), MPI_CHAR, peerRank,
insitumpi::MpiTags::Metadata, m_CommWorld, &request);
}
}

Expand Down Expand Up @@ -443,7 +443,8 @@ void InSituMPIWriter::ReceiveReadSchedule(
// Writer root receives nReaderPerWriter from reader root
if (m_WriterRank == 0)
{
MPI_Recv(nReaderPerWriter.data(), nReaderPerWriter.size(), MPI_INT,
MPI_Recv(nReaderPerWriter.data(),
static_cast<int>(nReaderPerWriter.size()), MPI_INT,
m_RankDirectPeers[0], insitumpi::MpiTags::NumReaderPerWriter,
m_CommWorld, MPI_STATUS_IGNORE);
}
Expand Down
3 changes: 2 additions & 1 deletion source/adios2/engine/insitumpi/InSituMPIWriter.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ void InSituMPIWriter::AsyncSendVariable(
const size_t blockStart = seek.first;
const size_t blockSize = seek.second - seek.first;

MPI_Isend(blockInfo.Data + blockStart, blockSize, MPI_CHAR,
MPI_Isend(blockInfo.Data + blockStart,
static_cast<int>(blockSize), MPI_CHAR,
m_RankAllPeers[readerPair.first],
insitumpi::MpiTags::Data, m_CommWorld,
&m_MPIRequests.back());
Expand Down
2 changes: 1 addition & 1 deletion source/utils/adios_iotest/decomp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void decompRowMajor(const size_t ndim, const size_t rank, const size_t *decomp,
// pos[k] = rank / prod(decomp[i], i=k+1..n-1) % decomp[k]

size_t prod = 1;
for (int k = ndim - 1; k >= 0; --k)
for (size_t k = ndim - 1; k >= 0; --k)
{
pos[k] = rank / prod % decomp[k];
prod *= decomp[k];
Expand Down
4 changes: 2 additions & 2 deletions source/utils/adios_iotest/processConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -706,8 +706,8 @@ Config processConfig(const Settings &settings, size_t *currentConfigLineNumber)
}
std::cout << std::endl;
}
auto cmd =
std::make_shared<CommandRead>(streamName, groupName, d);
auto cmd = std::make_shared<CommandRead>(
streamName, groupName, static_cast<float>(d));
cmd->conditionalStream = conditionalStream;
cfg.commands.push_back(cmd);
cfg.condMap[streamName] = adios2::StepStatus::OK;
Expand Down
2 changes: 1 addition & 1 deletion source/utils/adios_iotest/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ int Settings::processArguments(int argc, char *argv[], MPI_Comm worldComm)

int wrank;
MPI_Comm_rank(worldComm, &wrank);
MPI_Comm_split(worldComm, appId, wrank, &appComm);
MPI_Comm_split(worldComm, static_cast<int>(appId), wrank, &appComm);

int rank, nproc;
MPI_Comm_rank(appComm, &rank);
Expand Down
8 changes: 4 additions & 4 deletions testing/adios2/engine/common/TestEngineCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ adios2::Params ParseEngineParams(std::string Input)
static unsigned int ParseUintParam(const std::string &optionName, char *arg)
{
char *end;
int retval = std::strtoll(arg, &end, 10);
long retval = std::strtol(arg, &end, 10);
if (end[0] || errno == ERANGE)
{
throw std::invalid_argument("Invalid value given for " + optionName +
Expand All @@ -76,7 +76,7 @@ static unsigned int ParseUintParam(const std::string &optionName, char *arg)
throw std::invalid_argument("Negative value given for " + optionName +
": " + std::string(arg));
}
return (unsigned int)retval;
return static_cast<unsigned int>(retval);
}

class Common : public ::testing::Test
Expand Down Expand Up @@ -163,7 +163,7 @@ TEST_F(Common, NewAttributeEveryStep)
for (size_t step = 0; step < steps; ++step)
{
writer.BeginStep(adios2::StepMode::Append);
const double d = step + 1;
const double d = static_cast<double>(step + 1);
if (rank == 0)
writer.Put<double>(var, &d);
const std::string aname = "a" + std::to_string(step);
Expand Down Expand Up @@ -253,7 +253,7 @@ TEST_F(Common, NewAttributeEveryStep)
reader.Get(var, d);
reader.EndStep();

double expectedScalarValue = step + 1;
double expectedScalarValue = static_cast<double>(step + 1);

EXPECT_EQ(d[0], expectedScalarValue)
<< "Error in read, did not receive the expected values for "
Expand Down
6 changes: 3 additions & 3 deletions testing/adios2/engine/staging-common/TestStagingMPMD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ class TestStagingMPMD : public ::testing::TestWithParam<RunParams>
reader.Get(vMyArray, myArray.data());
reader.Get(vMyScalar, myIncomingScalar);
reader.EndStep();
float expectedScalarValue = 1.5 * (step + 1);
float expectedScalarValue = 1.5f * (step + 1);
EXPECT_EQ(myIncomingScalar, expectedScalarValue)
<< "Error in read, did not receive the expected value:"
<< " rank " << rank << ", step " << step;
Expand All @@ -261,8 +261,8 @@ class TestStagingMPMD : public ::testing::TestWithParam<RunParams>
std::cout << "test " << p.npx_w << "x" << p.npy_w << " writers "
<< p.npx_r << "x" << p.npy_r << " readers " << std::endl;

int nwriters = p.npx_w * p.npy_w;
int nreaders = p.npx_r * p.npy_r;
size_t nwriters = p.npx_w * p.npy_w;
size_t nreaders = p.npx_r * p.npy_r;
if (nwriters + nreaders > numprocs)
{
if (!wrank)
Expand Down

0 comments on commit 534770d

Please sign in to comment.