Skip to content

Commit

Permalink
Clang-Tidy changes in Src/Particle (#3476)
Browse files Browse the repository at this point in the history
  • Loading branch information
WeiqunZhang authored Aug 4, 2023
1 parent c1ec94d commit 933ec97
Show file tree
Hide file tree
Showing 27 changed files with 999 additions and 777 deletions.
4 changes: 2 additions & 2 deletions Src/Particle/AMReX_NeighborList.H
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ public:
for (auto p = poffset[index]; p < poffset[index+1]; ++p) {
const auto& pid = pperm[p];
bool ghost_pid = (pid >= np_real);
if (is_same && (pid == i)) continue;
if (is_same && (pid == i)) { continue; }
if (call_check_pair(check_pair,
src_ptile_data, dst_ptile_data,
i, pid, type, ghost_i, ghost_pid)) {
Expand Down Expand Up @@ -435,7 +435,7 @@ public:
for (auto p = poffset[index]; p < poffset[index+1]; ++p) {
const auto& pid = pperm[p];
bool ghost_pid = (pid >= np_real);
if (is_same && (pid == i)) continue;
if (is_same && (pid == i)) { continue; }
if (call_check_pair(check_pair,
src_ptile_data, dst_ptile_data,
i, pid, type, ghost_i, ghost_pid)) {
Expand Down
28 changes: 16 additions & 12 deletions Src/Particle/AMReX_NeighborParticles.H
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@ private:
os << nim.dst_level << " " << nim.dst_grid << " " << nim.dst_tile << " " << nim.dst_index
<< nim.src_level << " " << nim.src_grid << " " << nim.src_tile << " " << nim.src_index
<< nim.thread_num;
if (!os.good())
if (!os.good()) {
amrex::Error("operator<<(ostream&, const NeighborIndexMap& nim) failed");
}
return os;
}

Expand All @@ -93,9 +94,9 @@ private:
{}

bool operator< (const NeighborCopyTag& other) const {
if (level != other.level) return level < other.level;
if (grid != other.grid) return grid < other.grid;
if (tile != other.tile) return tile < other.tile;
if (level != other.level) { return level < other.level; }
if (grid != other.grid) { return grid < other.grid; }
if (tile != other.tile) { return tile < other.tile; }
AMREX_D_TERM(
if (periodic_shift[0] != other.periodic_shift[0])
return periodic_shift[0] < other.periodic_shift[0];,
Expand Down Expand Up @@ -124,8 +125,9 @@ private:
friend std::ostream& operator<< (std::ostream& os, const NeighborCopyTag& tag)
{
os << tag.level << " " << tag.grid << " " << tag.tile << " " << tag.periodic_shift;
if (!os.good())
if (!os.good()) {
amrex::Error("operator<<(ostream&, const NeighborCopyTag&) failed");
}
return os;
}
};
Expand All @@ -141,8 +143,9 @@ private:
friend std::ostream& operator<< (std::ostream& os, const InverseCopyTag& tag)
{
os << tag.src_level << " " << tag.src_grid << " " << tag.src_tile << " " << tag.src_index;
if (!os.good())
if (!os.good()) {
amrex::Error("operator<<(ostream&, const InverseCopyTag&) failed");
}
return os;
}

Expand Down Expand Up @@ -180,8 +183,9 @@ private:
friend std::ostream& operator<< (std::ostream& os, const NeighborCommTag& tag)
{
os << tag.proc_id << " " << tag.level_id << " " << tag.grid_id << " " << tag.tile_id;
if (!os.good())
if (!os.good()) {
amrex::Error("operator<<(ostream&, const NeighborCommTag&) failed");
}
return os;
}
};
Expand Down Expand Up @@ -433,15 +437,15 @@ protected:
: grid_id(a_grid_id), box(a_box), periodic_shift(a_periodic_shift) {}

bool operator<(const NeighborTask& other) const {
if (grid_id != other.grid_id) return grid_id < other.grid_id;
if (box != other.box ) return box < other.box;
if (grid_id != other.grid_id) { return grid_id < other.grid_id; }
if (box != other.box ) { return box < other.box; }
AMREX_D_TERM(
if (periodic_shift[0] != other.periodic_shift[0])
return periodic_shift[0] < other.periodic_shift[0];,
{ return periodic_shift[0] < other.periodic_shift[0]; },
if (periodic_shift[1] != other.periodic_shift[1])
return periodic_shift[1] < other.periodic_shift[1];,
{ return periodic_shift[1] < other.periodic_shift[1]; },
if (periodic_shift[2] != other.periodic_shift[2])
return periodic_shift[2] < other.periodic_shift[2];
{ return periodic_shift[2] < other.periodic_shift[2]; }
)
return false;
}
Expand Down
39 changes: 22 additions & 17 deletions Src/Particle/AMReX_NeighborParticlesCPUImpl.H
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,9 @@ sumNeighborsMPI (std::map<int, Vector<char> >& not_ours,

Vector<Long> isnds(NProcs, 0);
Vector<Long> ircvs(NProcs, 0);
for (int i = 0; i < NProcs; ++i)
for (int i = 0; i < NProcs; ++i) {
ircvs[i] = 0;
}

{
// each proc figures out how many bytes it will send, and how
Expand All @@ -132,7 +133,7 @@ sumNeighborsMPI (std::map<int, Vector<char> >& not_ours,

ParallelAllReduce::Max(num_isnds, ParallelContext::CommunicatorSub());

if (num_isnds == 0) return;
if (num_isnds == 0) { return; }

const int num_ircvs = neighbor_procs.size();
Vector<MPI_Status> stats(num_ircvs);
Expand Down Expand Up @@ -163,7 +164,7 @@ sumNeighborsMPI (std::map<int, Vector<char> >& not_ours,
ParallelContext::CommunicatorSub());
}

if (num_ircvs > 0) ParallelDescriptor::Waitall(rreqs, stats);
if (num_ircvs > 0) { ParallelDescriptor::Waitall(rreqs, stats); }
}

Vector<int> RcvProc;
Expand Down Expand Up @@ -303,11 +304,12 @@ NeighborParticleContainer<NStructReal, NStructInt, NArrayReal, NArrayInt>
auto& aos = neighbors[tag.level][dst_index].GetArrayOfStructs();
ParticleType& p = aos[tag.dst_index];
for (int dir = 0; dir < AMREX_SPACEDIM; ++dir) {
if (! periodicity.isPeriodic(dir)) continue;
if (tag.periodic_shift[dir] < 0)
if (! periodicity.isPeriodic(dir)) { continue; }
if (tag.periodic_shift[dir] < 0) {
p.pos(dir) += static_cast<ParticleReal> (prob_domain.length(dir));
else if (tag.periodic_shift[dir] > 0)
} else if (tag.periodic_shift[dir] > 0) {
p.pos(dir) -= static_cast<ParticleReal> (prob_domain.length(dir));
}
}
}

Expand All @@ -326,11 +328,12 @@ NeighborParticleContainer<NStructReal, NStructInt, NArrayReal, NArrayInt>
ParticleType p = aos[tag.src_index]; // copy
if (periodicity.isAnyPeriodic()) {
for (int dir = 0; dir < AMREX_SPACEDIM; ++dir) {
if (! periodicity.isPeriodic(dir)) continue;
if (tag.periodic_shift[dir] < 0)
if (! periodicity.isPeriodic(dir)) { continue; }
if (tag.periodic_shift[dir] < 0) {
p.pos(dir) += static_cast<ParticleReal> (prob_domain.length(dir));
else if (tag.periodic_shift[dir] > 0)
} else if (tag.periodic_shift[dir] > 0) {
p.pos(dir) -= static_cast<ParticleReal> (prob_domain.length(dir));
}
}
}

Expand Down Expand Up @@ -386,8 +389,9 @@ NeighborParticleContainer<NStructReal, NStructInt, NArrayReal, NArrayInt>
const int tile = mfi.LocalTileIndex();
PairIndex dst_index(grid, tile);
neighbors[lev][dst_index].resize(local_neighbor_sizes[lev][dst_index]);
if ( enableInverse() )
if ( enableInverse() ) {
inverse_tags[lev][dst_index].resize(local_neighbor_sizes[lev][dst_index]);
}
}
}
BL_PROFILE_VAR_STOP(update);
Expand Down Expand Up @@ -420,7 +424,7 @@ NeighborParticleContainer<NStructReal, NStructInt, NArrayReal, NArrayInt>
resizeContainers(this->numLevels());
for (int lev = 0; lev < this->numLevels(); ++lev) {
neighbors[lev].clear();
if ( enableInverse() ) inverse_tags[lev].clear();
if ( enableInverse() ) { inverse_tags[lev].clear(); }
buffer_tag_cache[lev].clear();

for(MFIter mfi = this->MakeMFIter(lev); mfi.isValid(); ++mfi)
Expand Down Expand Up @@ -450,8 +454,9 @@ getRcvCountsMPI () {
// many it will receive
Vector<Long> snds(NProcs, 0);
rcvs.resize(NProcs);
for (int i = 0; i < NProcs; ++i)
for (int i = 0; i < NProcs; ++i) {
rcvs[i] = 0;
}

num_snds = 0;
for (const auto& kv : send_data) {
Expand All @@ -461,7 +466,7 @@ getRcvCountsMPI () {

ParallelAllReduce::Max(num_snds, ParallelContext::CommunicatorSub());

if (num_snds == 0) return;
if (num_snds == 0) { return; }

const int num_rcvs = neighbor_procs.size();
Vector<MPI_Status> stats(num_rcvs);
Expand Down Expand Up @@ -491,7 +496,7 @@ getRcvCountsMPI () {
ParallelContext::CommunicatorSub());
}

if (num_rcvs > 0) ParallelDescriptor::Waitall(rreqs, stats);
if (num_rcvs > 0) { ParallelDescriptor::Waitall(rreqs, stats); }

#endif // AMREX_USE_MPI
}
Expand All @@ -508,8 +513,8 @@ fillNeighborsMPI (bool reuse_rcv_counts) {

// each proc figures out how many bytes it will send, and how
// many it will receive
if (!reuse_rcv_counts) getRcvCountsMPI();
if (num_snds == 0) return;
if (!reuse_rcv_counts) { getRcvCountsMPI(); }
if (num_snds == 0) { return; }

Vector<int> RcvProc;
Vector<std::size_t> rOffset; // Offset (in bytes) in the receive buffer
Expand Down Expand Up @@ -571,7 +576,7 @@ fillNeighborsMPI (bool reuse_rcv_counts) {
std::memcpy(&tid, buffer, sizeof(int)); buffer += sizeof(int);
std::memcpy(&size, buffer, sizeof(int)); buffer += sizeof(int);

if (size == 0) continue;
if (size == 0) { continue; }

np = size / cdata_size;

Expand Down
12 changes: 6 additions & 6 deletions Src/Particle/AMReX_NeighborParticlesGPUImpl.H
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ namespace detail
face_boxes.push_back(lo_face_box); bl.push_back(lo_face_box);
for (auto face_box : face_boxes) {
for (int j = 0; j < AMREX_SPACEDIM; ++j) {
if (i == j) continue;
if (i == j) { continue; }
BoxList edge_boxes;
Box hi_edge_box = adjCellHi(face_box, j, ncells);
Box lo_edge_box = adjCellLo(face_box, j, ncells);
edge_boxes.push_back(hi_edge_box); bl.push_back(hi_edge_box);
edge_boxes.push_back(lo_edge_box); bl.push_back(lo_edge_box);
for (auto edge_box : edge_boxes) {
for (int k = 0; k < AMREX_SPACEDIM; ++k) {
if ((j == k) || (i == k)) continue;
if ((j == k) || (i == k)) { continue; }
Box hi_corner_box = adjCellHi(edge_box, k, ncells);
Box lo_corner_box = adjCellLo(edge_box, k, ncells);
bl.push_back(hi_corner_box);
Expand Down Expand Up @@ -57,7 +57,7 @@ buildNeighborMask ()
const BoxArray& ba = this->ParticleBoxArray(lev);
const DistributionMapping& dmap = this->ParticleDistributionMap(lev);

if (ba.size() == 1 && (! geom.isAnyPeriodic()) ) return;
if (ba.size() == 1 && (! geom.isAnyPeriodic()) ) { return; }

if (m_neighbor_mask_ptr == nullptr ||
! BoxArray::SameRefs(m_neighbor_mask_ptr->boxArray(), ba) ||
Expand All @@ -82,7 +82,7 @@ buildNeighborMask ()
{
int nbor_grid = isec.first;
const Box isec_box = isec.second - pshift;
if ( (grid == nbor_grid) && (pshift == 0)) continue;
if ( (grid == nbor_grid) && (pshift == 0)) { continue; }
neighbor_grids.insert(NeighborTask(nbor_grid, isec_box, pshift));
const int global_rank = dmap[nbor_grid];
neighbor_procs.push_back(ParallelContext::global_to_local_rank(global_rank));
Expand Down Expand Up @@ -131,7 +131,7 @@ buildNeighborCopyOp (bool use_boundary_neighbor)
auto& plev = this->GetParticles(lev);
auto& ba = this->ParticleBoxArray(lev);

if (ba.size() == 1 && (! geom.isAnyPeriodic()) ) return;
if (ba.size() == 1 && (! geom.isAnyPeriodic()) ) { return; }

for(MFIter mfi = this->MakeMFIter(lev); mfi.isValid(); ++mfi)
{
Expand Down Expand Up @@ -159,7 +159,7 @@ buildNeighborCopyOp (bool use_boundary_neighbor)
auto p_counts = counts.dataPtr();
auto p_offsets = offsets.dataPtr();

ParticleType* p_ptr = &(aos[0]);
ParticleType* p_ptr = aos.data();
auto p_code_array = m_code_array[gid].dataPtr();
auto p_isec_boxes = m_isec_boxes[gid].dataPtr();
const int nisec_box = m_isec_boxes[gid].size();
Expand Down
Loading

0 comments on commit 933ec97

Please sign in to comment.