Skip to content

Commit

Permalink
Clang-Tidy 17: modernize-loop-convert (AMReX-Codes#3833)
Browse files Browse the repository at this point in the history
  • Loading branch information
WeiqunZhang authored Mar 21, 2024
1 parent 2e4daeb commit 6e18c42
Show file tree
Hide file tree
Showing 19 changed files with 124 additions and 139 deletions.
4 changes: 2 additions & 2 deletions Src/Amr/AMReX_Amr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1830,8 +1830,8 @@ Amr::checkPoint ()
amrex::FileOpenFailed(FAHeaderFilesName);
}

for(int i(0); i < FAHeaderNames.size(); ++i) {
FAHeaderFile << FAHeaderNames[i] << '\n';
for(const auto & FAHeaderName : FAHeaderNames) {
FAHeaderFile << FAHeaderName << '\n';
}
}
}
Expand Down
20 changes: 10 additions & 10 deletions Src/Amr/AMReX_AmrLevel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1445,8 +1445,8 @@ FillPatchIteratorHelper::fill (FArrayBox& fab,
//
// Copy intersect finefab into next level m_cboxes.
//
for (int j = 0, K = static_cast<int>(FinerCrseFabs.size()); j < K; ++j) {
FinerCrseFabs[j]->copy<RunOn::Host>(finefab);
for (const auto & FinerCrseFab : FinerCrseFabs) {
FinerCrseFab->copy<RunOn::Host>(finefab);
}
}

Expand All @@ -1462,8 +1462,8 @@ FillPatchIteratorHelper::fill (FArrayBox& fab,
//
// Copy intersect coarse into destination fab.
//
for (int i = 0, N = static_cast<int>(FinestCrseFabs.size()); i < N; ++i) {
fab.copy<RunOn::Host>(*FinestCrseFabs[i],0,dcomp,m_ncomp);
for (const auto & FinestCrseFab : FinestCrseFabs) {
fab.copy<RunOn::Host>(*FinestCrseFab,0,dcomp,m_ncomp);
}

if (FineGeom.isAnyPeriodic() && !FineDomain.contains(fab.box()))
Expand All @@ -1472,17 +1472,17 @@ FillPatchIteratorHelper::fill (FArrayBox& fab,

FineGeom.periodicShift(FineDomain,fab.box(),pshifts);

for (int i = 0, N = static_cast<int>(FinestCrseFabs.size()); i < N; i++)
for (const auto & FinestCrseFab : FinestCrseFabs)
{
for (const auto& iv : pshifts)
{
fab.shift(iv);

Box src_dst = FinestCrseFabs[i]->box() & fab.box();
Box src_dst = FinestCrseFab->box() & fab.box();
src_dst &= FineDomain;

if (src_dst.ok()) {
fab.copy<RunOn::Host>(*FinestCrseFabs[i],src_dst,0,src_dst,dcomp,m_ncomp);
fab.copy<RunOn::Host>(*FinestCrseFab,src_dst,0,src_dst,dcomp,m_ncomp);
}

fab.shift(-iv);
Expand Down Expand Up @@ -1846,10 +1846,10 @@ AmrLevel::UpdateDistributionMaps ( DistributionMapping& update_dmap )
if (dmap.size() == mapsize)
{ dmap = update_dmap; }

for (int i = 0; i < state.size(); ++i)
for (auto & i : state)
{
if (state[i].DistributionMap().size() == mapsize)
{ state[i].setDistributionMap(update_dmap); }
if (i.DistributionMap().size() == mapsize)
{ i.setDistributionMap(update_dmap); }
}
}

Expand Down
11 changes: 3 additions & 8 deletions Src/AmrCore/AMReX_ErrorList.H
Original file line number Diff line number Diff line change
Expand Up @@ -453,20 +453,16 @@ std::ostream& operator << (std::ostream& os, const ErrorList& elst);
AMRErrorTag::TEST test,
std::string field,
const AMRErrorTagInfo& info = AMRErrorTagInfo()) noexcept
: m_test(test), m_field(std::move(field)), m_info(info)
: m_value(info.m_max_level, value), m_test(test), m_field(std::move(field)), m_info(info),
m_ngrow(SetNGrow())
{
m_value.resize(info.m_max_level);
for (int i = 0; i < m_value.size(); ++i) {
m_value[i] = value;
}
m_ngrow = SetNGrow();
}

AMRErrorTag (amrex::Vector<amrex::Real> value,
AMRErrorTag::TEST test,
std::string field,
const AMRErrorTagInfo& info = AMRErrorTagInfo()) noexcept
: m_test(test), m_field(std::move(field)), m_info(info)
: m_test(test), m_field(std::move(field)), m_info(info), m_ngrow(SetNGrow())
{
AMREX_ASSERT(!value.empty());
m_value.resize(info.m_max_level);
Expand All @@ -478,7 +474,6 @@ std::ostream& operator << (std::ostream& os, const ErrorList& elst);
for (auto i = int(value.size()); i < m_value.size(); ++i) {
m_value[i] = value[value.size()-1];
}
m_ngrow = SetNGrow();
}

AMRErrorTag (AMRErrorTag::UserFunc* userfunc,
Expand Down
6 changes: 3 additions & 3 deletions Src/Base/AMReX_FileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,10 @@ CreateDirectories (std::string const& path, mode_t mode, bool verbose)
}

if(retVal == false || verbose == true) {
for(int i(0); i < pathError.size(); ++i) {
for(auto & i : pathError) {
amrex::AllPrint()<< "amrex::UtilCreateDirectory:: path errno: "
<< pathError[i].first << " :: "
<< strerror(pathError[i].second)
<< i.first << " :: "
<< strerror(i.second)
<< '\n';
}
}
Expand Down
2 changes: 1 addition & 1 deletion Src/Base/AMReX_MPMD.H
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ int MyProgId (); //! Program ID
class Copier
{
public:
Copier (bool);
explicit Copier (bool);

Copier (BoxArray const& ba, DistributionMapping const& dm,
bool send_ba = false);
Expand Down
4 changes: 2 additions & 2 deletions Src/Base/AMReX_Machine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,8 @@ class Machine
}

result.reserve(nbh_rank_n);
for (int i = 0; i < local_nbh.size(); ++i) {
for (auto rank : node_ranks.at(local_nbh[i])) {
for (int i : local_nbh) {
for (auto rank : node_ranks.at(i)) {
if (result.size() < nbh_rank_n) {
result.push_back(rank);
}
Expand Down
13 changes: 6 additions & 7 deletions Src/Base/AMReX_NFiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,11 @@ void NFilesIter::SetSparseFPP(const Vector<int> &ranksToWrite)
// ---- do more error checking here
// ---- ranks in range, is dynamic on already
mySparseFileNumber = -1;
for(int r(0); r < ranksToWrite.size(); ++r) {
if(ranksToWrite[r] < 0 || ranksToWrite[r] >= nProcs) {
for(int r : ranksToWrite) {
if(r < 0 || r >= nProcs) {
amrex::Abort("**** Error in NFilesIter::SetSparseFPP: rank out of range.");
}
if(ranksToWrite[r] == myProc) {
if(r == myProc) {
if(mySparseFileNumber == -1) {
mySparseFileNumber = myProc;
} else {
Expand Down Expand Up @@ -281,8 +281,8 @@ bool NFilesIter::ReadyToWrite(bool appendFirst) {
BL_PROFILE("NFI::ReadyToWrite:decider");
// ---- the first message received is the coordinator
ParallelDescriptor::Recv(&coordinatorProc, 1, MPI_ANY_SOURCE, deciderTag);
for(int i(0); i < setZeroProcs.size(); ++i) { // ---- tell the set zero ranks who is coordinating
ParallelDescriptor::Send(&coordinatorProc, 1, setZeroProcs[i], coordinatorTag);
for(int setZeroProc : setZeroProcs) { // ---- tell the set zero ranks who is coordinating
ParallelDescriptor::Send(&coordinatorProc, 1, setZeroProc, coordinatorTag);
}
unreadMessages.push_back(std::make_pair(deciderTag, setZeroProcs.size() - 1));
}
Expand Down Expand Up @@ -552,8 +552,7 @@ Vector<int> NFilesIter::FileNumbersWritten()
void NFilesIter::CleanUpMessages() {
#ifdef BL_USE_MPI
BL_PROFILE("NFI::CleanUpMessages");
for(int i(0); i < unreadMessages.size(); ++i) {
std::pair<int, int> & pii = unreadMessages[i];
for(auto & pii : unreadMessages) {
int fromProc, tag(pii.first), nMessages(pii.second);
#if 0
amrex::AllPrint() << ParallelDescriptor::MyProc() << ":: cleaning up " << nMessages
Expand Down
4 changes: 2 additions & 2 deletions Src/Base/AMReX_ParallelDescriptor.H
Original file line number Diff line number Diff line change
Expand Up @@ -996,9 +996,9 @@ ParallelDescriptor::GatherLayoutDataToVector (const LayoutData<T>& sendbuf,
Vector<int> recvcount(nprocs, 0);
recvbuf.resize(sendbuf.size());
const Vector<int>& old_pmap = sendbuf.DistributionMap().ProcessorMap();
for (int i=0; i<old_pmap.size(); ++i)
for (int i : old_pmap)
{
++recvcount[old_pmap[i]];
++recvcount[i];
}

// Make a map from post-gather to pre-gather index
Expand Down
4 changes: 2 additions & 2 deletions Src/Base/AMReX_PlotFileUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ WriteGenericPlotfileHeader (std::ostream &HeaderFile,

HeaderFile << varnames.size() << '\n';

for (int ivar = 0; ivar < varnames.size(); ++ivar) {
HeaderFile << varnames[ivar] << "\n";
for (const auto & varname : varnames) {
HeaderFile << varname << "\n";
}
HeaderFile << AMREX_SPACEDIM << '\n';
HeaderFile << time << '\n';
Expand Down
36 changes: 18 additions & 18 deletions Src/Base/AMReX_Utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -727,8 +727,8 @@ void amrex::SyncStrings(const Vector<std::string> &localStrings,
int pfStringsSize(0);
std::ostringstream pfStrings;
if(ParallelDescriptor::IOProcessor()) {
for(int i(0); i < localStringsCopy.size(); ++i) {
pfStrings << localStringsCopy[i] << '\n';
for(const auto & i : localStringsCopy) {
pfStrings << i << '\n';
}
pfStringsSize = static_cast<int>(pfStrings.str().size());
}
Expand All @@ -752,28 +752,28 @@ void amrex::SyncStrings(const Vector<std::string> &localStrings,
}
}
// ---- now check if they match on non ioprocs
for(int n(0); n < ioprocStrings.size(); ++n) {
for(const auto & ioprocString : ioprocStrings) {
bool matched(false);
for(int i(0); i < localStringsCopy.size(); ++i) {
if(ioprocStrings[n] == localStringsCopy[i]) {
for(const auto & i : localStringsCopy) {
if(ioprocString == i) {
matched = true;
}
}
if( ! matched) {
++nUnmatched;
localStringsCopy.push_back(ioprocStrings[n]); // ---- add to local set
localStringsCopy.push_back(ioprocString); // ---- add to local set
}
}
for(int n(0); n < localStringsCopy.size(); ++n) {
for(const auto & n : localStringsCopy) {
bool matched(false);
for(int i(0); i < ioprocStrings.size(); ++i) {
if(localStringsCopy[n] == ioprocStrings[i]) {
for(const auto & ioprocString : ioprocStrings) {
if(n == ioprocString) {
matched = true;
}
}
if( ! matched) {
++nUnmatched;
sendStrings.push_back(localStringsCopy[n]); // ---- send these to the ioproc
sendStrings.push_back(n); // ---- send these to the ioproc
}
}
}
Expand All @@ -791,8 +791,8 @@ void amrex::SyncStrings(const Vector<std::string> &localStrings,
std::ostringstream ossSendStrings;
Vector<char> sendCharArray(1); // cannot be zero for gather call
if( ! ParallelDescriptor::IOProcessor()) {
for(int i(0); i < sendStrings.size(); ++i) {
ossSendStrings << sendStrings[i] << '\n';
for(const auto & sendString : sendStrings) {
ossSendStrings << sendString << '\n';
}
sendStringsSize = static_cast<int>(ossSendStrings.str().size());
sendCharArray.resize(sendStringsSize + 1);
Expand All @@ -806,8 +806,8 @@ void amrex::SyncStrings(const Vector<std::string> &localStrings,
Vector<char> recvStrings(1);
Vector<int> offset(nProcs, 0);
if(ParallelDescriptor::IOProcessor()) {
for(int i(0); i < nChars.size(); ++i) {
totalChars += nChars[i];
for(int nChar : nChars) {
totalChars += nChar;
}
recvStrings.resize(totalChars + 1);

Expand Down Expand Up @@ -844,8 +844,8 @@ void amrex::SyncStrings(const Vector<std::string> &localStrings,
int syncedStringsSize(0);
std::ostringstream syncedStrStr;
if(ParallelDescriptor::IOProcessor()) {
for(int i(0); i < syncedStrings.size(); ++i) {
syncedStrStr << syncedStrings[i] << '\n';
for(const auto & syncedString : syncedStrings) {
syncedStrStr << syncedString << '\n';
}
syncedStringsSize = static_cast<int>(syncedStrStr.str().size());
}
Expand Down Expand Up @@ -878,8 +878,8 @@ void amrex::SyncStrings(const Vector<std::string> &localStrings,
amrex::Vector<char> amrex::SerializeStringArray(const Vector<std::string> &stringArray)
{
std::ostringstream stringStream;
for(int i(0); i < stringArray.size(); ++i) {
stringStream << stringArray[i] << '\n';
for(const auto & i : stringArray) {
stringStream << i << '\n';
}

Vector<char> charArray(stringStream.str().size() + 1);
Expand Down
4 changes: 2 additions & 2 deletions Src/Base/AMReX_VisMF.H
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,8 @@ Write (const FabArray<FAB>& fa, const std::string& name)
const Vector<int> &pmap = fa.DistributionMap().ProcessorMap();
std::set<int> procsWithData;
Vector<int> procsWithDataVector;
for(int i = 0; i < pmap.size(); ++i) {
procsWithData.insert(pmap[i]);
for(int i : pmap) {
procsWithData.insert(i);
}
const int nOutFiles = VisMF::GetNOutFiles();
if (static_cast<int>(procsWithData.size()) < nOutFiles) {
Expand Down
Loading

0 comments on commit 6e18c42

Please sign in to comment.