diff --git a/Src/Particle/AMReX_NeighborList.H b/Src/Particle/AMReX_NeighborList.H index 28afc3bce9d..330bef29834 100644 --- a/Src/Particle/AMReX_NeighborList.H +++ b/Src/Particle/AMReX_NeighborList.H @@ -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)) { @@ -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)) { diff --git a/Src/Particle/AMReX_NeighborParticles.H b/Src/Particle/AMReX_NeighborParticles.H index 1e0872a032e..5789f6f206d 100644 --- a/Src/Particle/AMReX_NeighborParticles.H +++ b/Src/Particle/AMReX_NeighborParticles.H @@ -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; } @@ -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];, @@ -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; } }; @@ -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; } @@ -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; } }; @@ -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; } diff --git a/Src/Particle/AMReX_NeighborParticlesCPUImpl.H b/Src/Particle/AMReX_NeighborParticlesCPUImpl.H index 6be73c64a5a..6f7da58f06e 100644 --- a/Src/Particle/AMReX_NeighborParticlesCPUImpl.H +++ b/Src/Particle/AMReX_NeighborParticlesCPUImpl.H @@ -116,8 +116,9 @@ sumNeighborsMPI (std::map >& not_ours, Vector isnds(NProcs, 0); Vector 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 @@ -132,7 +133,7 @@ sumNeighborsMPI (std::map >& 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 stats(num_ircvs); @@ -163,7 +164,7 @@ sumNeighborsMPI (std::map >& not_ours, ParallelContext::CommunicatorSub()); } - if (num_ircvs > 0) ParallelDescriptor::Waitall(rreqs, stats); + if (num_ircvs > 0) { ParallelDescriptor::Waitall(rreqs, stats); } } Vector RcvProc; @@ -303,11 +304,12 @@ NeighborParticleContainer 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 (prob_domain.length(dir)); - else if (tag.periodic_shift[dir] > 0) + } else if (tag.periodic_shift[dir] > 0) { p.pos(dir) -= static_cast (prob_domain.length(dir)); + } } } @@ -326,11 +328,12 @@ NeighborParticleContainer 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 (prob_domain.length(dir)); - else if (tag.periodic_shift[dir] > 0) + } else if (tag.periodic_shift[dir] > 0) { p.pos(dir) -= static_cast (prob_domain.length(dir)); + } } } @@ -386,8 +389,9 @@ NeighborParticleContainer 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); @@ -420,7 +424,7 @@ NeighborParticleContainer 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) @@ -450,8 +454,9 @@ getRcvCountsMPI () { // many it will receive Vector 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) { @@ -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 stats(num_rcvs); @@ -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 } @@ -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 RcvProc; Vector rOffset; // Offset (in bytes) in the receive buffer @@ -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; diff --git a/Src/Particle/AMReX_NeighborParticlesGPUImpl.H b/Src/Particle/AMReX_NeighborParticlesGPUImpl.H index 6338d9d55f8..4cc533d901e 100644 --- a/Src/Particle/AMReX_NeighborParticlesGPUImpl.H +++ b/Src/Particle/AMReX_NeighborParticlesGPUImpl.H @@ -21,7 +21,7 @@ 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); @@ -29,7 +29,7 @@ namespace detail 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); @@ -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) || @@ -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)); @@ -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) { @@ -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(); diff --git a/Src/Particle/AMReX_NeighborParticlesI.H b/Src/Particle/AMReX_NeighborParticlesI.H index 56ce4ff27d8..07819e9f7b4 100644 --- a/Src/Particle/AMReX_NeighborParticlesI.H +++ b/Src/Particle/AMReX_NeighborParticlesI.H @@ -43,10 +43,12 @@ template void NeighborParticleContainer ::initializeCommComps () { - for (int ii = 0; ii < AMREX_SPACEDIM + NStructReal + this->NumRealComps(); ++ii) + for (int ii = 0; ii < AMREX_SPACEDIM + NStructReal + this->NumRealComps(); ++ii) { ghost_real_comp.push_back(1); - for (int ii = 0; ii < 2 + NStructInt + this->NumIntComps(); ++ii) + } + for (int ii = 0; ii < 2 + NStructInt + this->NumIntComps(); ++ii) { ghost_int_comp.push_back(1); + } calcCommSize(); } @@ -81,7 +83,7 @@ NeighborParticleContainer comm_size += sizeof(int); } } - if ( enableInverse() ) comm_size += 4*sizeof(int); + if ( enableInverse() ) { comm_size += 4*sizeof(int); } cdata_size = comm_size; } @@ -150,8 +152,8 @@ NeighborParticleContainer BL_PROFILE("NeighborParticleContainer::BuildMasks"); - if (this->numLevels() == 1) use_mask = true; - else use_mask = false; + if (this->numLevels() == 1) { use_mask = true; } + else { use_mask = false; } resizeContainers(this->numLevels()); @@ -208,8 +210,9 @@ NeighborParticleContainer const int proc = ParallelContext::global_to_local_rank(global_proc); NeighborCommTag comm_tag(proc, level, grid, tile); local_neighbors.push_back(comm_tag); - if (proc != ParallelContext::MyProcSub()) + if (proc != ParallelContext::MyProcSub()) { neighbor_procs.push_back(proc); + } } } } @@ -225,8 +228,9 @@ NeighborParticleContainer GetCommTagsBox(comm_tags, lev, box); for (auto const& tag : comm_tags) { local_neighbors.push_back(tag); - if (tag.proc_id != ParallelContext::MyProcSub()) + if (tag.proc_id != ParallelContext::MyProcSub()) { neighbor_procs.push_back(tag.proc_id); + } } } } @@ -373,7 +377,7 @@ NeighborParticleContainer for (int j = 0; j < static_cast(tags.size()); ++j) { NeighborCopyTag& tag = tags[j]; PairIndex dst_index(tag.grid, tag.tile); - if (tag.grid < 0) continue; + if (tag.grid < 0) { continue; } tag.src_index = i; const int cache_index = cache.size(); @@ -482,14 +486,14 @@ NeighborParticleContainer } for (const auto& kv: remote_map) { - if (kv.first.proc_id == MyProc) continue; + if (kv.first.proc_id == MyProc) { continue; } Vector& buffer = send_data[kv.first.proc_id]; buffer.resize(sizeof(int)); - std::memcpy(&buffer[0], &tile_counts[kv.first.proc_id], sizeof(int)); + std::memcpy(buffer.data(), &tile_counts[kv.first.proc_id], sizeof(int)); } for (auto& kv : remote_map) { - if (kv.first.proc_id == MyProc) continue; + if (kv.first.proc_id == MyProc) { continue; } int np = kv.second.size(); int data_size = np * cdata_size; Vector& buffer = send_data[kv.first.proc_id]; @@ -550,7 +554,7 @@ getNeighborTags (Vector& tags, const ParticleType& p, const int lev = 0; const IntVect& iv = this->Index(p, lev); - if (shrink_box.contains(iv)) return; + if (shrink_box.contains(iv)) { return; } const Periodicity& periodicity = this->Geom(lev).periodicity(); const Box& domain = this->Geom(lev).Domain(); @@ -562,7 +566,7 @@ getNeighborTags (Vector& tags, const ParticleType& p, for (int ii = -nGrow[0]; ii < nGrow[0] + 1; ii += nGrow[0]) {, for (int jj = -nGrow[1]; jj < nGrow[1] + 1; jj += nGrow[1]) {, for (int kk = -nGrow[2]; kk < nGrow[2] + 1; kk += nGrow[2]) {) - if (AMREX_D_TERM((ii == 0), && (jj == 0), && (kk == 0))) continue; + if (AMREX_D_TERM((ii == 0), && (jj == 0), && (kk == 0))) { continue; } IntVect shift(AMREX_D_DECL(ii, jj, kk)); IntVect neighbor_cell = iv + shift; @@ -572,15 +576,16 @@ getNeighborTags (Vector& tags, const ParticleType& p, tag.level = mask(neighbor_cell, MaskComps::level); if (periodicity.isAnyPeriodic()) { for (int dir = 0; dir < AMREX_SPACEDIM; ++dir) { - if (! periodicity.isPeriodic(dir)) continue; - if (neighbor_cell[dir] < lo[dir]) + if (! periodicity.isPeriodic(dir)) { continue; } + if (neighbor_cell[dir] < lo[dir]) { tag.periodic_shift[dir] = -1; - else if (neighbor_cell[dir] > hi[dir]) + } else if (neighbor_cell[dir] > hi[dir]) { tag.periodic_shift[dir] = 1; + } } } - if (tag != src_tag) tags.push_back(tag); + if (tag != src_tag) { tags.push_back(tag); } AMREX_D_TERM( }, @@ -610,12 +615,12 @@ getNeighborTags (Vector& tags, const ParticleType& p, { const Box& grid_box = ba[isec.first]; for (IntVect cell = pbox.smallEnd(); cell <= pbox.bigEnd(); pbox.next(cell)) { - if ( !grid_box.contains(cell) ) continue; + if ( !grid_box.contains(cell) ) { continue; } int tile = getTileIndex(cell, grid_box, this->do_tiling, this->tile_size, tbx); auto nbor = NeighborCopyTag(lev, isec.first, tile); nbor.periodic_shift = -pshift; - if (src_tag != nbor) tags.push_back(nbor); + if (src_tag != nbor) { tags.push_back(nbor); } } } } @@ -724,7 +729,7 @@ buildNeighborList (CheckPair&& check_pair, bool /*sort*/) auto& ptile = plev[index]; - if (ptile.numParticles() == 0) continue; + if (ptile.numParticles() == 0) { continue; } Box bx = pti.tilebox(); int ng = computeRefFac(0, lev).max()*m_num_neighbor_cells; @@ -809,7 +814,7 @@ buildNeighborList (CheckPair&& check_pair, OtherPCType& other, const auto& ptile = plev[index]; auto& other_ptile = other.ParticlesAt(lev, pti); - if (ptile.numParticles() == 0) continue; + if (ptile.numParticles() == 0) { continue; } Box bx = pti.tilebox(); int ng = computeRefFac(0, lev).max()*m_num_neighbor_cells; @@ -844,7 +849,7 @@ buildNeighborList (CheckPair&& check_pair, int type_ind, int* ref_ratio, { AMREX_ASSERT(numParticlesOutOfRange(*this, m_num_neighbor_cells) == 0); - if (num_bin_types == 1) AMREX_ASSERT(ref_ratio[0] == 1); + if (num_bin_types == 1) { AMREX_ASSERT(ref_ratio[0] == 1); } BL_PROFILE("NeighborParticleContainer::buildNeighborList"); @@ -880,7 +885,7 @@ buildNeighborList (CheckPair&& check_pair, int type_ind, int* ref_ratio, auto index = std::make_pair(gid, tid); auto& ptile = plev[index]; - if (ptile.numParticles() == 0) continue; + if (ptile.numParticles() == 0) { continue; } Box bx = pti.tilebox(); int ng = 1; @@ -1057,10 +1062,10 @@ selectActualNeighbors (CheckPair&& check_pair, int num_cells) for (int ii = amrex::max(ix-num_cells, 0); ii <= amrex::min(ix+num_cells, nx); ++ii) { for (int jj = amrex::max(iy-num_cells, 0); jj <= amrex::min(iy+num_cells, ny); ++jj) { for (int kk = amrex::max(iz-num_cells, 0); kk <= amrex::min(iz+num_cells, nz); ++kk) { - if (isActualNeighbor) break; + if (isActualNeighbor) { break; } int nbr_cell_id = (ii * ny + jj) * nz + kk; for (auto p = poffset[nbr_cell_id]; p < poffset[nbr_cell_id+1]; ++p) { - if (pperm[p] == i) continue; + if (pperm[p] == i) { continue; } if (call_check_pair(check_pair, ptile_data, ptile_data, i, pperm[p])) { IntVect cell_ijk = getParticleCell(pstruct[pperm[p]], plo, dxi, domain); if (!box.contains(cell_ijk)) { @@ -1116,7 +1121,7 @@ resizeContainers (int num_levels) mask_ptr.resize(num_levels); buffer_tag_cache.resize(num_levels); local_neighbor_sizes.resize(num_levels); - if ( enableInverse() ) inverse_tags.resize(num_levels); + if ( enableInverse() ) { inverse_tags.resize(num_levels); } } AMREX_ASSERT((neighbors.size() == m_neighbor_list.size()) && diff --git a/Src/Particle/AMReX_ParGDB.H b/Src/Particle/AMReX_ParGDB.H index 925416170e5..59f236ad1f5 100644 --- a/Src/Particle/AMReX_ParGDB.H +++ b/Src/Particle/AMReX_ParGDB.H @@ -342,8 +342,9 @@ int ParGDB::MaxRefRatio (int /*level*/) const { int max_ref_ratio = 0; - for (int lev = 0; lev < m_nlevels-1; lev++) + for (int lev = 0; lev < m_nlevels-1; lev++) { max_ref_ratio = std::max(max_ref_ratio, m_rr[lev].max()); + } return max_ref_ratio; } diff --git a/Src/Particle/AMReX_Particle.H b/Src/Particle/AMReX_Particle.H index 8bee9af24eb..16004d1231e 100644 --- a/Src/Particle/AMReX_Particle.H +++ b/Src/Particle/AMReX_Particle.H @@ -55,7 +55,7 @@ struct ParticleIDWrapper AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE ParticleIDWrapper& operator= (const ParticleIDWrapper& pidw) noexcept { - return this->operator=(Long(pidw)); // NOLINT(cppcoreguidelines-c-copy-assignment-signature) + return this->operator=(Long(pidw)); // NOLINT } AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE @@ -123,7 +123,7 @@ struct ParticleCPUWrapper AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE ParticleCPUWrapper& operator= (const ParticleCPUWrapper& pcpuw) noexcept { - return this->operator=(int(pcpuw)); // NOLINT(cppcoreguidelines-c-copy-assignment-signature) + return this->operator=(int(pcpuw)); // NOLINT } AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE @@ -441,8 +441,9 @@ Particle::NextID () #endif next = the_next_id++; - if (next > LongParticleIds::LastParticleID) + if (next > LongParticleIds::LastParticleID) { amrex::Abort("Particle::NextID() -- too many particles"); + } return next; } @@ -452,8 +453,9 @@ Long Particle::UnprotectedNextID () { Long next = the_next_id++; - if (next > LongParticleIds::LastParticleID) + if (next > LongParticleIds::LastParticleID) { amrex::Abort("Particle::NextID() -- too many particles"); + } return next; } @@ -471,17 +473,21 @@ operator<< (std::ostream& os, const Particle& p) os << p.id() << ' ' << p.cpu() << ' '; - for (int i = 0; i < AMREX_SPACEDIM; i++) + for (int i = 0; i < AMREX_SPACEDIM; i++) { os << p.pos(i) << ' '; + } - for (int i = 0; i < NReal; i++) + for (int i = 0; i < NReal; i++) { os << p.rdata(i) << ' '; + } - for (int i = 0; i < NInt; i++) + for (int i = 0; i < NInt; i++) { os << p.idata(i) << ' '; + } - if (!os.good()) + if (!os.good()) { amrex::Error("operator<<(ostream&,Particle&) failed"); + } return os; } @@ -493,14 +499,17 @@ operator<< (std::ostream& os, const Particle& p) os << p.id() << ' ' << p.cpu() << ' '; - for (int i = 0; i < AMREX_SPACEDIM; i++) + for (int i = 0; i < AMREX_SPACEDIM; i++) { os << p.pos(i) << ' '; + } - for (int i = 0; i < NReal; i++) + for (int i = 0; i < NReal; i++) { os << p.rdata(i) << ' '; + } - if (!os.good()) + if (!os.good()) { amrex::Error("operator<<(ostream&,Particle&) failed"); + } return os; } @@ -512,14 +521,17 @@ operator<< (std::ostream& os, const Particle<0, NInt>& p) os << p.id() << ' ' << p.cpu() << ' '; - for (int i = 0; i < AMREX_SPACEDIM; i++) + for (int i = 0; i < AMREX_SPACEDIM; i++) { os << p.pos(i) << ' '; + } - for (int i = 0; i < NInt; i++) + for (int i = 0; i < NInt; i++) { os << p.idata(i) << ' '; + } - if (!os.good()) + if (!os.good()) { amrex::Error("operator<<(ostream&,Particle&) failed"); + } return os; } @@ -531,11 +543,13 @@ operator<< (std::ostream& os, const Particle<0, 0>& p) os << p.id() << ' ' << p.cpu() << ' '; - for (int i = 0; i < AMREX_SPACEDIM; i++) + for (int i = 0; i < AMREX_SPACEDIM; i++) { os << p.pos(i) << ' '; + } - if (!os.good()) + if (!os.good()) { amrex::Error("operator<<(ostream&,Particle&) failed"); + } return os; } diff --git a/Src/Particle/AMReX_ParticleArray.H b/Src/Particle/AMReX_ParticleArray.H index 8b7b4425210..0079d573620 100644 --- a/Src/Particle/AMReX_ParticleArray.H +++ b/Src/Particle/AMReX_ParticleArray.H @@ -83,7 +83,7 @@ struct DataLayoutPolicy, DataLayout::AoS> static constexpr raw_type get_raw_data (container_type& a_container) { - return raw_type(static_cast*>(&a_container[0])); + return raw_type(static_cast*>(a_container.data())); } static constexpr void resize (container_type& a_container, std::size_t a_size) diff --git a/Src/Particle/AMReX_ParticleBufferMap.cpp b/Src/Particle/AMReX_ParticleBufferMap.cpp index 86686ec87b1..a342a1ff86b 100644 --- a/Src/Particle/AMReX_ParticleBufferMap.cpp +++ b/Src/Particle/AMReX_ParticleBufferMap.cpp @@ -57,15 +57,15 @@ void ParticleBufferMap::define (const ParGDBBase* a_gdb) { int pid_a = std::get<2>(a); int pid_b = std::get<2>(b); - if (pid_a != pid_b) return pid_a < pid_b; + if (pid_a != pid_b) { return pid_a < pid_b; } int lev_a = std::get<1>(a); int lev_b = std::get<1>(b); - if (lev_a != lev_b) return lev_a < lev_b; + if (lev_a != lev_b) { return lev_a < lev_b; } int gid_a = std::get<0>(a); int gid_b = std::get<0>(b); - if (gid_a != gid_b) return gid_a < gid_b; + if (gid_a != gid_b) { return gid_a < gid_b; } return false; }); @@ -93,8 +93,9 @@ void ParticleBufferMap::define (const ParGDBBase* a_gdb) m_proc_box_offsets.resize(0); m_proc_box_offsets.push_back(0); - for (auto count : m_proc_box_counts) + for (auto count : m_proc_box_counts) { m_proc_box_offsets.push_back(m_proc_box_offsets.back() + count); + } d_bucket_to_pid.resize(0); d_bucket_to_pid.resize(num_buckets); @@ -113,10 +114,10 @@ void ParticleBufferMap::define (const ParGDBBase* a_gdb) bool ParticleBufferMap::isValid (const ParGDBBase* a_gdb) const { - if (!m_defined) return false; + if (!m_defined) { return false; } int num_levs = a_gdb->finestLevel() + 1; - if (num_levs != m_ba.size()) return false; + if (num_levs != m_ba.size()) { return false; } bool valid = true; for (int lev = 0; lev < num_levs; ++lev) diff --git a/Src/Particle/AMReX_ParticleCommunication.H b/Src/Particle/AMReX_ParticleCommunication.H index 924fc894a89..36ecb747e4b 100644 --- a/Src/Particle/AMReX_ParticleCommunication.H +++ b/Src/Particle/AMReX_ParticleCommunication.H @@ -37,8 +37,9 @@ struct RedistributeUnpackPolicy int N = static_cast(sizes.size()); std::map tile_sizes; - for(int i = 0; i < N; ++i) + for(int i = 0; i < N; ++i) { tile_sizes[tiles[i]] = tiles[i]->numParticles(); + } for(int i = 0; i < N; ++i) { @@ -46,8 +47,9 @@ struct RedistributeUnpackPolicy tile_sizes[tiles[i]] += sizes[i]; } - for (auto& kv : tile_sizes) + for (auto& kv : tile_sizes) { kv.first->resize(kv.second); + } } }; @@ -66,7 +68,7 @@ struct ParticleCopyOp [[nodiscard]] int numCopies (int gid, int lev) const { - if (m_boxes.size() <= lev) return 0; + if (m_boxes.size() <= lev) { return 0; } auto mit = m_boxes[lev].find(gid); return mit == m_boxes[lev].end() ? 0 : int(mit->second.size()); } @@ -160,7 +162,7 @@ struct ParticleCopyPlan { int gid = kv.first.first; int num_copies = op.numCopies(gid, lev); - if (num_copies == 0) continue; + if (num_copies == 0) { continue; } m_dst_indices[lev][gid].resize(num_copies); const auto* p_boxes = op.m_boxes[lev].at(gid).dataPtr(); @@ -337,7 +339,7 @@ void packBuffer (const PC& pc, const ParticleCopyOp& op, const ParticleCopyPlan& const auto ptd = src_tile.getConstParticleTileData(); int num_copies = op.numCopies(gid, lev); - if (num_copies == 0) continue; + if (num_copies == 0) { continue; } const auto* p_boxes = op.m_boxes[lev].at(gid).dataPtr(); const auto* p_levels = op.m_levels[lev].at(gid).dataPtr(); @@ -370,11 +372,12 @@ void packBuffer (const PC& pc, const ParticleCopyOp& op, const ParticleCopyPlan& AMREX_SPACEDIM*sizeof(ParticleReal)); for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { - if (! is_per[idim]) continue; - if (pshift[idim] > 0) + if (! is_per[idim]) { continue; } + if (pshift[idim] > 0) { pos[idim] += phi[idim] - plo[idim]; - else if (pshift[idim] < 0) + } else if (pshift[idim] < 0) { pos[idim] -= phi[idim] - plo[idim]; + } } amrex::Gpu::memcpy(&p_snd_buffer[dst_offset], &pos[0], AMREX_SPACEDIM*sizeof(ParticleReal)); @@ -461,7 +464,7 @@ void communicateParticlesStart (const PC& pc, ParticleCopyPlan& plan, const SndB const int NProcs = ParallelContext::NProcsSub(); const int MyProc = ParallelContext::MyProcSub(); - if (NProcs == 1) return; + if (NProcs == 1) { return; } Vector RcvProc; Vector rOffset; @@ -519,15 +522,15 @@ void communicateParticlesStart (const PC& pc, ParticleCopyPlan& plan, const SndB ParallelDescriptor::Arecv((char*) (rcv_buffer.dataPtr() + offset), Cnt, Who, SeqNum, ParallelContext::CommunicatorSub()).req(); } - if (plan.m_NumSnds == 0) return; + if (plan.m_NumSnds == 0) { return; } // Send. for (int i = 0; i < NProcs; ++i) { - if (i == MyProc) continue; + if (i == MyProc) { continue; } const auto Who = i; const auto Cnt = plan.m_snd_counts[i]; - if (Cnt == 0) continue; + if (Cnt == 0) { continue; } auto snd_offset = plan.m_snd_offsets[i]; AMREX_ASSERT(plan.m_snd_counts[i] % ParallelDescriptor::alignof_comm_data(plan.m_snd_num_particles[i]*psize) == 0); @@ -554,7 +557,7 @@ void unpackRemotes (PC& pc, const ParticleCopyPlan& plan, Buffer& rcv_buffer, Un #ifdef AMREX_USE_MPI const int NProcs = ParallelContext::NProcsSub(); - if (NProcs == 1) return; + if (NProcs == 1) { return; } const int MyProc = ParallelContext::MyProcSub(); amrex::ignore_unused(MyProc); diff --git a/Src/Particle/AMReX_ParticleCommunication.cpp b/Src/Particle/AMReX_ParticleCommunication.cpp index 474c8adc40e..6558c30e3fa 100644 --- a/Src/Particle/AMReX_ParticleCommunication.cpp +++ b/Src/Particle/AMReX_ParticleCommunication.cpp @@ -54,7 +54,7 @@ void ParticleCopyPlan::buildMPIStart (const ParticleBufferMap& map, Long psize) const int MyProc = ParallelContext::MyProcSub(); const auto NNeighborProcs = static_cast(m_neighbor_procs.size()); - if (NProcs == 1) return; + if (NProcs == 1) { return; } m_Snds.resize(0); m_Snds.resize(NProcs, 0); @@ -81,9 +81,9 @@ void ParticleCopyPlan::buildMPIStart (const ParticleBufferMap& map, Long psize) int lev = map.bucketToLevel(bucket); AMREX_ASSERT(m_box_counts_h[bucket] <= static_cast(std::numeric_limits::max())); int npart = static_cast(m_box_counts_h[bucket]); - if (npart == 0) continue; + if (npart == 0) { continue; } m_snd_num_particles[i] += npart; - if (i == MyProc) continue; + if (i == MyProc) { continue; } snd_data[i].push_back(npart); snd_data[i].push_back(dst); snd_data[i].push_back(lev); @@ -160,10 +160,10 @@ void ParticleCopyPlan::buildMPIStart (const ParticleBufferMap& map, Long psize) for (auto i : m_neighbor_procs) { - if (i == MyProc) continue; + if (i == MyProc) { continue; } const auto Who = i; const auto Cnt = m_Snds[i]; - if (Cnt == 0) continue; + if (Cnt == 0) { continue; } AMREX_ASSERT(Cnt > 0); AMREX_ASSERT(Who >= 0 && Who < NProcs); @@ -212,7 +212,7 @@ void ParticleCopyPlan::buildMPIFinish (const ParticleBufferMap& map) // NOLINT(r #ifdef AMREX_USE_MPI const int NProcs = ParallelContext::NProcsSub(); - if (NProcs == 1) return; + if (NProcs == 1) { return; } if (m_nrcvs > 0) { @@ -255,8 +255,8 @@ void ParticleCopyPlan::buildMPIFinish (const ParticleBufferMap& map) // NOLINT(r void ParticleCopyPlan::doHandShake (const Vector& Snds, Vector& Rcvs) const // NOLINT(readability-convert-member-functions-to-static) { BL_PROFILE("ParticleCopyPlan::doHandShake"); - if (m_local) doHandShakeLocal(Snds, Rcvs); - else doHandShakeGlobal(Snds, Rcvs); + if (m_local) { doHandShakeLocal(Snds, Rcvs); } + else { doHandShakeGlobal(Snds, Rcvs); } } void ParticleCopyPlan::doHandShakeLocal (const Vector& Snds, Vector& Rcvs) const // NOLINT(readability-convert-member-functions-to-static) @@ -331,7 +331,7 @@ void ParticleCopyPlan::doHandShakeGlobal (const Vector& Snds, Vector Vector snd_connectivity(NProcs, 0); Vector rcv_connectivity(NProcs, 1); - for (int i = 0; i < NProcs; ++i) { if (Snds[i] > 0) snd_connectivity[i] = 1; } + for (int i = 0; i < NProcs; ++i) { if (Snds[i] > 0) { snd_connectivity[i] = 1; } } Long num_rcvs = 0; MPI_Reduce_scatter(snd_connectivity.data(), &num_rcvs, rcv_connectivity.data(), @@ -349,7 +349,7 @@ void ParticleCopyPlan::doHandShakeGlobal (const Vector& Snds, Vector } for (int i = 0; i < NProcs; ++i) { - if (Snds[i] == 0) continue; + if (Snds[i] == 0) { continue; } const Long Cnt = 1; MPI_Send( &Snds[i], Cnt, ParallelDescriptor::Mpi_typemap::type(), i, SeqNum, ParallelContext::CommunicatorSub()); diff --git a/Src/Particle/AMReX_ParticleContainerBase.cpp b/Src/Particle/AMReX_ParticleContainerBase.cpp index 7583302c8f5..7b405681e4d 100644 --- a/Src/Particle/AMReX_ParticleContainerBase.cpp +++ b/Src/Particle/AMReX_ParticleContainerBase.cpp @@ -53,7 +53,7 @@ void ParticleContainerBase::resizeData () void ParticleContainerBase::RedefineDummyMF (int lev) { - if (lev > m_dummy_mf.size()-1) m_dummy_mf.resize(lev+1); + if (lev > m_dummy_mf.size()-1) { m_dummy_mf.resize(lev+1); } if (m_dummy_mf[lev] == nullptr || ! BoxArray::SameRefs(m_dummy_mf[lev]->boxArray(), @@ -319,8 +319,9 @@ void ParticleContainerBase::BuildRedistributeMask (int lev, int nghost) const { const int global_rank = this->ParticleDistributionMap(lev)[grid]; const int rank = ParallelContext::global_to_local_rank(global_rank); - if (rank != ParallelContext::MyProcSub()) + if (rank != ParallelContext::MyProcSub()) { neighbor_procs.push_back(rank); + } } } } diff --git a/Src/Particle/AMReX_ParticleContainerI.H b/Src/Particle/AMReX_ParticleContainerI.H index 9712a13a415..377d87e21e8 100644 --- a/Src/Particle/AMReX_ParticleContainerI.H +++ b/Src/Particle/AMReX_ParticleContainerI.H @@ -48,7 +48,7 @@ ParticleContainer_impl :: Initia pp.queryAdd("do_tiling", do_tiling); Vector tilesize(AMREX_SPACEDIM); if (pp.queryarr("tile_size", tilesize, 0, AMREX_SPACEDIM)) { - for (int i=0; i::value, @@ -97,8 +97,9 @@ ParticleContainer_impl AMREX_ASSERT(m_gdb != nullptr); - if (lev_max == -1) + if (lev_max == -1) { lev_max = finestLevel(); + } AMREX_ASSERT(lev_max <= finestLevel()); @@ -176,10 +177,11 @@ ParticleContainer_impl AMREX_ASSERT(m_gdb != nullptr); - if (!Geom(0).isAnyPeriodic()) return false; + if (!Geom(0).isAnyPeriodic()) { return false; } - if (lev_max == -1) + if (lev_max == -1) { lev_max = finestLevel(); + } AMREX_ASSERT(lev_max <= finestLevel()); @@ -411,7 +413,7 @@ ParticleContainer_impl::NumberOf { ParallelDescriptor::GatherLayoutDataToVector(np_per_grid_local, nparticles, ParallelContext::IOProcessorNumberSub()); - ParallelDescriptor::Bcast(&nparticles[0], nparticles.size(), + ParallelDescriptor::Bcast(nparticles.data(), nparticles.size(), ParallelContext::IOProcessorNumberSub()); } @@ -424,7 +426,7 @@ Long ParticleContainer_impl::Num { Long nparticles = 0; - if (level < 0 || level >= int(m_particles.size())) return nparticles; + if (level < 0 || level >= int(m_particles.size())) { return nparticles; } if (only_valid) { ReduceOps reduce_op; @@ -575,7 +577,7 @@ ParticleContainer_impl::Incremen BL_PROFILE("ParticleContainer::Increment"); AMREX_ASSERT(OK()); - if (m_particles.empty()) return; + if (m_particles.empty()) { return; } AMREX_ASSERT(lev >= 0 && lev < int(m_particles.size())); AMREX_ASSERT(numParticlesOutOfRange(*this, 0) == 0); @@ -609,7 +611,7 @@ void ParticleContainer_impl::RemoveParticlesAtLevel (int level) { BL_PROFILE("ParticleContainer::RemoveParticlesAtLevel()"); - if (level >= int(this->m_particles.size())) return; + if (level >= int(this->m_particles.size())) { return; } if (!this->m_particles[level].empty()) { @@ -1038,12 +1040,12 @@ addParticles (const PCType& other, F&& f, bool local) for(MFIter mfi = other.MakeMFIter(lev); mfi.isValid(); ++mfi) { auto index = std::make_pair(mfi.index(), mfi.LocalTileIndex()); - if(plevel_other.find(index) == plevel_other.end()) continue; + if(plevel_other.find(index) == plevel_other.end()) { continue; } auto& ptile = DefineAndReturnParticleTile(lev, mfi.index(), mfi.LocalTileIndex()); const auto& ptile_other = plevel_other.at(index); auto np = ptile_other.numParticles(); - if (np == 0) continue; + if (np == 0) { continue; } auto dst_index = ptile.numParticles(); ptile.resize(dst_index + np); @@ -1054,7 +1056,7 @@ addParticles (const PCType& other, F&& f, bool local) } } - if (! local) Redistribute(); + if (! local) { Redistribute(); } } // @@ -1175,7 +1177,7 @@ ParticleContainer_impl { BL_PROFILE("ParticleContainer::SortParticlesByBin()"); - if (bin_size == IntVect::TheZeroVector()) return; + if (bin_size == IntVect::TheZeroVector()) { return; } for (int lev = 0; lev < numLevels(); ++lev) { @@ -1238,7 +1240,7 @@ ParticleContainer_impl { #ifdef AMREX_USE_GPU - if (local) AMREX_ASSERT(numParticlesOutOfRange(*this, lev_min, lev_max, local) == 0); + if (local) { AMREX_ASSERT(numParticlesOutOfRange(*this, lev_min, lev_max, local) == 0); } // sanity check AMREX_ALWAYS_ASSERT(do_tiling == false); @@ -1272,7 +1274,7 @@ ParticleContainer_impl this->defineBufferMap(); - if (! m_particle_locator.isValid(GetParGDB())) m_particle_locator.build(GetParGDB()); + if (! m_particle_locator.isValid(GetParGDB())) { m_particle_locator.build(GetParGDB()); } m_particle_locator.setGeometry(GetParGDB()); auto assign_grid = m_particle_locator.getGridAssignor(); @@ -1423,475 +1425,491 @@ void ParticleContainer_impl ::RedistributeCPU (int lev_min, int lev_max, int nGrow, int local, bool remove_negative) { - BL_PROFILE("ParticleContainer::RedistributeCPU()"); + BL_PROFILE("ParticleContainer::RedistributeCPU()"); - const int MyProc = ParallelContext::MyProcSub(); - auto strttime = amrex::second(); + const int MyProc = ParallelContext::MyProcSub(); + auto strttime = amrex::second(); - if (local > 0) BuildRedistributeMask(0, local); + if (local > 0) { BuildRedistributeMask(0, local); } - // On startup there are cases where Redistribute() could be called - // with a given finestLevel() where that AmrLevel has yet to be defined. - int theEffectiveFinestLevel = m_gdb->finestLevel(); + // On startup there are cases where Redistribute() could be called + // with a given finestLevel() where that AmrLevel has yet to be defined. + int theEffectiveFinestLevel = m_gdb->finestLevel(); - while (!m_gdb->LevelDefined(theEffectiveFinestLevel)) - theEffectiveFinestLevel--; + while (!m_gdb->LevelDefined(theEffectiveFinestLevel)) { + theEffectiveFinestLevel--; + } - if (int(m_particles.size()) < theEffectiveFinestLevel+1) { - if (Verbose()) { - amrex::Print() << "ParticleContainer::Redistribute() resizing containers from " - << m_particles.size() << " to " - << theEffectiveFinestLevel + 1 << '\n'; - } - m_particles.resize(theEffectiveFinestLevel+1); - m_dummy_mf.resize(theEffectiveFinestLevel+1); - } + if (int(m_particles.size()) < theEffectiveFinestLevel+1) { + if (Verbose()) { + amrex::Print() << "ParticleContainer::Redistribute() resizing containers from " + << m_particles.size() << " to " + << theEffectiveFinestLevel + 1 << '\n'; + } + m_particles.resize(theEffectiveFinestLevel+1); + m_dummy_mf.resize(theEffectiveFinestLevel+1); + } - // It is important to do this even if we don't have more levels because we may have changed the - // grids at this level in a regrid. - for (int lev = 0; lev < theEffectiveFinestLevel+1; ++lev) - RedefineDummyMF(lev); + // It is important to do this even if we don't have more levels because we may have changed the + // grids at this level in a regrid. + for (int lev = 0; lev < theEffectiveFinestLevel+1; ++lev) { + RedefineDummyMF(lev); + } - int finest_lev_particles; - if (lev_max == -1) { - lev_max = theEffectiveFinestLevel; - finest_lev_particles = m_particles.size() - 1; - } else { - finest_lev_particles = lev_max; - } - AMREX_ASSERT(lev_max <= finestLevel()); + int finest_lev_particles; + if (lev_max == -1) { + lev_max = theEffectiveFinestLevel; + finest_lev_particles = m_particles.size() - 1; + } else { + finest_lev_particles = lev_max; + } + AMREX_ASSERT(lev_max <= finestLevel()); - // This will hold the valid particles that go to another process - std::map > not_ours; - - int num_threads = OpenMP::get_max_threads(); - - // these are temporary buffers for each thread - std::map > > tmp_remote; - Vector, Vector > > tmp_local; - Vector, Vector > > > soa_local; - tmp_local.resize(theEffectiveFinestLevel+1); - soa_local.resize(theEffectiveFinestLevel+1); - - // we resize these buffers outside the parallel region - for (int lev = lev_min; lev <= lev_max; lev++) { - for (MFIter mfi(*m_dummy_mf[lev], this->do_tiling ? this->tile_size : IntVect::TheZeroVector()); - mfi.isValid(); ++mfi) { - auto index = std::make_pair(mfi.index(), mfi.LocalTileIndex()); - tmp_local[lev][index].resize(num_threads); - soa_local[lev][index].resize(num_threads); - for (int t = 0; t < num_threads; ++t) { - soa_local[lev][index][t].define(m_num_runtime_real, m_num_runtime_int); - } - } - } - if (local) { - for (int i = 0; i < neighbor_procs.size(); ++i) - tmp_remote[neighbor_procs[i]].resize(num_threads); - } else { - for (int i = 0; i < ParallelContext::NProcsSub(); ++i) - tmp_remote[i].resize(num_threads); - } + // This will hold the valid particles that go to another process + std::map > not_ours; - // first pass: for each tile in parallel, in each thread copies the particles that - // need to be moved into it's own, temporary buffer. - for (int lev = lev_min; lev <= finest_lev_particles; lev++) { - auto& pmap = m_particles[lev]; + int num_threads = OpenMP::get_max_threads(); - Vector > grid_tile_ids; - Vector ptile_ptrs; - for (auto& kv : pmap) - { - grid_tile_ids.push_back(kv.first); - ptile_ptrs.push_back(&(kv.second)); - } + // these are temporary buffers for each thread + std::map > > tmp_remote; + Vector, Vector > > tmp_local; + Vector, Vector > > > soa_local; + tmp_local.resize(theEffectiveFinestLevel+1); + soa_local.resize(theEffectiveFinestLevel+1); + + // we resize these buffers outside the parallel region + for (int lev = lev_min; lev <= lev_max; lev++) { + for (MFIter mfi(*m_dummy_mf[lev], this->do_tiling ? this->tile_size : IntVect::TheZeroVector()); + mfi.isValid(); ++mfi) { + auto index = std::make_pair(mfi.index(), mfi.LocalTileIndex()); + tmp_local[lev][index].resize(num_threads); + soa_local[lev][index].resize(num_threads); + for (int t = 0; t < num_threads; ++t) { + soa_local[lev][index][t].define(m_num_runtime_real, m_num_runtime_int); + } + } + } + if (local) { + for (int i = 0; i < neighbor_procs.size(); ++i) { + tmp_remote[neighbor_procs[i]].resize(num_threads); + } + } else { + for (int i = 0; i < ParallelContext::NProcsSub(); ++i) { + tmp_remote[i].resize(num_threads); + } + } + + // first pass: for each tile in parallel, in each thread copies the particles that + // need to be moved into it's own, temporary buffer. + for (int lev = lev_min; lev <= finest_lev_particles; lev++) { + auto& pmap = m_particles[lev]; + + Vector > grid_tile_ids; + Vector ptile_ptrs; + for (auto& kv : pmap) + { + grid_tile_ids.push_back(kv.first); + ptile_ptrs.push_back(&(kv.second)); + } #ifdef AMREX_USE_OMP #pragma omp parallel for #endif - for (int pmap_it = 0; pmap_it < static_cast(ptile_ptrs.size()); ++pmap_it) - { - int thread_num = OpenMP::get_thread_num(); - int grid = grid_tile_ids[pmap_it].first; - int tile = grid_tile_ids[pmap_it].second; - auto& soa = ptile_ptrs[pmap_it]->GetStructOfArrays(); - auto& aos = ptile_ptrs[pmap_it]->GetArrayOfStructs(); - - // AMREX_ASSERT_WITH_MESSAGE((NumRealComps() == 0 && NumIntComps() == 0) - // || aos.size() == soa.size(), - // "The AoS and SoA data on this tile are different sizes - " - // "perhaps particles have not been initialized correctly?"); - unsigned npart = ptile_ptrs[pmap_it]->numParticles(); - ParticleLocData pld; - - if constexpr(!ParticleType::is_soa_particle){ - - if (npart != 0) { - Long last = npart - 1; - Long pindex = 0; - while (pindex <= last) { - ParticleType& p = aos[pindex]; - - if ((remove_negative == false) && (p.id() < 0)) { - ++pindex; - continue; - } - - if (p.id() < 0) - { - aos[pindex] = aos[last]; - for (int comp = 0; comp < NumRealComps(); comp++) - soa.GetRealData(comp)[pindex] = soa.GetRealData(comp)[last]; - for (int comp = 0; comp < NumIntComps(); comp++) - soa.GetIntData(comp)[pindex] = soa.GetIntData(comp)[last]; - correctCellVectors(last, pindex, grid, aos[pindex]); - --last; - continue; - } - - locateParticle(p, pld, lev_min, lev_max, nGrow, local ? grid : -1); - - particlePostLocate(p, pld, lev); - - if (p.id() < 0) - { - aos[pindex] = aos[last]; - for (int comp = 0; comp < NumRealComps(); comp++) - soa.GetRealData(comp)[pindex] = soa.GetRealData(comp)[last]; - for (int comp = 0; comp < NumIntComps(); comp++) - soa.GetIntData(comp)[pindex] = soa.GetIntData(comp)[last]; - correctCellVectors(last, pindex, grid, aos[pindex]); - --last; - continue; - } - - const int who = ParallelContext::global_to_local_rank(ParticleDistributionMap(pld.m_lev)[pld.m_grid]); - if (who == MyProc) { - if (pld.m_lev != lev || pld.m_grid != grid || pld.m_tile != tile) { - // We own it but must shift it to another place. - auto index = std::make_pair(pld.m_grid, pld.m_tile); - AMREX_ASSERT(tmp_local[pld.m_lev][index].size() == num_threads); - tmp_local[pld.m_lev][index][thread_num].push_back(p); - for (int comp = 0; comp < NumRealComps(); ++comp) { - RealVector& arr = soa_local[pld.m_lev][index][thread_num].GetRealData(comp); - arr.push_back(soa.GetRealData(comp)[pindex]); + for (int pmap_it = 0; pmap_it < static_cast(ptile_ptrs.size()); ++pmap_it) + { + int thread_num = OpenMP::get_thread_num(); + int grid = grid_tile_ids[pmap_it].first; + int tile = grid_tile_ids[pmap_it].second; + auto& soa = ptile_ptrs[pmap_it]->GetStructOfArrays(); + auto& aos = ptile_ptrs[pmap_it]->GetArrayOfStructs(); + + // AMREX_ASSERT_WITH_MESSAGE((NumRealComps() == 0 && NumIntComps() == 0) + // || aos.size() == soa.size(), + // "The AoS and SoA data on this tile are different sizes - " + // "perhaps particles have not been initialized correctly?"); + unsigned npart = ptile_ptrs[pmap_it]->numParticles(); + ParticleLocData pld; + + if constexpr(!ParticleType::is_soa_particle){ + + if (npart != 0) { + Long last = npart - 1; + Long pindex = 0; + while (pindex <= last) { + ParticleType& p = aos[pindex]; + + if ((remove_negative == false) && (p.id() < 0)) { + ++pindex; + continue; + } + + if (p.id() < 0) + { + aos[pindex] = aos[last]; + for (int comp = 0; comp < NumRealComps(); comp++) { + soa.GetRealData(comp)[pindex] = soa.GetRealData(comp)[last]; + } + for (int comp = 0; comp < NumIntComps(); comp++) { + soa.GetIntData(comp)[pindex] = soa.GetIntData(comp)[last]; } - for (int comp = 0; comp < NumIntComps(); ++comp) { - IntVector& arr = soa_local[pld.m_lev][index][thread_num].GetIntData(comp); - arr.push_back(soa.GetIntData(comp)[pindex]); + correctCellVectors(last, pindex, grid, aos[pindex]); + --last; + continue; + } + + locateParticle(p, pld, lev_min, lev_max, nGrow, local ? grid : -1); + + particlePostLocate(p, pld, lev); + + if (p.id() < 0) + { + aos[pindex] = aos[last]; + for (int comp = 0; comp < NumRealComps(); comp++) { + soa.GetRealData(comp)[pindex] = soa.GetRealData(comp)[last]; + } + for (int comp = 0; comp < NumIntComps(); comp++) { + soa.GetIntData(comp)[pindex] = soa.GetIntData(comp)[last]; + } + correctCellVectors(last, pindex, grid, aos[pindex]); + --last; + continue; + } + + const int who = ParallelContext::global_to_local_rank(ParticleDistributionMap(pld.m_lev)[pld.m_grid]); + if (who == MyProc) { + if (pld.m_lev != lev || pld.m_grid != grid || pld.m_tile != tile) { + // We own it but must shift it to another place. + auto index = std::make_pair(pld.m_grid, pld.m_tile); + AMREX_ASSERT(tmp_local[pld.m_lev][index].size() == num_threads); + tmp_local[pld.m_lev][index][thread_num].push_back(p); + for (int comp = 0; comp < NumRealComps(); ++comp) { + RealVector& arr = soa_local[pld.m_lev][index][thread_num].GetRealData(comp); + arr.push_back(soa.GetRealData(comp)[pindex]); + } + for (int comp = 0; comp < NumIntComps(); ++comp) { + IntVector& arr = soa_local[pld.m_lev][index][thread_num].GetIntData(comp); + arr.push_back(soa.GetIntData(comp)[pindex]); } + p.id() = -p.id(); // Invalidate the particle + } + } + else { + auto& particles_to_send = tmp_remote[who][thread_num]; + auto old_size = particles_to_send.size(); + auto new_size = old_size + superparticle_size; + particles_to_send.resize(new_size); + std::memcpy(&particles_to_send[old_size], &p, particle_size); + char* dst = &particles_to_send[old_size] + particle_size; + int array_comp_start = AMREX_SPACEDIM + NStructReal; + for (int comp = 0; comp < NumRealComps(); comp++) { + if (h_redistribute_real_comp[array_comp_start + comp]) { + std::memcpy(dst, &soa.GetRealData(comp)[pindex], sizeof(ParticleReal)); + dst += sizeof(ParticleReal); + } + } + array_comp_start = 2 + NStructInt; + for (int comp = 0; comp < NumIntComps(); comp++) { + if (h_redistribute_int_comp[array_comp_start + comp]) { + std::memcpy(dst, &soa.GetIntData(comp)[pindex], sizeof(int)); + dst += sizeof(int); + } + } + p.id() = -p.id(); // Invalidate the particle - } - } - else { - auto& particles_to_send = tmp_remote[who][thread_num]; - auto old_size = particles_to_send.size(); - auto new_size = old_size + superparticle_size; - particles_to_send.resize(new_size); - std::memcpy(&particles_to_send[old_size], &p, particle_size); - char* dst = &particles_to_send[old_size] + particle_size; - int array_comp_start = AMREX_SPACEDIM + NStructReal; - for (int comp = 0; comp < NumRealComps(); comp++) { - if (h_redistribute_real_comp[array_comp_start + comp]) { - std::memcpy(dst, &soa.GetRealData(comp)[pindex], sizeof(ParticleReal)); - dst += sizeof(ParticleReal); - } - } - array_comp_start = 2 + NStructInt; - for (int comp = 0; comp < NumIntComps(); comp++) { - if (h_redistribute_int_comp[array_comp_start + comp]) { - std::memcpy(dst, &soa.GetIntData(comp)[pindex], sizeof(int)); - dst += sizeof(int); - } - } - - p.id() = -p.id(); // Invalidate the particle - } + } - if (p.id() < 0) - { - aos[pindex] = aos[last]; - for (int comp = 0; comp < NumRealComps(); comp++) - soa.GetRealData(comp)[pindex] = soa.GetRealData(comp)[last]; - for (int comp = 0; comp < NumIntComps(); comp++) - soa.GetIntData(comp)[pindex] = soa.GetIntData(comp)[last]; - correctCellVectors(last, pindex, grid, aos[pindex]); - --last; - continue; + if (p.id() < 0) + { + aos[pindex] = aos[last]; + for (int comp = 0; comp < NumRealComps(); comp++) { + soa.GetRealData(comp)[pindex] = soa.GetRealData(comp)[last]; + } + for (int comp = 0; comp < NumIntComps(); comp++) { + soa.GetIntData(comp)[pindex] = soa.GetIntData(comp)[last]; + } + correctCellVectors(last, pindex, grid, aos[pindex]); + --last; + continue; + } + + ++pindex; } - ++pindex; + aos().erase(aos().begin() + last + 1, aos().begin() + npart); + for (int comp = 0; comp < NumRealComps(); comp++) { + RealVector& rdata = soa.GetRealData(comp); + rdata.erase(rdata.begin() + last + 1, rdata.begin() + npart); + } + for (int comp = 0; comp < NumIntComps(); comp++) { + IntVector& idata = soa.GetIntData(comp); + idata.erase(idata.begin() + last + 1, idata.begin() + npart); + } } - aos().erase(aos().begin() + last + 1, aos().begin() + npart); - for (int comp = 0; comp < NumRealComps(); comp++) { - RealVector& rdata = soa.GetRealData(comp); - rdata.erase(rdata.begin() + last + 1, rdata.begin() + npart); - } - for (int comp = 0; comp < NumIntComps(); comp++) { - IntVector& idata = soa.GetIntData(comp); - idata.erase(idata.begin() + last + 1, idata.begin() + npart); - } - } + } else{ // soa particle - } else{ // soa particle + auto particle_tile = ptile_ptrs[pmap_it]; + if (npart != 0) { + Long last = npart - 1; + Long pindex = 0; + while (pindex <= last) { + auto ptd = particle_tile->getParticleTileData(); + ParticleType p(ptd,pindex); - auto particle_tile = ptile_ptrs[pmap_it]; - if (npart != 0) { - Long last = npart - 1; - Long pindex = 0; - while (pindex <= last) { - auto ptd = particle_tile->getParticleTileData(); - ParticleType p(ptd,pindex); + if ((remove_negative == false) && (p.id() < 0)) { + ++pindex; + continue; + } - if ((remove_negative == false) && (p.id() < 0)) { - ++pindex; - continue; - } + if (p.id() < 0){ + for (int comp = 0; comp < NumRealComps(); comp++) { + soa.GetRealData(comp)[pindex] = soa.GetRealData(comp)[last]; + } + for (int comp = 0; comp < NumIntComps(); comp++) { + soa.GetIntData(comp)[pindex] = soa.GetIntData(comp)[last]; + } + correctCellVectors(last, pindex, grid, aos[pindex]); + --last; + continue; + } - if (p.id() < 0){ - for (int comp = 0; comp < NumRealComps(); comp++) - soa.GetRealData(comp)[pindex] = soa.GetRealData(comp)[last]; - for (int comp = 0; comp < NumIntComps(); comp++) - soa.GetIntData(comp)[pindex] = soa.GetIntData(comp)[last]; - correctCellVectors(last, pindex, grid, aos[pindex]); - --last; - continue; - } + locateParticle(p, pld, lev_min, lev_max, nGrow, local ? grid : -1); - locateParticle(p, pld, lev_min, lev_max, nGrow, local ? grid : -1); + particlePostLocate(p, pld, lev); - particlePostLocate(p, pld, lev); + if (p.id() < 0) { + for (int comp = 0; comp < NumRealComps(); comp++) { + soa.GetRealData(comp)[pindex] = soa.GetRealData(comp)[last]; + } + for (int comp = 0; comp < NumIntComps(); comp++) { + soa.GetIntData(comp)[pindex] = soa.GetIntData(comp)[last]; + } + correctCellVectors(last, pindex, grid, aos[pindex]); + --last; + continue; + } - if (p.id() < 0) { - for (int comp = 0; comp < NumRealComps(); comp++) - soa.GetRealData(comp)[pindex] = soa.GetRealData(comp)[last]; - for (int comp = 0; comp < NumIntComps(); comp++) - soa.GetIntData(comp)[pindex] = soa.GetIntData(comp)[last]; - correctCellVectors(last, pindex, grid, aos[pindex]); - --last; - continue; - } + const int who = ParallelContext::global_to_local_rank(ParticleDistributionMap(pld.m_lev)[pld.m_grid]); + if (who == MyProc) { + if (pld.m_lev != lev || pld.m_grid != grid || pld.m_tile != tile) { + // We own it but must shift it to another place. + auto index = std::make_pair(pld.m_grid, pld.m_tile); + AMREX_ASSERT(soa_local[pld.m_lev][index].size() == num_threads); + for (int comp = 0; comp < NumRealComps(); ++comp) { + RealVector& arr = soa_local[pld.m_lev][index][thread_num].GetRealData(comp); + arr.push_back(soa.GetRealData(comp)[pindex]); + } + for (int comp = 0; comp < NumIntComps(); ++comp) { + IntVector& arr = soa_local[pld.m_lev][index][thread_num].GetIntData(comp); + arr.push_back(soa.GetIntData(comp)[pindex]); + } - const int who = ParallelContext::global_to_local_rank(ParticleDistributionMap(pld.m_lev)[pld.m_grid]); - if (who == MyProc) { - if (pld.m_lev != lev || pld.m_grid != grid || pld.m_tile != tile) { - // We own it but must shift it to another place. - auto index = std::make_pair(pld.m_grid, pld.m_tile); - AMREX_ASSERT(soa_local[pld.m_lev][index].size() == num_threads); - for (int comp = 0; comp < NumRealComps(); ++comp) { - RealVector& arr = soa_local[pld.m_lev][index][thread_num].GetRealData(comp); - arr.push_back(soa.GetRealData(comp)[pindex]); - } - for (int comp = 0; comp < NumIntComps(); ++comp) { - IntVector& arr = soa_local[pld.m_lev][index][thread_num].GetIntData(comp); - arr.push_back(soa.GetIntData(comp)[pindex]); - } - - p.id() = -p.id(); // Invalidate the particle - } - } - else { - auto& particles_to_send = tmp_remote[who][thread_num]; - auto old_size = particles_to_send.size(); - auto new_size = old_size + superparticle_size; - particles_to_send.resize(new_size); - - char* dst = &particles_to_send[old_size]; - int array_comp_start = AMREX_SPACEDIM + NStructReal; - for (int comp = 0; comp < NumRealComps(); comp++) { - if (h_redistribute_real_comp[array_comp_start + comp]) { - std::memcpy(dst, &soa.GetRealData(comp)[pindex], sizeof(ParticleReal)); - dst += sizeof(ParticleReal); - } + p.id() = -p.id(); // Invalidate the particle + } } - array_comp_start = 2 + NStructInt; - for (int comp = 0; comp < NumIntComps(); comp++) { - if (h_redistribute_int_comp[array_comp_start + comp]) { - std::memcpy(dst, &soa.GetIntData(comp)[pindex], sizeof(int)); - dst += sizeof(int); - } + else { + auto& particles_to_send = tmp_remote[who][thread_num]; + auto old_size = particles_to_send.size(); + auto new_size = old_size + superparticle_size; + particles_to_send.resize(new_size); + + char* dst = &particles_to_send[old_size]; + int array_comp_start = AMREX_SPACEDIM + NStructReal; + for (int comp = 0; comp < NumRealComps(); comp++) { + if (h_redistribute_real_comp[array_comp_start + comp]) { + std::memcpy(dst, &soa.GetRealData(comp)[pindex], sizeof(ParticleReal)); + dst += sizeof(ParticleReal); + } + } + array_comp_start = 2 + NStructInt; + for (int comp = 0; comp < NumIntComps(); comp++) { + if (h_redistribute_int_comp[array_comp_start + comp]) { + std::memcpy(dst, &soa.GetIntData(comp)[pindex], sizeof(int)); + dst += sizeof(int); + } + } + p.id() = -p.id(); // Invalidate the particle } - p.id() = -p.id(); // Invalidate the particle - } - if (p.id() < 0){ - for (int comp = 0; comp < NumRealComps(); comp++) - soa.GetRealData(comp)[pindex] = soa.GetRealData(comp)[last]; - for (int comp = 0; comp < NumIntComps(); comp++) - soa.GetIntData(comp)[pindex] = soa.GetIntData(comp)[last]; - correctCellVectors(last, pindex, grid, aos[pindex]); - --last; - continue; + if (p.id() < 0){ + for (int comp = 0; comp < NumRealComps(); comp++) { + soa.GetRealData(comp)[pindex] = soa.GetRealData(comp)[last]; + } + for (int comp = 0; comp < NumIntComps(); comp++) { + soa.GetIntData(comp)[pindex] = soa.GetIntData(comp)[last]; + } + correctCellVectors(last, pindex, grid, aos[pindex]); + --last; + continue; + } + + ++pindex; } - ++pindex; + for (int comp = 0; comp < NumRealComps(); comp++) { + RealVector& rdata = soa.GetRealData(comp); + rdata.erase(rdata.begin() + last + 1, rdata.begin() + npart); + } + for (int comp = 0; comp < NumIntComps(); comp++) { + IntVector& idata = soa.GetIntData(comp); + idata.erase(idata.begin() + last + 1, idata.begin() + npart); + } } + } + } + } - for (int comp = 0; comp < NumRealComps(); comp++) { - RealVector& rdata = soa.GetRealData(comp); - rdata.erase(rdata.begin() + last + 1, rdata.begin() + npart); - } - for (int comp = 0; comp < NumIntComps(); comp++) { - IntVector& idata = soa.GetIntData(comp); - idata.erase(idata.begin() + last + 1, idata.begin() + npart); - } - } - } - } - } - - for (int lev = lev_min; lev <= lev_max; lev++) { - particle_detail::clearEmptyEntries(m_particles[lev]); - } + for (int lev = lev_min; lev <= lev_max; lev++) { + particle_detail::clearEmptyEntries(m_particles[lev]); + } - // Second pass - for each tile in parallel, collect the particles we are owed from all thread's buffers. - for (int lev = lev_min; lev <= lev_max; lev++) { - typename std::map, Vector >::iterator pmap_it; + // Second pass - for each tile in parallel, collect the particles we are owed from all thread's buffers. + for (int lev = lev_min; lev <= lev_max; lev++) { + typename std::map, Vector >::iterator pmap_it; - if constexpr(!ParticleType::is_soa_particle) { - Vector > grid_tile_ids; - Vector* > pvec_ptrs; + if constexpr(!ParticleType::is_soa_particle) { + Vector > grid_tile_ids; + Vector* > pvec_ptrs; - // we need to create any missing map entries in serial here - for (pmap_it=tmp_local[lev].begin(); pmap_it != tmp_local[lev].end(); pmap_it++) - { - m_particles[lev][pmap_it->first]; - grid_tile_ids.push_back(pmap_it->first); - pvec_ptrs.push_back(&(pmap_it->second)); - } + // we need to create any missing map entries in serial here + for (pmap_it=tmp_local[lev].begin(); pmap_it != tmp_local[lev].end(); pmap_it++) + { + m_particles[lev][pmap_it->first]; + grid_tile_ids.push_back(pmap_it->first); + pvec_ptrs.push_back(&(pmap_it->second)); + } #ifdef AMREX_USE_OMP #pragma omp parallel for #endif - for (int pit = 0; pit < static_cast(pvec_ptrs.size()); ++pit) - { - auto index = grid_tile_ids[pit]; - auto& ptile = DefineAndReturnParticleTile(lev, index.first, index.second); - auto& aos = ptile.GetArrayOfStructs(); - auto& soa = ptile.GetStructOfArrays(); - auto& aos_tmp = *(pvec_ptrs[pit]); - auto& soa_tmp = soa_local[lev][index]; - for (int i = 0; i < num_threads; ++i) { - aos.insert(aos.end(), aos_tmp[i].begin(), aos_tmp[i].end()); - aos_tmp[i].erase(aos_tmp[i].begin(), aos_tmp[i].end()); - for (int comp = 0; comp < NumRealComps(); ++comp) { - RealVector& arr = soa.GetRealData(comp); - RealVector& tmp = soa_tmp[i].GetRealData(comp); - arr.insert(arr.end(), tmp.begin(), tmp.end()); - tmp.erase(tmp.begin(), tmp.end()); - } - for (int comp = 0; comp < NumIntComps(); ++comp) { - IntVector& arr = soa.GetIntData(comp); - IntVector& tmp = soa_tmp[i].GetIntData(comp); - arr.insert(arr.end(), tmp.begin(), tmp.end()); - tmp.erase(tmp.begin(), tmp.end()); - } - } - } - } else { // soa particle - Vector > grid_tile_ids; - - // we need to create any missing map entries in serial here - for (auto soa_map_it=soa_local[lev].begin(); soa_map_it != soa_local[lev].end(); soa_map_it++) - { - m_particles[lev][soa_map_it->first]; - grid_tile_ids.push_back(soa_map_it->first); - } + for (int pit = 0; pit < static_cast(pvec_ptrs.size()); ++pit) + { + auto index = grid_tile_ids[pit]; + auto& ptile = DefineAndReturnParticleTile(lev, index.first, index.second); + auto& aos = ptile.GetArrayOfStructs(); + auto& soa = ptile.GetStructOfArrays(); + auto& aos_tmp = *(pvec_ptrs[pit]); + auto& soa_tmp = soa_local[lev][index]; + for (int i = 0; i < num_threads; ++i) { + aos.insert(aos.end(), aos_tmp[i].begin(), aos_tmp[i].end()); + aos_tmp[i].erase(aos_tmp[i].begin(), aos_tmp[i].end()); + for (int comp = 0; comp < NumRealComps(); ++comp) { + RealVector& arr = soa.GetRealData(comp); + RealVector& tmp = soa_tmp[i].GetRealData(comp); + arr.insert(arr.end(), tmp.begin(), tmp.end()); + tmp.erase(tmp.begin(), tmp.end()); + } + for (int comp = 0; comp < NumIntComps(); ++comp) { + IntVector& arr = soa.GetIntData(comp); + IntVector& tmp = soa_tmp[i].GetIntData(comp); + arr.insert(arr.end(), tmp.begin(), tmp.end()); + tmp.erase(tmp.begin(), tmp.end()); + } + } + } + } else { // soa particle + Vector > grid_tile_ids; + + // we need to create any missing map entries in serial here + for (auto soa_map_it=soa_local[lev].begin(); soa_map_it != soa_local[lev].end(); soa_map_it++) + { + m_particles[lev][soa_map_it->first]; + grid_tile_ids.push_back(soa_map_it->first); + } #ifdef AMREX_USE_OMP #pragma omp parallel for #endif - for (int pit = 0; pit < static_cast(grid_tile_ids.size()); ++pit) - { - auto index = grid_tile_ids[pit]; - auto& ptile = DefineAndReturnParticleTile(lev, index.first, index.second); - auto& soa = ptile.GetStructOfArrays(); - auto& soa_tmp = soa_local[lev][index]; - for (int i = 0; i < num_threads; ++i) { - for (int comp = 0; comp < NumRealComps(); ++comp) { - RealVector& arr = soa.GetRealData(comp); - RealVector& tmp = soa_tmp[i].GetRealData(comp); - arr.insert(arr.end(), tmp.begin(), tmp.end()); - tmp.erase(tmp.begin(), tmp.end()); - } - for (int comp = 0; comp < NumIntComps(); ++comp) { - IntVector& arr = soa.GetIntData(comp); - IntVector& tmp = soa_tmp[i].GetIntData(comp); - arr.insert(arr.end(), tmp.begin(), tmp.end()); - tmp.erase(tmp.begin(), tmp.end()); - } - } - } - } - } + for (int pit = 0; pit < static_cast(grid_tile_ids.size()); ++pit) + { + auto index = grid_tile_ids[pit]; + auto& ptile = DefineAndReturnParticleTile(lev, index.first, index.second); + auto& soa = ptile.GetStructOfArrays(); + auto& soa_tmp = soa_local[lev][index]; + for (int i = 0; i < num_threads; ++i) { + for (int comp = 0; comp < NumRealComps(); ++comp) { + RealVector& arr = soa.GetRealData(comp); + RealVector& tmp = soa_tmp[i].GetRealData(comp); + arr.insert(arr.end(), tmp.begin(), tmp.end()); + tmp.erase(tmp.begin(), tmp.end()); + } + for (int comp = 0; comp < NumIntComps(); ++comp) { + IntVector& arr = soa.GetIntData(comp); + IntVector& tmp = soa_tmp[i].GetIntData(comp); + arr.insert(arr.end(), tmp.begin(), tmp.end()); + tmp.erase(tmp.begin(), tmp.end()); + } + } + } + } + } - for (auto& map_it : tmp_remote) { - int who = map_it.first; - not_ours[who]; - } + for (auto& map_it : tmp_remote) { + int who = map_it.first; + not_ours[who]; + } - Vector dest_proc_ids; - Vector >* > pbuff_ptrs; - for (auto& kv : tmp_remote) - { - dest_proc_ids.push_back(kv.first); - pbuff_ptrs.push_back(&(kv.second)); - } + Vector dest_proc_ids; + Vector >* > pbuff_ptrs; + for (auto& kv : tmp_remote) + { + dest_proc_ids.push_back(kv.first); + pbuff_ptrs.push_back(&(kv.second)); + } #ifdef AMREX_USE_OMP #pragma omp parallel for #endif - for (int pmap_it = 0; pmap_it < static_cast(pbuff_ptrs.size()); ++pmap_it) - { - int who = dest_proc_ids[pmap_it]; - Vector >& tmp = *(pbuff_ptrs[pmap_it]); - for (int i = 0; i < num_threads; ++i) { - not_ours[who].insert(not_ours[who].end(), tmp[i].begin(), tmp[i].end()); - tmp[i].erase(tmp[i].begin(), tmp[i].end()); - } - } + for (int pmap_it = 0; pmap_it < static_cast(pbuff_ptrs.size()); ++pmap_it) + { + int who = dest_proc_ids[pmap_it]; + Vector >& tmp = *(pbuff_ptrs[pmap_it]); + for (int i = 0; i < num_threads; ++i) { + not_ours[who].insert(not_ours[who].end(), tmp[i].begin(), tmp[i].end()); + tmp[i].erase(tmp[i].begin(), tmp[i].end()); + } + } - particle_detail::clearEmptyEntries(not_ours); + particle_detail::clearEmptyEntries(not_ours); - if (int(m_particles.size()) > theEffectiveFinestLevel+1) { - // Looks like we lost an AmrLevel on a regrid. - if (m_verbose > 0) { - amrex::Print() << "ParticleContainer::Redistribute() resizing m_particles from " - << m_particles.size() << " to " << theEffectiveFinestLevel+1 << '\n'; - } - AMREX_ASSERT(int(m_particles.size()) >= 2); + if (int(m_particles.size()) > theEffectiveFinestLevel+1) { + // Looks like we lost an AmrLevel on a regrid. + if (m_verbose > 0) { + amrex::Print() << "ParticleContainer::Redistribute() resizing m_particles from " + << m_particles.size() << " to " << theEffectiveFinestLevel+1 << '\n'; + } + AMREX_ASSERT(int(m_particles.size()) >= 2); - m_particles.resize(theEffectiveFinestLevel + 1); - m_dummy_mf.resize(theEffectiveFinestLevel + 1); - } + m_particles.resize(theEffectiveFinestLevel + 1); + m_dummy_mf.resize(theEffectiveFinestLevel + 1); + } - if (ParallelContext::NProcsSub() == 1) { - AMREX_ASSERT(not_ours.empty()); - } - else { - RedistributeMPI(not_ours, lev_min, lev_max, nGrow, local); - } + if (ParallelContext::NProcsSub() == 1) { + AMREX_ASSERT(not_ours.empty()); + } + else { + RedistributeMPI(not_ours, lev_min, lev_max, nGrow, local); + } - AMREX_ASSERT(OK(lev_min, lev_max, nGrow)); + AMREX_ASSERT(OK(lev_min, lev_max, nGrow)); - if (m_verbose > 0) { - auto stoptime = amrex::second() - strttime; + if (m_verbose > 0) { + auto stoptime = amrex::second() - strttime; - ByteSpread(); + ByteSpread(); #ifdef AMREX_LAZY - Lazy::QueueReduction( [=] () mutable { + Lazy::QueueReduction( [=] () mutable { #endif - ParallelReduce::Max(stoptime, ParallelContext::IOProcessorNumberSub(), - ParallelContext::CommunicatorSub()); + ParallelReduce::Max(stoptime, ParallelContext::IOProcessorNumberSub(), + ParallelContext::CommunicatorSub()); - amrex::Print() << "ParticleContainer::Redistribute() time: " << stoptime << "\n\n"; + amrex::Print() << "ParticleContainer::Redistribute() time: " << stoptime << "\n\n"; #ifdef AMREX_LAZY - }); + }); #endif - } + } } template >& not_ours, const int SeqNum = ParallelDescriptor::SeqNum(); - if ((! local) && NumSnds == 0) + if ((! local) && NumSnds == 0) { return; // There's no parallel work to do. + } if (local) { @@ -2227,8 +2246,9 @@ ParticleContainer_impl::OK (int { BL_PROFILE("ParticleContainer::OK()"); - if (lev_max == -1) + if (lev_max == -1) { lev_max = finestLevel(); +} return (numParticlesOutOfRange(*this, lev_min, lev_max, nGrow) == 0); } @@ -2291,7 +2311,7 @@ AssignCellDensitySingleLevel (int rho_index, { BL_PROFILE("ParticleContainer::AssignCellDensitySingleLevel()"); - if (rho_index != 0) amrex::Abort("AssignCellDensitySingleLevel only works if rho_index = 0"); + if (rho_index != 0) { amrex::Abort("AssignCellDensitySingleLevel only works if rho_index = 0"); } MultiFab* mf_pointer; @@ -2312,8 +2332,9 @@ AssignCellDensitySingleLevel (int rho_index, // its effect to an adjacent grid by first putting the value into ghost cells of its // own grid. The mf->SumBoundary call then adds the value from one grid's ghost cell // to another grid's valid region. - if (mf_pointer->nGrow() < 1) + if (mf_pointer->nGrow() < 1) { amrex::Error("Must have at least one ghost cell when in AssignCellDensitySingleLevel"); + } const auto strttime = amrex::second(); @@ -2438,8 +2459,9 @@ InterpolateSingleLevel (MultiFab& mesh_data, int lev) { BL_PROFILE("ParticleContainer::InterpolateSingleLevel()"); - if (mesh_data.nGrow() < 1) + if (mesh_data.nGrow() < 1) { amrex::Error("Must have at least one ghost cell when in InterpolateSingleLevel"); + } const Geometry& gm = Geom(lev); const auto plo = gm.ProbLoArray(); diff --git a/Src/Particle/AMReX_ParticleIO.H b/Src/Particle/AMReX_ParticleIO.H index 4417385d39f..d23fde9d1dd 100644 --- a/Src/Particle/AMReX_ParticleIO.H +++ b/Src/Particle/AMReX_ParticleIO.H @@ -129,10 +129,14 @@ ParticleContainer_impl AMREX_ASSERT( int_comp_names.size() == NStructInt + NumIntComps() ); Vector write_real_comp; - for (int i = 0; i < NStructReal + NumRealComps(); ++i) write_real_comp.push_back(1); + for (int i = 0; i < NStructReal + NumRealComps(); ++i) { + write_real_comp.push_back(1); + } Vector write_int_comp; - for (int i = 0; i < NStructInt + NumIntComps(); ++i) write_int_comp.push_back(1); + for (int i = 0; i < NStructInt + NumIntComps(); ++i) { + write_int_comp.push_back(1); + } WriteBinaryParticleData(dir, name, write_real_comp, write_int_comp, @@ -153,10 +157,14 @@ ParticleContainer_impl AMREX_ASSERT(real_comp_names.size() == NStructReal + NumRealComps()); Vector write_real_comp; - for (int i = 0; i < NStructReal + NumRealComps(); ++i) write_real_comp.push_back(1); + for (int i = 0; i < NStructReal + NumRealComps(); ++i) { + write_real_comp.push_back(1); + } Vector write_int_comp; - for (int i = 0; i < NStructInt + NumIntComps(); ++i) write_int_comp.push_back(1); + for (int i = 0; i < NStructInt + NumIntComps(); ++i) { + write_int_comp.push_back(1); + } Vector int_comp_names; for (int i = 0; i < NStructInt + NumIntComps(); ++i ) @@ -277,10 +285,14 @@ ParticleContainer_impl AMREX_ASSERT( int_comp_names.size() == NStructInt + NArrayInt ); Vector write_real_comp; - for (int i = 0; i < NStructReal + NumRealComps(); ++i) write_real_comp.push_back(1); + for (int i = 0; i < NStructReal + NumRealComps(); ++i) { + write_real_comp.push_back(1); + } Vector write_int_comp; - for (int i = 0; i < NStructInt + NumIntComps(); ++i) write_int_comp.push_back(1); + for (int i = 0; i < NStructInt + NumIntComps(); ++i) { + write_int_comp.push_back(1); + } WriteBinaryParticleData(dir, name, write_real_comp, write_int_comp, @@ -299,10 +311,14 @@ ParticleContainer_impl AMREX_ASSERT(real_comp_names.size() == NStructReal + NumRealComps()); Vector write_real_comp; - for (int i = 0; i < NStructReal + NumRealComps(); ++i) write_real_comp.push_back(1); + for (int i = 0; i < NStructReal + NumRealComps(); ++i) { + write_real_comp.push_back(1); + } Vector write_int_comp; - for (int i = 0; i < NStructInt + NumIntComps(); ++i) write_int_comp.push_back(1); + for (int i = 0; i < NStructInt + NumIntComps(); ++i) { + write_int_comp.push_back(1); + } Vector int_comp_names; for (int i = 0; i < NStructInt + NumIntComps(); ++i ) @@ -568,7 +584,7 @@ ParticleContainer_impl which[grid] = fnum; where[grid] = VisMF::FileOffset(ofs); - if (count[grid] == 0) continue; + if (count[grid] == 0) { continue; } Vector istuff; Vector rstuff; @@ -611,12 +627,14 @@ ParticleContainer_impl pp.queryAdd("datadigits_read",DATA_Digits_Read); std::string fullname = dir; - if (!fullname.empty() && fullname[fullname.size()-1] != '/') + if (!fullname.empty() && fullname[fullname.size()-1] != '/') { fullname += '/'; + } fullname += file; std::string HdrFileName = fullname; - if (!HdrFileName.empty() && HdrFileName[HdrFileName.size()-1] != '/') + if (!HdrFileName.empty() && HdrFileName[HdrFileName.size()-1] != '/') { HdrFileName += '/'; + } HdrFileName += "Header"; Vector fileCharPtr; @@ -666,25 +684,30 @@ ParticleContainer_impl int dm; HdrFile >> dm; - if (dm != AMREX_SPACEDIM) + if (dm != AMREX_SPACEDIM) { amrex::Abort("ParticleContainer::Restart(): dm != AMREX_SPACEDIM"); + } int nr; HdrFile >> nr; - if (nr != NStructReal + NumRealComps()) + if (nr != NStructReal + NumRealComps()) { amrex::Abort("ParticleContainer::Restart(): nr != NStructReal + NumRealComps()"); + } std::string comp_name; - for (int i = 0; i < nr; ++i) + for (int i = 0; i < nr; ++i) { HdrFile >> comp_name; + } int ni; HdrFile >> ni; - if (ni != NStructInt + NumIntComps()) + if (ni != NStructInt + NumIntComps()) { amrex::Abort("ParticleContainer::Restart(): ni != NStructInt"); + } - for (int i = 0; i < ni; ++i) + for (int i = 0; i < ni; ++i) { HdrFile >> comp_name; + } bool checkpoint; HdrFile >> checkpoint; @@ -733,7 +756,7 @@ ParticleContainer_impl phdr_name = amrex::Concatenate(phdr_name, lev, 1); phdr_name += "/Particle_H"; - if (! amrex::FileExists(phdr_name)) continue; + if (! amrex::FileExists(phdr_name)) { continue; } Vector phdr_chars; ParallelDescriptor::ReadAndBcastFile(phdr_name, phdr_chars); @@ -747,7 +770,7 @@ ParticleContainer_impl } particle_box_arrays[lev].readFrom(phdr_file); - if (! particle_box_arrays[lev].CellEqual(ParticleBoxArray(lev))) dual_grid = true; + if (! particle_box_arrays[lev].CellEqual(ParticleBoxArray(lev))) { dual_grid = true; } } } else // if no particle box array information exists in the file, we assume a single grid restart { @@ -798,7 +821,7 @@ ParticleContainer_impl const int rank = ParallelDescriptor::MyProc(); const int NReaders = MaxReaders(); - if (rank >= NReaders) return; + if (rank >= NReaders) { return; } const int Navg = ngrids[lev] / NReaders; const int Nleft = ngrids[lev] - Navg * NReaders; @@ -821,13 +844,14 @@ ParticleContainer_impl for(int igrid = 0; igrid < static_cast(grids_to_read.size()); ++igrid) { const int grid = grids_to_read[igrid]; - if (count[grid] <= 0) continue; + if (count[grid] <= 0) { continue; } // The file names in the header file are relative. std::string name = fullname; - if (!name.empty() && name[name.size()-1] != '/') + if (!name.empty() && name[name.size()-1] != '/') { name += '/'; + } name += "Level_"; name += amrex::Concatenate("", lev, 1); @@ -839,8 +863,9 @@ ParticleContainer_impl ParticleFile.open(name.c_str(), std::ios::in | std::ios::binary); - if (!ParticleFile.good()) + if (!ParticleFile.good()) { amrex::FileOpenFailed(name); + } ParticleFile.seekg(where[grid], std::ios::beg); @@ -869,8 +894,9 @@ ParticleContainer_impl ParticleFile.close(); - if (!ParticleFile.good()) + if (!ParticleFile.good()) { amrex::Abort("ParticleContainer::Restart(): problem reading particles"); + } } } @@ -1090,11 +1116,12 @@ ParticleContainer_impl Gpu::copy(Gpu::deviceToHost, aos.begin(), aos.begin() + np, host_aos.begin()); for (int k = 0; k < np; ++k) { const ParticleType& p = host_aos[k]; - if (p.id() > 0) + if (p.id() > 0) { // // Only count (and checkpoint) valid particles. // nparticles++; + } } } } @@ -1113,8 +1140,9 @@ ParticleContainer_impl File.open(filename.c_str(), std::ios::out|std::ios::trunc); - if (!File.good()) + if (!File.good()) { amrex::FileOpenFailed(filename); + } File << nparticles << '\n'; File << NStructReal << '\n'; @@ -1126,8 +1154,9 @@ ParticleContainer_impl File.close(); - if (!File.good()) + if (!File.good()) { amrex::Abort("ParticleContainer::WriteAsciiFile(): problem writing file"); + } } ParallelDescriptor::Barrier(); @@ -1151,8 +1180,9 @@ ParticleContainer_impl File.precision(15); - if (!File.good()) + if (!File.good()) { amrex::FileOpenFailed(filename); + } for (int lev = 0; lev < m_particles.size(); lev++) { auto& pmap = m_particles[lev]; @@ -1175,21 +1205,25 @@ ParticleContainer_impl << it->pos(1) << ' ', << it->pos(2) << ' '); - for (int i = 0; i < NStructReal; i++) + for (int i = 0; i < NStructReal; i++) { File << it->rdata(i) << ' '; + } File << it->id() << ' '; File << it->cpu() << ' '; - for (int i = 0; i < NStructInt; i++) + for (int i = 0; i < NStructInt; i++) { File << it->idata(i) << ' '; + } // then the particle attributes. - for (int i = 0; i < NumRealComps(); i++) + for (int i = 0; i < NumRealComps(); i++) { File << host_soa.GetRealData(i)[index] << ' '; + } - for (int i = 0; i < NumIntComps(); i++) + for (int i = 0; i < NumIntComps(); i++) { File << host_soa.GetIntData(i)[index] << ' '; + } File << '\n'; } @@ -1201,8 +1235,9 @@ ParticleContainer_impl File.close(); - if (!File.good()) + if (!File.good()) { amrex::Abort("ParticleContainer::WriteAsciiFile(): problem writing file"); + } } diff --git a/Src/Particle/AMReX_ParticleInit.H b/Src/Particle/AMReX_ParticleInit.H index 04e8b75fbc3..82119142191 100644 --- a/Src/Particle/AMReX_ParticleInit.H +++ b/Src/Particle/AMReX_ParticleInit.H @@ -75,15 +75,16 @@ ParticleContainer_impl IntVect lNrep(AMREX_D_DECL(1,1,1)); - if (Nrep != nullptr) + if (Nrep != nullptr) { lNrep = *Nrep; + } Long how_many = 0; Long how_many_read = 0; Gpu::HostVector nparticles; Vector > nreals(0); - if (extradata > NStructReal) nreals.resize(extradata - NStructReal); + if (extradata > NStructReal) { nreals.resize(extradata - NStructReal); } if (MyProc < NReaders) { @@ -108,7 +109,7 @@ ParticleContainer_impl ParticleType p, p_rep; Vector r; - if (extradata > NStructReal) r.resize(extradata - NStructReal); + if (extradata > NStructReal) { r.resize(extradata - NStructReal); } const int Chunk = cnt / NReaders; @@ -183,11 +184,12 @@ ParticleContainer_impl p.cpu() = MyProc; nparticles.push_back(p); - if(nreals.size() > extradata - NStructReal) + if(nreals.size() > extradata - NStructReal) { for (int n = NStructReal; n < extradata; n++) { nreals[n-NStructReal].push_back(r[n-NStructReal]); } + } how_many++; how_many_read++; @@ -242,11 +244,12 @@ ParticleContainer_impl nparticles.push_back(p_rep); - if (nreals.size() > extradata - NStructReal) + if (nreals.size() > extradata - NStructReal) { for (int n = NStructReal; n < extradata; n++) { nreals[n-NStructReal].push_back(r[n-NStructReal]); } + } how_many++; } @@ -333,13 +336,14 @@ ParticleContainer_impl Gpu::copyAsync(Gpu::hostToDevice, src_tile.begin(), src_tile.end(), dst_tile.GetArrayOfStructs().begin() + old_size); - if((host_real_attribs[lev][std::make_pair(grid, tile)]).size() > (long unsigned int) NArrayReal) - for (int i = 0; i < NArrayReal; ++i) { - Gpu::copyAsync(Gpu::hostToDevice, - host_real_attribs[lev][std::make_pair(grid,tile)][i].begin(), - host_real_attribs[lev][std::make_pair(grid,tile)][i].end(), - dst_tile.GetStructOfArrays().GetRealData(i).begin() + old_size); - } + if((host_real_attribs[lev][std::make_pair(grid, tile)]).size() > (long unsigned int) NArrayReal) { + for (int i = 0; i < NArrayReal; ++i) { + Gpu::copyAsync(Gpu::hostToDevice, + host_real_attribs[lev][std::make_pair(grid,tile)][i].begin(), + host_real_attribs[lev][std::make_pair(grid,tile)][i].end(), + dst_tile.GetStructOfArrays().GetRealData(i).begin() + old_size); + } + } } } Gpu::streamSynchronize(); @@ -373,20 +377,22 @@ ParticleContainer_impl Where(p, pld); host_particles[pld.m_lev][std::make_pair(pld.m_grid, pld.m_tile)].push_back(p); - if((host_real_attribs[pld.m_lev][std::make_pair(pld.m_grid, pld.m_tile)]).size() > (long unsigned int) (extradata - NStructReal)) + if((host_real_attribs[pld.m_lev][std::make_pair(pld.m_grid, pld.m_tile)]).size() > (long unsigned int) (extradata - NStructReal)) { for (int n = NStructReal; n < extradata; n++) { Real rdata = nreals[n-NStructReal].back(); host_real_attribs[pld.m_lev][std::make_pair(pld.m_grid, pld.m_tile)][n-NStructReal].push_back(rdata); } + } nparticles.pop_back(); - if (nreals.size() > extradata - NStructReal) + if (nreals.size() > extradata - NStructReal) { for (int n = NStructReal; n < extradata; n++) { nreals[n-NStructReal].pop_back(); } + } } } @@ -539,8 +545,9 @@ InitFromBinaryFile (const std::string& file, // // Just set'm. // - for (int i = 0; i < NProcs; i++) + for (int i = 0; i < NProcs; i++) { rprocs[i] = i; + } } else { @@ -604,8 +611,9 @@ InitFromBinaryFile (const std::string& file, ifs.open(file.c_str(), std::ios::in|std::ios::binary); - if (!ifs.good()) + if (!ifs.good()) { amrex::FileOpenFailed(file); + } ifs.read((char*)&NP, sizeof(NP)); ifs.read((char*)&DM, sizeof(DM)); @@ -613,23 +621,27 @@ InitFromBinaryFile (const std::string& file, // // NP MUST be positive! // - if (NP <= 0) + if (NP <= 0) { amrex::Abort("ParticleContainer_impl::InitFromBinaryFile(): NP <= 0"); + } // // DM must equal AMREX_SPACEDIM. // - if (DM != AMREX_SPACEDIM) + if (DM != AMREX_SPACEDIM) { amrex::Abort("ParticleContainer_impl::InitFromBinaryFile(): DM != AMREX_SPACEDIM"); + } // // NX MUST be in [0,N]. // - if (NX < 0 || NX > NStructReal) + if (NX < 0 || NX > NStructReal) { amrex::Abort("ParticleContainer_impl::InitFromBinaryFile(): NX < 0 || NX > N"); + } // // Can't ask for more data than exists in the file! // - if (extradata > NX) + if (extradata > NX) { amrex::Abort("ParticleContainer_impl::InitFromBinaryFile(): extradata > NX"); + } // // Figure out whether we're dealing with floats or doubles. // @@ -656,9 +668,11 @@ InitFromBinaryFile (const std::string& file, // Skip to our place in the file. // int id = 0; - for ( ; id < NReaders; id++) - if (rprocs[id] == MyProc) + for ( ; id < NReaders; id++) { + if (rprocs[id] == MyProc) { break; + } + } AMREX_ASSERT(id >= 0 && id < NReaders); @@ -686,15 +700,16 @@ InitFromBinaryFile (const std::string& file, // Long MyCnt = NP / NReaders; - if (MyProc == rprocs[0]) + if (MyProc == rprocs[0]) { // // Give any remainder to the first reader. // MyCnt += NP % NReaders; + } Long how_many_redists = NP / (NPartPerRedist*NReaders), how_many_read = 0; - if (NP % (NPartPerRedist*NReaders)) how_many_redists++; + if (NP % (NPartPerRedist*NReaders)) { how_many_redists++; } Vector fxtra, fignore; Vector dxtra, dignore; @@ -763,17 +778,19 @@ InitFromBinaryFile (const std::string& file, { if (RealSizeInFile == sizeof(float)) { - ifs.read((char*)&fxtra[0], std::streamsize(extradata*sizeof(float))); + ifs.read((char*)fxtra.data(), std::streamsize(extradata*sizeof(float))); - for (int ii = 0; ii < extradata; ii++) + for (int ii = 0; ii < extradata; ii++) { p.rdata(ii) = static_cast(fxtra[ii]); + } } else if (RealSizeInFile == sizeof(double)) { - ifs.read((char*)&dxtra[0], std::streamsize(extradata*sizeof(double))); + ifs.read((char*)dxtra.data(), std::streamsize(extradata*sizeof(double))); - for (int ii = 0; ii < extradata; ii++) + for (int ii = 0; ii < extradata; ii++) { p.rdata(ii) = static_cast(dxtra[ii]); + } } } // @@ -783,11 +800,11 @@ InitFromBinaryFile (const std::string& file, { if (RealSizeInFile == sizeof(float)) { - ifs.read((char*)&fignore[0], std::streamsize((NX-extradata)*sizeof(float))); + ifs.read((char*)fignore.data(), std::streamsize((NX-extradata)*sizeof(float))); } else if (RealSizeInFile == sizeof(double)) { - ifs.read((char*)&dignore[0], std::streamsize((NX-extradata)*sizeof(double))); + ifs.read((char*)dignore.data(), std::streamsize((NX-extradata)*sizeof(double))); } } @@ -923,10 +940,11 @@ InitFromBinaryMetaFile (const std::string& metafile, { std::getline(ifs,file); - if (!ifs.good()) break; + if (!ifs.good()) { break; } - if (m_verbose > 1) + if (m_verbose > 1) { amrex::Print() << "InitFromBinaryMetaFile: processing file: " << file << '\n'; + } InitFromBinaryFile(file, extradata); } @@ -971,7 +989,7 @@ InitRandom (Long icount, // We will enforce that the particles are within the containing_bx. // If containing_bx is not passed in, it defaults to the full domain. - if (!containing_bx.ok()) containing_bx = geom.ProbDomain(); + if (!containing_bx.ok()) { containing_bx = geom.ProbDomain(); } // containing_bx is assumed to lie within the domain. if (!geom.ProbDomain().contains(containing_bx)) @@ -1366,8 +1384,9 @@ ParticleContainer_impl p.pos(1) = static_cast(grid_box.lo(1) + (dist(mt) + double(jcnt)) / double(icount_per_box) * grid_box.length(1)); p.pos(2) = static_cast(grid_box.lo(2) + (dist(mt) + double(kcnt)) / double(icount_per_box) * grid_box.length(2)); - for (int i = 0; i < AMREX_SPACEDIM; i++) + for (int i = 0; i < AMREX_SPACEDIM; i++) { AMREX_ASSERT(p.pos(i) < grid_box.hi(i)); + } // the real struct data for (int i = 0; i < NStructReal; i++) { @@ -1518,8 +1537,9 @@ InitNRandomPerCell (int n_per_cell, const ParticleInitData& pdata) resizeData(); - for (int lev = 0; lev < m_particles.size(); lev++) + for (int lev = 0; lev < m_particles.size(); lev++) { AMREX_ASSERT(m_particles[lev].empty()); + } ParticleLocData pld; ParticleType p; @@ -1555,7 +1575,7 @@ InitNRandomPerCell (int n_per_cell, const ParticleInitData& pdata) while (iter < max_iter) { r = amrex::Random(); p.pos(i) = static_cast(grid_box.lo(i) + (r + Real(cell[i]-beg[i]))*dx[i]); - if (p.pos(i) < grid_box.hi(i)) break; + if (p.pos(i) < grid_box.hi(i)) { break; } iter++; } AMREX_ASSERT(p.pos(i) < grid_box.hi(i)); diff --git a/Src/Particle/AMReX_ParticleLocator.H b/Src/Particle/AMReX_ParticleLocator.H index 35257049b9d..f9eac5d6ee4 100644 --- a/Src/Particle/AMReX_ParticleLocator.H +++ b/Src/Particle/AMReX_ParticleLocator.H @@ -112,7 +112,7 @@ public: m_geom = geom; int num_boxes = static_cast(ba.size()); m_host_boxes.resize(0); - for (int i = 0; i < num_boxes; ++i) m_host_boxes.push_back(ba[i]); + for (int i = 0; i < num_boxes; ++i) { m_host_boxes.push_back(ba[i]); } m_device_boxes.resize(num_boxes); Gpu::copyAsync(Gpu::hostToDevice, m_host_boxes.begin(), m_host_boxes.end(), m_device_boxes.begin()); @@ -178,7 +178,7 @@ public: bool isValid (const BoxArray& ba) const noexcept { - if (m_defined) return BoxArray::SameRefs(m_ba, ba); + if (m_defined) { return BoxArray::SameRefs(m_ba, ba); } return false; } @@ -220,13 +220,13 @@ struct AmrAssignGrid for (int lev = lev_max; lev >= lev_min; --lev) { int grid = m_funcs[lev](p); - if (grid >= 0) return makeTuple(grid, lev); + if (grid >= 0) { return makeTuple(grid, lev); } } for (int lev = lev_min; lev >= lev_min; --lev) { int grid = m_funcs[lev](p, nGrow); - if (grid >= 0) return makeTuple(grid, lev); + if (grid >= 0) { return makeTuple(grid, lev); } } return makeTuple(-1, -1); @@ -301,11 +301,12 @@ public: [[nodiscard]] bool isValid (const Vector& a_ba) const { if ( !m_defined || (m_locators.empty()) || - (m_locators.size() != a_ba.size()) ) return false; + (m_locators.size() != a_ba.size()) ) { return false; } bool all_valid = true; int num_levels = m_locators.size(); - for (int lev = 0; lev < num_levels; ++lev) + for (int lev = 0; lev < num_levels; ++lev) { all_valid = all_valid && m_locators[lev].isValid(a_ba[lev]); + } return all_valid; } @@ -313,8 +314,9 @@ public: { Vector ba; int num_levels = a_gdb->finestLevel()+1; - for (int lev = 0; lev < num_levels; ++lev) + for (int lev = 0; lev < num_levels; ++lev) { ba.push_back(a_gdb->ParticleBoxArray(lev)); + } return this->isValid(ba); } diff --git a/Src/Particle/AMReX_ParticleMPIUtil.cpp b/Src/Particle/AMReX_ParticleMPIUtil.cpp index 64e9737a95a..d9b9f73a29f 100644 --- a/Src/Particle/AMReX_ParticleMPIUtil.cpp +++ b/Src/Particle/AMReX_ParticleMPIUtil.cpp @@ -26,7 +26,7 @@ namespace amrex { Vector& Snds, Vector& Rcvs) { Long NumSnds = CountSnds(not_ours, Snds); - if (NumSnds == 0) return NumSnds; + if (NumSnds == 0) { return NumSnds; } BL_COMM_PROFILE(BLProfiler::Alltoall, sizeof(Long), ParallelContext::MyProcSub(), BLProfiler::BeforeCall()); diff --git a/Src/Particle/AMReX_ParticleMesh.H b/Src/Particle/AMReX_ParticleMesh.H index 75d2cdb4838..2ded8df7506 100644 --- a/Src/Particle/AMReX_ParticleMesh.H +++ b/Src/Particle/AMReX_ParticleMesh.H @@ -130,7 +130,7 @@ MeshToParticle (PC& pc, MF const& mf, int lev, F&& f) pc.ParticleDistributionMap(lev), mf.nComp(), mf.nGrowVect()); - if (mf_pointer != &mf) mf_pointer->ParallelCopy(mf,0,0,mf.nComp(),mf.nGrowVect(),mf.nGrowVect()); + if (mf_pointer != &mf) {mf_pointer->ParallelCopy(mf,0,0,mf.nComp(),mf.nGrowVect(),mf.nGrowVect()); } const auto plo = pc.Geom(lev).ProbLoArray(); const auto dxi = pc.Geom(lev).InvCellSizeArray(); @@ -154,7 +154,7 @@ MeshToParticle (PC& pc, MF const& mf, int lev, F&& f) }); } - if (mf_pointer != &mf) delete mf_pointer; + if (mf_pointer != &mf) { delete mf_pointer; } } } diff --git a/Src/Particle/AMReX_ParticleTile.H b/Src/Particle/AMReX_ParticleTile.H index 871acad3533..1663fece598 100644 --- a/Src/Particle/AMReX_ParticleTile.H +++ b/Src/Particle/AMReX_ParticleTile.H @@ -205,18 +205,23 @@ struct ParticleTileData { AMREX_ASSERT(index < m_size); SuperParticleType sp; - for (int i = 0; i < AMREX_SPACEDIM; ++i) + for (int i = 0; i < AMREX_SPACEDIM; ++i) { sp.pos(i) = m_aos[index].pos(i); - for (int i = 0; i < NStructReal; ++i) + } + for (int i = 0; i < NStructReal; ++i) { sp.rdata(i) = m_aos[index].rdata(i); - for (int i = 0; i < NAR; ++i) + } + for (int i = 0; i < NAR; ++i) { sp.rdata(NStructReal+i) = m_rdata[i][index]; + } sp.id() = m_aos[index].id(); sp.cpu() = m_aos[index].cpu(); - for (int i = 0; i < NStructInt; ++i) + for (int i = 0; i < NStructInt; ++i) { sp.idata(i) = m_aos[index].idata(i); - for (int i = 0; i < NAI; ++i) + } + for (int i = 0; i < NAI; ++i) { sp.idata(NStructInt+i) = m_idata[i][index]; + } return sp; } @@ -229,10 +234,12 @@ struct ParticleTileData for (int i = 0; i < AMREX_SPACEDIM; ++i) {sp.pos(i) = m_rdata[i][index];} sp.id() = m_idata[0][index]; sp.cpu() = m_idata[1][index]; - for (int i = 0; i < NAR; ++i) + for (int i = 0; i < NAR; ++i) { sp.rdata(i) = m_rdata[i][index]; - for (int i = 0; i < NAI; ++i) + } + for (int i = 0; i < NAI; ++i) { sp.idata(i) = m_idata[i][index]; + } return sp; } @@ -240,28 +247,35 @@ struct ParticleTileData AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void setSuperParticle (const SuperParticleType& sp, int index) const noexcept { - for (int i = 0; i < AMREX_SPACEDIM; ++i) + for (int i = 0; i < AMREX_SPACEDIM; ++i) { m_aos[index].pos(i) = sp.pos(i); - for (int i = 0; i < NStructReal; ++i) + } + for (int i = 0; i < NStructReal; ++i) { m_aos[index].rdata(i) = sp.rdata(i); - for (int i = 0; i < NAR; ++i) + } + for (int i = 0; i < NAR; ++i) { m_rdata[i][index] = sp.rdata(NStructReal+i); + } m_aos[index].id() = sp.id(); m_aos[index].cpu() = sp.cpu(); - for (int i = 0; i < NStructInt; ++i) + for (int i = 0; i < NStructInt; ++i) { m_aos[index].idata(i) = sp.idata(i); - for (int i = 0; i < NAI; ++i) + } + for (int i = 0; i < NAI; ++i) { m_idata[i][index] = sp.idata(NStructInt+i); + } } template ::type = 0> AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void setSuperParticle (const SuperParticleType& sp, int index) const noexcept { - for (int i = 0; i < NAR; ++i) + for (int i = 0; i < NAR; ++i) { m_rdata[i][index] = sp.rdata(i); - for (int i = 0; i < NAI; ++i) + } + for (int i = 0; i < NAI; ++i) { m_idata[i][index] = sp.idata(i); + } } }; @@ -421,8 +435,9 @@ SoAParticle::NextID () #endif next = the_next_id++; - if (next > IntParticleIds::LastParticleID) + if (next > IntParticleIds::LastParticleID) { amrex::Abort("SoAParticle::NextID() -- too many particles"); + } return int(next); } @@ -432,8 +447,9 @@ int SoAParticle::UnprotectedNextID () { int next = the_next_id++; - if (next > IntParticleIds::LastParticleID) + if (next > IntParticleIds::LastParticleID) { amrex::Abort("SoAParticle::NextID() -- too many particles"); + } return next; } @@ -575,20 +591,27 @@ struct ConstParticleTileData { AMREX_ASSERT(index < m_size); SuperParticleType sp; - for (int i = 0; i < AMREX_SPACEDIM; ++i) + for (int i = 0; i < AMREX_SPACEDIM; ++i) { sp.pos(i) = m_aos[index].pos(i); - for (int i = 0; i < NStructReal; ++i) + } + for (int i = 0; i < NStructReal; ++i) { sp.rdata(i) = m_aos[index].rdata(i); - if constexpr(NArrayReal > 0) - for (int i = 0; i < NArrayReal; ++i) + } + if constexpr(NArrayReal > 0) { + for (int i = 0; i < NArrayReal; ++i) { sp.rdata(NStructReal+i) = m_rdata[i][index]; + } + } sp.id() = m_aos[index].id(); sp.cpu() = m_aos[index].cpu(); - for (int i = 0; i < NStructInt; ++i) + for (int i = 0; i < NStructInt; ++i) { sp.idata(i) = m_aos[index].idata(i); - if constexpr(NArrayInt > 0) - for (int i = 0; i < NArrayInt; ++i) + } + if constexpr(NArrayInt > 0) { + for (int i = 0; i < NArrayInt; ++i) { sp.idata(NStructInt+i) = m_idata[i][index]; + } + } return sp; } @@ -601,10 +624,12 @@ struct ConstParticleTileData for (int i = 0; i < AMREX_SPACEDIM; ++i) {sp.pos(i) = m_rdata[i][index];} sp.id() = m_idata[0][index]; sp.cpu() = m_idata[1][index]; - for (int i = 0; i < NAR; ++i) + for (int i = 0; i < NAR; ++i) { sp.rdata(i) = m_rdata[i][index]; - for (int i = 0; i < NAI; ++i) + } + for (int i = 0; i < NAI; ++i) { sp.idata(i) = m_idata[i][index]; + } return sp; } }; @@ -825,24 +850,29 @@ struct ParticleTile if constexpr (!ParticleType::is_soa_particle) { m_aos_tile.resize(np+1); - for (int i = 0; i < AMREX_SPACEDIM; ++i) + for (int i = 0; i < AMREX_SPACEDIM; ++i) { m_aos_tile[np].pos(i) = sp.pos(i); - for (int i = 0; i < NStructReal; ++i) + } + for (int i = 0; i < NStructReal; ++i) { m_aos_tile[np].rdata(i) = sp.rdata(i); + } m_aos_tile[np].id() = sp.id(); m_aos_tile[np].cpu() = sp.cpu(); - for (int i = 0; i < NStructInt; ++i) + for (int i = 0; i < NStructInt; ++i) { m_aos_tile[np].idata(i) = sp.idata(i); + } } m_soa_tile.resize(np+1); auto& arr_rdata = m_soa_tile.GetRealData(); auto& arr_idata = m_soa_tile.GetIntData(); - for (int i = 0; i < NArrayReal; ++i) + for (int i = 0; i < NArrayReal; ++i) { arr_rdata[i][np] = sp.rdata(NStructReal+i); - for (int i = 0; i < NArrayInt; ++i) + } + for (int i = 0; i < NArrayInt; ++i) { arr_idata[i][np] = sp.idata(NStructInt+i); + } } /// @@ -1053,12 +1083,16 @@ struct ParticleTile } else { ptd.m_aos = nullptr; } - if constexpr(NArrayReal > 0) - for (int i = 0; i < NArrayReal; ++i) + if constexpr(NArrayReal > 0) { + for (int i = 0; i < NArrayReal; ++i) { ptd.m_rdata[i] = m_soa_tile.GetRealData(i).dataPtr(); - if constexpr(NArrayInt > 0) - for (int i = 0; i < NArrayInt; ++i) + } + } + if constexpr(NArrayInt > 0) { + for (int i = 0; i < NArrayInt; ++i) { ptd.m_idata[i] = m_soa_tile.GetIntData(i).dataPtr(); + } + } ptd.m_size = size(); ptd.m_num_runtime_real = m_runtime_r_ptrs.size(); ptd.m_num_runtime_int = m_runtime_i_ptrs.size(); @@ -1114,12 +1148,16 @@ struct ParticleTile } else { ptd.m_aos = nullptr; } - if constexpr(NArrayReal > 0) - for (int i = 0; i < NArrayReal; ++i) + if constexpr(NArrayReal > 0) { + for (int i = 0; i < NArrayReal; ++i) { ptd.m_rdata[i] = m_soa_tile.GetRealData(i).dataPtr(); - if constexpr(NArrayInt > 0) - for (int i = 0; i < NArrayInt; ++i) + } + } + if constexpr(NArrayInt > 0) { + for (int i = 0; i < NArrayInt; ++i) { ptd.m_idata[i] = m_soa_tile.GetIntData(i).dataPtr(); + } + } ptd.m_size = size(); ptd.m_num_runtime_real = m_runtime_r_cptrs.size(); ptd.m_num_runtime_int = m_runtime_i_cptrs.size(); diff --git a/Src/Particle/AMReX_ParticleTransformation.H b/Src/Particle/AMReX_ParticleTransformation.H index 0858ac6b1a0..a5b7afa2356 100644 --- a/Src/Particle/AMReX_ParticleTransformation.H +++ b/Src/Particle/AMReX_ParticleTransformation.H @@ -36,16 +36,22 @@ void copyParticle (const ParticleTileData& dst, AMREX_ASSERT(dst.m_num_runtime_int == src.m_num_runtime_int ); dst.m_aos[dst_i] = src.m_aos[src_i]; - if constexpr(NAR > 0) - for (int j = 0; j < NAR; ++j) + if constexpr(NAR > 0) { + for (int j = 0; j < NAR; ++j) { dst.m_rdata[j][dst_i] = src.m_rdata[j][src_i]; - for (int j = 0; j < dst.m_num_runtime_real; ++j) + } + } + for (int j = 0; j < dst.m_num_runtime_real; ++j) { dst.m_runtime_rdata[j][dst_i] = src.m_runtime_rdata[j][src_i]; - if constexpr(NAI > 0) - for (int j = 0; j < NAI; ++j) + } + if constexpr(NAI > 0) { + for (int j = 0; j < NAI; ++j) { dst.m_idata[j][dst_i] = src.m_idata[j][src_i]; - for (int j = 0; j < dst.m_num_runtime_int; ++j) + } + } + for (int j = 0; j < dst.m_num_runtime_int; ++j) { dst.m_runtime_idata[j][dst_i] = src.m_runtime_idata[j][src_i]; + } } /** @@ -72,14 +78,18 @@ void copyParticle (const ParticleTileData& dst, AMREX_ASSERT(dst.m_num_runtime_int == src.m_num_runtime_int ); dst.m_aos[dst_i] = src.m_aos[src_i]; - for (int j = 0; j < NAR; ++j) + for (int j = 0; j < NAR; ++j) { dst.m_rdata[j][dst_i] = src.m_rdata[j][src_i]; - for (int j = 0; j < dst.m_num_runtime_real; ++j) + } + for (int j = 0; j < dst.m_num_runtime_real; ++j) { dst.m_runtime_rdata[j][dst_i] = src.m_runtime_rdata[j][src_i]; - for (int j = 0; j < NAI; ++j) + } + for (int j = 0; j < NAI; ++j) { dst.m_idata[j][dst_i] = src.m_idata[j][src_i]; - for (int j = 0; j < dst.m_num_runtime_int; ++j) + } + for (int j = 0; j < dst.m_num_runtime_int; ++j) { dst.m_runtime_idata[j][dst_i] = src.m_runtime_idata[j][src_i]; + } } /** @@ -106,14 +116,18 @@ void swapParticle (const ParticleTileData& dst, AMREX_ASSERT(dst.m_num_runtime_int == src.m_num_runtime_int ); amrex::Swap(src.m_aos[src_i], dst.m_aos[dst_i]); - for (int j = 0; j < NAR; ++j) + for (int j = 0; j < NAR; ++j) { amrex::Swap(dst.m_rdata[j][dst_i], src.m_rdata[j][src_i]); - for (int j = 0; j < dst.m_num_runtime_real; ++j) + } + for (int j = 0; j < dst.m_num_runtime_real; ++j) { amrex::Swap(dst.m_runtime_rdata[j][dst_i], src.m_runtime_rdata[j][src_i]); - for (int j = 0; j < NAI; ++j) + } + for (int j = 0; j < NAI; ++j) { amrex::Swap(dst.m_idata[j][dst_i], src.m_idata[j][src_i]); - for (int j = 0; j < dst.m_num_runtime_int; ++j) + } + for (int j = 0; j < dst.m_num_runtime_int; ++j) { amrex::Swap(dst.m_runtime_idata[j][dst_i], src.m_runtime_idata[j][src_i]); + } } /** @@ -337,7 +351,7 @@ Index filterParticles (DstTile& dst, const SrcTile& src, const Index* mask, AMREX_HOST_DEVICE_FOR_1D( n, i, { - if (mask[i]) copyParticle(dst_data, src_data, src_start+i, dst_start+p_offsets[i]); + if (mask[i]) { copyParticle(dst_data, src_data, src_start+i, dst_start+p_offsets[i]); } }); Gpu::streamSynchronize(); @@ -437,8 +451,10 @@ Index filterAndTransformParticles (DstTile& dst, const SrcTile& src, Index* mask AMREX_HOST_DEVICE_FOR_1D( np, i, { - if (mask[i]) f(dst_data, src_data, src_start+i, - dst_start+p_offsets[src_start+i]); + if (mask[i]) { + f(dst_data, src_data, src_start+i, + dst_start+p_offsets[src_start+i]); + } }); Gpu::streamSynchronize(); @@ -526,7 +542,7 @@ Index filterAndTransformParticles (DstTile1& dst1, DstTile2& dst2, AMREX_HOST_DEVICE_FOR_1D( np, i, { - if (mask[i]) f(dst_data1, dst_data2, src_data, i, p_offsets[i], p_offsets[i]); + if (mask[i]) { f(dst_data1, dst_data2, src_data, i, p_offsets[i], p_offsets[i]); } }); Gpu::streamSynchronize(); diff --git a/Src/Particle/AMReX_ParticleUtil.H b/Src/Particle/AMReX_ParticleUtil.H index 0d7f9af776b..9136bea6741 100644 --- a/Src/Particle/AMReX_ParticleUtil.H +++ b/Src/Particle/AMReX_ParticleUtil.H @@ -74,7 +74,7 @@ numParticlesOutOfRange (Iterator const& pti, IntVect nGrow) [=] AMREX_GPU_DEVICE (int i) -> ReduceTuple { auto p = make_particle{}(ptd,i); - if ((p.id() < 0)) return false; + if ((p.id() < 0)) { return false; } IntVect iv( AMREX_D_DECL(int(amrex::Math::floor((p.pos(0)-plo[0])*dxi[0])), int(amrex::Math::floor((p.pos(1)-plo[1])*dxi[1])), @@ -383,7 +383,7 @@ int getParticleGrid (P const& p, amrex::Array4 const& mask, amrex::GpuArray const& dxi, const Box& domain) noexcept { - if (p.id() < 0) return -1; + if (p.id() < 0) { return -1; } IntVect iv = getParticleCell(p, plo, dxi, domain); return mask(iv); } @@ -400,7 +400,7 @@ bool enforcePeriodic (P& p, bool shifted = false; for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { - if (! is_per[idim]) continue; + if (! is_per[idim]) { continue; } if (p.pos(idim) > rhi[idim]) { while (p.pos(idim) > rhi[idim]) { p.pos(idim) -= static_cast(phi[idim] - plo[idim]); @@ -441,7 +441,7 @@ partitionParticlesByDest (PTile& ptile, const PLocator& ploc, const ParticleBuff int lev_min, int lev_max, int nGrow, bool remove_negative) { const int np = ptile.numParticles(); - if (np == 0) return 0; + if (np == 0) { return 0; } auto getPID = pmap.getPIDFunctor(); diff --git a/Src/Particle/AMReX_ParticleUtil.cpp b/Src/Particle/AMReX_ParticleUtil.cpp index 4dcced59c2c..63d0cbe90db 100644 --- a/Src/Particle/AMReX_ParticleUtil.cpp +++ b/Src/Particle/AMReX_ParticleUtil.cpp @@ -36,8 +36,8 @@ Vector computeNeighborProcs (const ParGDBBase* a_gdb, int ngrow) { Box box = src_box; const IntVect& ref_fac = computeRefFac(a_gdb, src_lev, lev); - if (ref_fac < IntVect::TheZeroVector()) box.coarsen(-1*ref_fac); - else if (ref_fac > IntVect::TheZeroVector()) box.refine(ref_fac); + if (ref_fac < IntVect::TheZeroVector()) { box.coarsen(-1*ref_fac); } + else if (ref_fac > IntVect::TheZeroVector()) { box.refine(ref_fac); } box.grow(computeRefFac(a_gdb, 0, src_lev)*ngrow); const Periodicity& periodicity = a_gdb->Geom(lev).periodicity(); diff --git a/Src/Particle/AMReX_Particle_mod_K.H b/Src/Particle/AMReX_Particle_mod_K.H index fe62bb002a6..2d1f91b4275 100644 --- a/Src/Particle/AMReX_Particle_mod_K.H +++ b/Src/Particle/AMReX_Particle_mod_K.H @@ -123,7 +123,7 @@ void amrex_deposit_particle_dx_cic (P const& p, int nc, amrex::Array4(amrex::Math::floor(hx)); for (int i = lo_x; i <= hi_x; ++i) { - if (i < rho.begin.x || i >= rho.end.x) continue; + if (i < rho.begin.x || i >= rho.end.x) { continue; } amrex::Real wx = amrex::min(hx - static_cast(i), amrex::Real(1.0)) - amrex::max(lx - static_cast(i), amrex::Real(0.0)); amrex::Real weight = wx*factor; amrex::Gpu::Atomic::AddNoRet(&rho(i, 0, 0, 0), static_cast(weight*p.rdata(0))); @@ -132,7 +132,7 @@ void amrex_deposit_particle_dx_cic (P const& p, int nc, amrex::Array4= rho.end.x) continue; + if (i < rho.begin.x || i >= rho.end.x) { continue; } amrex::Real wx = amrex::min(hx - static_cast(i), amrex::Real(1.0)) - amrex::max(lx - static_cast(i), amrex::Real(0.0)); amrex::Real weight = wx*factor; amrex::Gpu::Atomic::AddNoRet(&rho(i, 0, 0, comp), static_cast(weight*p.rdata(0)*p.rdata(comp))); @@ -155,10 +155,10 @@ void amrex_deposit_particle_dx_cic (P const& p, int nc, amrex::Array4(amrex::Math::floor(hy)); for (int j = lo_y; j <= hi_y; ++j) { - if (j < rho.begin.y || j >= rho.end.y) continue; + if (j < rho.begin.y || j >= rho.end.y) { continue; } amrex::Real wy = amrex::min(hy - static_cast(j), amrex::Real(1.0)) - amrex::max(ly - static_cast(j), amrex::Real(0.0)); for (int i = lo_x; i <= hi_x; ++i) { - if (i < rho.begin.x || i >= rho.end.x) continue; + if (i < rho.begin.x || i >= rho.end.x) { continue; } amrex::Real wx = amrex::min(hx - static_cast(i), amrex::Real(1.0)) - amrex::max(lx - static_cast(i), amrex::Real(0.0)); amrex::Real weight = wx*wy*factor; amrex::Gpu::Atomic::AddNoRet(&rho(i, j, 0, 0), static_cast(weight*p.rdata(0))); @@ -167,10 +167,10 @@ void amrex_deposit_particle_dx_cic (P const& p, int nc, amrex::Array4= rho.end.y) continue; + if (j < rho.begin.y || j >= rho.end.y) { continue; } amrex::Real wy = amrex::min(hy - static_cast(j), amrex::Real(1.0)) - amrex::max(ly - static_cast(j), amrex::Real(0.0)); for (int i = lo_x; i <= hi_x; ++i) { - if (i < rho.begin.x || i >= rho.end.x) continue; + if (i < rho.begin.x || i >= rho.end.x) { continue; } amrex::Real wx = amrex::min(hx - static_cast(i), amrex::Real(1.0)) - amrex::max(lx - static_cast(i), amrex::Real(0.0)); amrex::Real weight = wx*wy*factor; amrex::Gpu::Atomic::AddNoRet(&rho(i, j, 0, comp), static_cast(weight*p.rdata(0)*p.rdata(comp))); @@ -198,13 +198,13 @@ void amrex_deposit_particle_dx_cic (P const& p, int nc, amrex::Array4(amrex::Math::floor(hz)); for (int k = lo_z; k <= hi_z; ++k) { - if (k < rho.begin.z || k >= rho.end.z) continue; + if (k < rho.begin.z || k >= rho.end.z) { continue; } amrex::Real wz = amrex::min(hz - static_cast(k), amrex::Real(1.0)) - amrex::max(lz - static_cast(k), amrex::Real(0.0)); for (int j = lo_y; j <= hi_y; ++j) { - if (j < rho.begin.y || j >= rho.end.y) continue; + if (j < rho.begin.y || j >= rho.end.y) { continue; } amrex::Real wy = amrex::min(hy - static_cast(j), amrex::Real(1.0)) - amrex::max(ly - static_cast(j), amrex::Real(0.0)); for (int i = lo_x; i <= hi_x; ++i) { - if (i < rho.begin.x || i >= rho.end.x) continue; + if (i < rho.begin.x || i >= rho.end.x) { continue; } amrex::Real wx = amrex::min(hx - static_cast(i), amrex::Real(1.0)) - amrex::max(lx - static_cast(i), amrex::Real(0.0)); amrex::Real weight = wx*wy*wz*factor; amrex::Gpu::Atomic::AddNoRet(&rho(i, j, k, 0), static_cast(weight*p.rdata(0))); @@ -214,13 +214,13 @@ void amrex_deposit_particle_dx_cic (P const& p, int nc, amrex::Array4= rho.end.z) continue; + if (k < rho.begin.z || k >= rho.end.z) { continue; } amrex::Real wz = amrex::min(hz - static_cast(k), amrex::Real(1.0)) - amrex::max(lz - static_cast(k), amrex::Real(0.0)); for (int j = lo_y; j <= hi_y; ++j) { - if (j < rho.begin.y || j >= rho.end.y) continue; + if (j < rho.begin.y || j >= rho.end.y) { continue; } amrex::Real wy = amrex::min(hy - static_cast(j), amrex::Real(1.0)) - amrex::max(ly - static_cast(j), amrex::Real(0.0)); for (int i = lo_x; i <= hi_x; ++i) { - if (i < rho.begin.x || i >= rho.end.x) continue; + if (i < rho.begin.x || i >= rho.end.x) { continue; } amrex::Real wx = amrex::min(hx - static_cast(i), amrex::Real(1.0)) - amrex::max(lx - static_cast(i), amrex::Real(0.0)); amrex::Real weight = wx*wy*wz*factor; amrex::Gpu::Atomic::AddNoRet(&rho(i, j, k, comp), static_cast(weight*p.rdata(0)*p.rdata(comp))); diff --git a/Src/Particle/AMReX_SparseBins.H b/Src/Particle/AMReX_SparseBins.H index 035828b1da6..6ec80a0a831 100644 --- a/Src/Particle/AMReX_SparseBins.H +++ b/Src/Particle/AMReX_SparseBins.H @@ -39,18 +39,18 @@ struct SparseBinIteratorFactory [[nodiscard]] AMREX_GPU_HOST_DEVICE index_type getIndex (const index_type bin_number) const noexcept { - if (m_num_bins == 1) return 0; + if (m_num_bins == 1) { return 0; } index_type lo = 0; index_type hi = m_num_bins - 1; while (lo < hi) { - if (m_bins_ptr[lo] == bin_number) return lo; - if (m_bins_ptr[hi] == bin_number) return hi; + if (m_bins_ptr[lo] == bin_number) { return lo; } + if (m_bins_ptr[hi] == bin_number) { return hi; } index_type mid = (lo + hi) / 2; index_type mid_value = m_bins_ptr[mid]; - if (mid_value == bin_number) return mid; + if (mid_value == bin_number) { return mid; } mid_value < bin_number ? lo = mid+1 : hi = mid; } diff --git a/Src/Particle/AMReX_StructOfArrays.H b/Src/Particle/AMReX_StructOfArrays.H index 00097e445b7..0ef3b8ae869 100644 --- a/Src/Particle/AMReX_StructOfArrays.H +++ b/Src/Particle/AMReX_StructOfArrays.H @@ -42,10 +42,16 @@ struct StructOfArrays { */ [[nodiscard]] RealVector& GetRealData (const int index) { AMREX_ASSERT(index >= 0 && index < NReal + static_cast(m_runtime_rdata.size())); - if (index >= 0 && index < NReal) return m_rdata[index]; - else { + if constexpr (NReal == 0) { AMREX_ASSERT(m_defined); - return m_runtime_rdata[index - NReal]; + return m_runtime_rdata[index]; + } else { + if (index < NReal) { + return m_rdata[index]; + } else { + AMREX_ASSERT(m_defined); + return m_runtime_rdata[index - NReal]; + } } } @@ -55,10 +61,16 @@ struct StructOfArrays { */ [[nodiscard]] const RealVector& GetRealData (const int index) const { AMREX_ASSERT(index >= 0 && index < NReal + static_cast(m_runtime_rdata.size())); - if (index >= 0 && index < NReal) return m_rdata[index]; - else { + if constexpr (NReal == 0) { AMREX_ASSERT(m_defined); - return m_runtime_rdata[index - NReal]; + return m_runtime_rdata[index]; + } else { + if (index < NReal) { + return m_rdata[index]; + } else { + AMREX_ASSERT(m_defined); + return m_runtime_rdata[index - NReal]; + } } } @@ -68,10 +80,16 @@ struct StructOfArrays { */ [[nodiscard]] IntVector& GetIntData (const int index) { AMREX_ASSERT(index >= 0 && index < NInt + static_cast(m_runtime_idata.size())); - if (index >= 0 && index < NInt) return m_idata[index]; - else { + if constexpr (NInt == 0) { AMREX_ASSERT(m_defined); - return m_runtime_idata[index - NInt]; + return m_runtime_idata[index]; + } else { + if (index < NInt) { + return m_idata[index]; + } else { + AMREX_ASSERT(m_defined); + return m_runtime_idata[index - NInt]; + } } } @@ -82,10 +100,16 @@ struct StructOfArrays { */ [[nodiscard]] const IntVector& GetIntData (const int index) const { AMREX_ASSERT(index >= 0 && index < NInt + static_cast(m_runtime_idata.size())); - if (index >= 0 && index < NInt) return m_idata[index]; - else { + if constexpr (NInt == 0) { AMREX_ASSERT(m_defined); - return m_runtime_idata[index - NInt]; + return m_runtime_idata[index]; + } else { + if (index < NInt) { + return m_idata[index]; + } else { + AMREX_ASSERT(m_defined); + return m_runtime_idata[index - NInt]; + } } } @@ -95,16 +119,19 @@ struct StructOfArrays { */ [[nodiscard]] std::size_t size () const { - if (NReal > 0) + if constexpr (NReal > 0) { return m_rdata[0].size(); - else if (NInt > 0) + } else if constexpr (NInt > 0) { return m_idata[0].size(); - else if (!m_runtime_rdata.empty()) - return m_runtime_rdata[0].size(); - else if (!m_runtime_idata.empty()) - return m_runtime_idata[0].size(); - else - return 0; + } else { + if (!m_runtime_rdata.empty()) { + return m_runtime_rdata[0].size(); + } else if (!m_runtime_idata.empty()) { + return m_runtime_idata[0].size(); + } else { + return 0; + } + } } /** @@ -148,10 +175,14 @@ struct StructOfArrays { void resize (size_t count) { - for (int i = 0; i < NReal; ++i) m_rdata[i].resize(count); - for (int i = 0; i < NInt; ++i) m_idata[i].resize(count); - for (int i = 0; i < int(m_runtime_rdata.size()); ++i) m_runtime_rdata[i].resize(count); - for (int i = 0; i < int(m_runtime_idata.size()); ++i) m_runtime_idata[i].resize(count); + if constexpr (NReal > 0) { + for (int i = 0; i < NReal; ++i) { m_rdata[i].resize(count); } + } + if constexpr (NInt > 0) { + for (int i = 0; i < NInt; ++i) { m_idata[i].resize(count); } + } + for (int i = 0; i < int(m_runtime_rdata.size()); ++i) { m_runtime_rdata[i].resize(count); } + for (int i = 0; i < int(m_runtime_idata.size()); ++i) { m_runtime_idata[i].resize(count); } } [[nodiscard]] GpuArray realarray () diff --git a/Src/Particle/AMReX_TracerParticles.cpp b/Src/Particle/AMReX_TracerParticles.cpp index 5d290be43f2..08fbf08dfae 100644 --- a/Src/Particle/AMReX_TracerParticles.cpp +++ b/Src/Particle/AMReX_TracerParticles.cpp @@ -73,7 +73,7 @@ TracerParticleContainer::AdvectWithUmac (MultiFab* umac, int lev, Real dt) [=] AMREX_GPU_DEVICE (int i) { ParticleType& p = p_pbox[i]; - if (p.id() <= 0) return; + if (p.id() <= 0) { return; } ParticleReal v[AMREX_SPACEDIM]; mac_interpolate(p, plo, dxi, umacarr, v); if (ipass == 0) @@ -151,7 +151,7 @@ TracerParticleContainer::AdvectWithUcc (const MultiFab& Ucc, int lev, Real dt) [=] AMREX_GPU_DEVICE (int i) { ParticleType& p = p_pbox[i]; - if (p.id() <= 0) return; + if (p.id() <= 0) { return; } ParticleReal v[AMREX_SPACEDIM]; cic_interpolate(p, plo, dxi, uccarr, v); @@ -258,8 +258,9 @@ TracerParticleContainer::Timestamp (const std::string& basename, TimeStampFile.seekp(0, std::ios::end); - if (!TimeStampFile.good()) + if (!TimeStampFile.good()) { amrex::FileOpenFailed(FileName); + } const auto M = static_cast(indices.size()); const BoxArray& ba = mf.boxArray(); @@ -299,11 +300,11 @@ TracerParticleContainer::Timestamp (const std::string& basename, { const ParticleType& p = pbox[k]; - if (p.id() <= 0) continue; + if (p.id() <= 0) { continue; } const IntVect& iv = Index(p,lev); - if (!bx.contains(iv) && !ba.contains(iv)) continue; + if (!bx.contains(iv) && !ba.contains(iv)) { continue; } TimeStampFile << p.id() << ' ' << p.cpu() << ' '; @@ -321,7 +322,7 @@ TracerParticleContainer::Timestamp (const std::string& basename, if (M > 0) { - cic_interpolate(p, plo, dxi, *uccarr_ptr, &vals[0], M); + cic_interpolate(p, plo, dxi, *uccarr_ptr, vals.data(), M); for (int i = 0; i < M; i++) { @@ -341,8 +342,9 @@ TracerParticleContainer::Timestamp (const std::string& basename, const int wakeUpPID = (MyProc + nOutFiles); const int tag = (MyProc % nOutFiles); - if (wakeUpPID < NProcs) + if (wakeUpPID < NProcs) { ParallelDescriptor::Send(&iBuff, 1, wakeUpPID, tag); + } } if (mySet == (iSet + 1)) { @@ -369,6 +371,6 @@ TracerParticleContainer::Timestamp (const std::string& basename, #ifdef AMREX_LAZY }); #endif - } + } } } diff --git a/Src/Particle/AMReX_WriteBinaryParticleData.H b/Src/Particle/AMReX_WriteBinaryParticleData.H index 40203e17c12..8a67ac62d45 100644 --- a/Src/Particle/AMReX_WriteBinaryParticleData.H +++ b/Src/Particle/AMReX_WriteBinaryParticleData.H @@ -129,7 +129,7 @@ countFlags (const Vector,Container>>& const auto& pflags = particle_io_flags[lev].at(kv.first); for (int k = 0; k < kv.second.numParticles(); ++k) { - if (pflags[k]) nparticles++; + if (pflags[k]) { nparticles++; } } } } @@ -143,7 +143,7 @@ countFlags (const Container& pflags) int nparticles = 0; for (std::size_t k = 0; k < pflags.size(); ++k) { - if (pflags[k]) nparticles++; + if (pflags[k]) { nparticles++; } } return nparticles; } @@ -175,15 +175,17 @@ packIOData (Vector& idata, Vector& rdata, const PC& pc, int l const Vector& tiles, int np, bool is_checkpoint) { int num_output_int = 0; - for (int i = 0; i < pc.NumIntComps() + PC::NStructInt; ++i) - if (write_int_comp[i]) ++num_output_int; + for (int i = 0; i < pc.NumIntComps() + PC::NStructInt; ++i) { + if (write_int_comp[i]) { ++num_output_int; } + } const Long iChunkSize = 2 + num_output_int; idata.resize(np*iChunkSize); int num_output_real = 0; - for (int i = 0; i < pc.NumRealComps() + PC::NStructReal; ++i) - if (write_real_comp[i]) ++num_output_real; + for (int i = 0; i < pc.NumRealComps() + PC::NStructReal; ++i) { + if (write_real_comp[i]) { ++num_output_real; } + } const Long rChunkSize = AMREX_SPACEDIM + num_output_real; rdata.resize(np*rChunkSize); @@ -279,20 +281,22 @@ packIOData (Vector& idata, Vector& rdata, const PC& pc, int l const Vector& tiles, int np, bool is_checkpoint) { int num_output_int = 0; - for (int i = 0; i < pc.NumIntComps() + PC::NStructInt; ++i) - if (write_int_comp[i]) ++num_output_int; + for (int i = 0; i < pc.NumIntComps() + PC::NStructInt; ++i) { + if (write_int_comp[i]) { ++num_output_int; } + } const Long iChunkSize = 2 + num_output_int; idata.resize(np*iChunkSize); int num_output_real = 0; - for (int i = 0; i < pc.NumRealComps() + PC::NStructReal; ++i) - if (write_real_comp[i]) ++num_output_real; + for (int i = 0; i < pc.NumRealComps() + PC::NStructReal; ++i) { + if (write_real_comp[i]) { ++num_output_real; } + } const Long rChunkSize = AMREX_SPACEDIM + num_output_real; rdata.resize(np*rChunkSize); - int* iptr = idata.dataPtr(); + int* iptr = idata.dataPtr(); ParticleReal* rptr = rdata.dataPtr(); for (unsigned i = 0; i < tiles.size(); i++) { const auto& ptile = pc.ParticlesAt(lev, grid, tiles[i]); @@ -313,7 +317,7 @@ packIOData (Vector& idata, Vector& rdata, const PC& pc, int l iptr += 2; // Real: positions - for (int j = 0; j < AMREX_SPACEDIM; j++) rptr[j] = p.pos(j); + for (int j = 0; j < AMREX_SPACEDIM; j++) { rptr[j] = p.pos(j); } rptr += AMREX_SPACEDIM; // extra AoS Int components @@ -340,7 +344,7 @@ packIOData (Vector& idata, Vector& rdata, const PC& pc, int l iptr += 1; // Real: position - for (int j = 0; j < AMREX_SPACEDIM; j++) rptr[j] = soa.GetRealData(j)[pindex]; + for (int j = 0; j < AMREX_SPACEDIM; j++) { rptr[j] = soa.GetRealData(j)[pindex]; } rptr += AMREX_SPACEDIM; } @@ -392,7 +396,7 @@ void WriteBinaryParticleDataSync (PC const& pc, AMREX_ALWAYS_ASSERT( int_comp_names.size() == pc.NumIntComps() + NStructInt); std::string pdir = dir; - if ( ! pdir.empty() && pdir[pdir.size()-1] != '/') pdir += '/'; + if ( ! pdir.empty() && pdir[pdir.size()-1] != '/') { pdir += '/'; } pdir += name; if ( ! pc.GetLevelDirectoriesCreated()) { @@ -444,15 +448,16 @@ void WriteBinaryParticleDataSync (PC const& pc, { std::string HdrFileName = pdir; - if ( ! HdrFileName.empty() && HdrFileName[HdrFileName.size()-1] != '/') + if ( ! HdrFileName.empty() && HdrFileName[HdrFileName.size()-1] != '/') { HdrFileName += '/'; + } HdrFileName += "Header"; pc.HdrFileNamePrePost = HdrFileName; HdrFile.open(HdrFileName.c_str(), std::ios::out|std::ios::trunc); - if ( ! HdrFile.good()) amrex::FileOpenFailed(HdrFileName); + if ( ! HdrFile.good()) { amrex::FileOpenFailed(HdrFileName); } // // First thing written is our version string. @@ -470,12 +475,14 @@ void WriteBinaryParticleDataSync (PC const& pc, } int num_output_real = 0; - for (int i = 0; i < pc.NumRealComps() + NStructReal; ++i) - if (write_real_comp[i]) ++num_output_real; + for (int i = 0; i < pc.NumRealComps() + NStructReal; ++i) { + if (write_real_comp[i]) { ++num_output_real; } + } int num_output_int = 0; - for (int i = 0; i < pc.NumIntComps() + NStructInt; ++i) - if (write_int_comp[i]) ++num_output_int; + for (int i = 0; i < pc.NumIntComps() + NStructInt; ++i) { + if (write_int_comp[i]) { ++num_output_int; } + } // AMREX_SPACEDIM and N for sanity checking. HdrFile << AMREX_SPACEDIM << '\n'; @@ -484,15 +491,17 @@ void WriteBinaryParticleDataSync (PC const& pc, HdrFile << num_output_real << '\n'; // Real component names - for (int i = 0; i < NStructReal + pc.NumRealComps(); ++i ) - if (write_real_comp[i]) HdrFile << real_comp_names[i] << '\n'; + for (int i = 0; i < NStructReal + pc.NumRealComps(); ++i ) { + if (write_real_comp[i]) { HdrFile << real_comp_names[i] << '\n'; } + } // The number of extra int parameters HdrFile << num_output_int << '\n'; // int component names - for (int i = 0; i < NStructInt + pc.NumIntComps(); ++i ) - if (write_int_comp[i]) HdrFile << int_comp_names[i] << '\n'; + for (int i = 0; i < NStructInt + pc.NumIntComps(); ++i ) { + if (write_int_comp[i]) { HdrFile << int_comp_names[i] << '\n'; } + } bool is_checkpoint_legacy = true; // legacy HdrFile << is_checkpoint_legacy << '\n'; @@ -507,8 +516,9 @@ void WriteBinaryParticleDataSync (PC const& pc, HdrFile << pc.finestLevel() << '\n'; // Then the number of grids at each level. - for (int lev = 0; lev <= pc.finestLevel(); lev++) + for (int lev = 0; lev <= pc.finestLevel(); lev++) { HdrFile << pc.ParticleBoxArray(lev).size() << '\n'; + } } // We want to write the data out in parallel. @@ -517,7 +527,7 @@ void WriteBinaryParticleDataSync (PC const& pc, ParmParse pp("particles"); pp.queryAdd("particles_nfiles",nOutFiles); - if(nOutFiles == -1) nOutFiles = NProcs; + if(nOutFiles == -1) { nOutFiles = NProcs; } nOutFiles = std::max(1, std::min(nOutFiles,NProcs)); pc.nOutFilesPrePost = nOutFiles; @@ -538,15 +548,17 @@ void WriteBinaryParticleDataSync (PC const& pc, if (gotsome) { - if ( ! LevelDir.empty() && LevelDir[LevelDir.size()-1] != '/') LevelDir += '/'; + if ( ! LevelDir.empty() && LevelDir[LevelDir.size()-1] != '/') { LevelDir += '/'; } LevelDir = amrex::Concatenate(LevelDir.append("Level_"), lev, 1); if ( ! pc.GetLevelDirectoriesCreated()) { - if (ParallelDescriptor::IOProcessor()) - if ( ! amrex::UtilCreateDirectory(LevelDir, 0755)) + if (ParallelDescriptor::IOProcessor()) { + if ( ! amrex::UtilCreateDirectory(LevelDir, 0755)) { amrex::CreateDirectoryFailed(LevelDir); + } + } ParallelDescriptor::Barrier(); } } @@ -715,7 +727,7 @@ void WriteBinaryParticleDataAsync (PC const& pc, } std::string pdir = dir; - if ( ! pdir.empty() && pdir[pdir.size()-1] != '/') pdir += '/'; + if ( ! pdir.empty() && pdir[pdir.size()-1] != '/') { pdir += '/'; } pdir += name; if (MyProc == IOProcNumber) @@ -735,7 +747,7 @@ void WriteBinaryParticleDataAsync (PC const& pc, if (gotsome) { - if ( ! LevelDir.empty() && LevelDir[LevelDir.size()-1] != '/') LevelDir += '/'; + if ( ! LevelDir.empty() && LevelDir[LevelDir.size()-1] != '/') { LevelDir += '/'; } LevelDir = amrex::Concatenate(LevelDir.append("Level_"), lev, 1); @@ -810,11 +822,13 @@ void WriteBinaryParticleDataAsync (PC const& pc, new_ptile.define(runtime_real_comps, runtime_int_comps); - for (auto comp(0); comp < runtime_real_comps; ++comp) - new_ptile.push_back_real(NArrayReal+comp, np, 0.); + for (auto comp(0); comp < runtime_real_comps; ++comp) { + new_ptile.push_back_real(NArrayReal+comp, np, 0.); + } - for (auto comp(0); comp < runtime_int_comps; ++comp) - new_ptile.push_back_int(NArrayInt+comp, np, 0); + for (auto comp(0); comp < runtime_int_comps; ++comp) { + new_ptile.push_back_int(NArrayInt+comp, np, 0); + } amrex::filterParticles(new_ptile, ptile, KeepValidFilter()); } @@ -845,14 +859,15 @@ void WriteBinaryParticleDataAsync (PC const& pc, std::string HdrFileName = pdir; std::ofstream HdrFile; - if ( ! HdrFileName.empty() && HdrFileName[HdrFileName.size()-1] != '/') + if ( ! HdrFileName.empty() && HdrFileName[HdrFileName.size()-1] != '/') { HdrFileName += '/'; + } HdrFileName += "Header"; HdrFile.open(HdrFileName.c_str(), std::ios::out|std::ios::trunc); - if ( ! HdrFile.good()) amrex::FileOpenFailed(HdrFileName); + if ( ! HdrFile.good()) { amrex::FileOpenFailed(HdrFileName); } std::string version_string = is_checkpoint ? PC::CheckpointVersion() : PC::PlotfileVersion(); if (sizeof(typename PC::ParticleType::RealType) == 4) @@ -865,12 +880,14 @@ void WriteBinaryParticleDataAsync (PC const& pc, } int num_output_real = 0; - for (int i = 0; i < nrc + NStructReal; ++i) - if (write_real_comp[i]) ++num_output_real; + for (int i = 0; i < nrc + NStructReal; ++i) { + if (write_real_comp[i]) { ++num_output_real; } + } int num_output_int = 0; - for (int i = 0; i < nic + NStructInt; ++i) - if (write_int_comp[i]) ++num_output_int; + for (int i = 0; i < nic + NStructInt; ++i) { + if (write_int_comp[i]) { ++num_output_int; } + } // AMREX_SPACEDIM and N for sanity checking. HdrFile << AMREX_SPACEDIM << '\n'; @@ -879,15 +896,17 @@ void WriteBinaryParticleDataAsync (PC const& pc, HdrFile << num_output_real << '\n'; // Real component names - for (int i = 0; i < NStructReal + nrc; ++i ) - if (write_real_comp[i]) HdrFile << real_comp_names[i] << '\n'; + for (int i = 0; i < NStructReal + nrc; ++i ) { + if (write_real_comp[i]) { HdrFile << real_comp_names[i] << '\n'; } + } // The number of extra int parameters HdrFile << num_output_int << '\n'; // int component names - for (int i = 0; i < NStructInt + nic; ++i ) - if (write_int_comp[i]) HdrFile << int_comp_names[i] << '\n'; + for (int i = 0; i < NStructInt + nic; ++i ) { + if (write_int_comp[i]) { HdrFile << int_comp_names[i] << '\n'; } + } bool is_checkpoint_legacy = true; // legacy HdrFile << is_checkpoint_legacy << '\n'; @@ -902,8 +921,9 @@ void WriteBinaryParticleDataAsync (PC const& pc, HdrFile << finest_level << '\n'; // Then the number of grids at each level. - for (int lev = 0; lev <= finest_level; lev++) + for (int lev = 0; lev <= finest_level; lev++) { HdrFile << dms[lev].size() << '\n'; + } for (int lev = 0; lev <= finest_level; lev++) { @@ -942,7 +962,7 @@ void WriteBinaryParticleDataAsync (PC const& pc, } std::string LevelDir = pdir; - if ( ! LevelDir.empty() && LevelDir[LevelDir.size()-1] != '/') LevelDir += '/'; + if ( ! LevelDir.empty() && LevelDir[LevelDir.size()-1] != '/') { LevelDir += '/'; } LevelDir = amrex::Concatenate(LevelDir.append("Level_"), lev, 1); std::string filePrefix(LevelDir); filePrefix += '/'; @@ -956,14 +976,15 @@ void WriteBinaryParticleDataAsync (PC const& pc, for (int k = 0; k < bas[lev].size(); ++k) { int rank = dms[lev][k]; - if (rank != MyProc) continue; + if (rank != MyProc) { continue; } const int grid = k; - if (np_per_grid_local[lev][grid] == 0) continue; + if (np_per_grid_local[lev][grid] == 0) { continue; } // First write out the integer data in binary. int num_output_int = 0; - for (int i = 0; i < nic + NStructInt; ++i) - if (write_int_comp[i]) ++num_output_int; + for (int i = 0; i < nic + NStructInt; ++i) { + if (write_int_comp[i]) { ++num_output_int; } + } const Long iChunkSize = 2 + num_output_int; Vector istuff(np_per_grid_local[lev][grid]*iChunkSize); @@ -978,7 +999,7 @@ void WriteBinaryParticleDataAsync (PC const& pc, const auto& soa = pbox.GetStructOfArrays(); const auto& p = make_particle{}(ptd, pindex); - if (p.id() <= 0) continue; + if (p.id() <= 0) { continue; } // note: for pure SoA particle layouts, we do write the id, cpu and positions as a struct // for backwards compatibility with readers @@ -1024,8 +1045,9 @@ void WriteBinaryParticleDataAsync (PC const& pc, // Write the Real data in binary. int num_output_real = 0; - for (int i = 0; i < nrc + NStructReal; ++i) - if (write_real_comp[i]) ++num_output_real; + for (int i = 0; i < nrc + NStructReal; ++i) { + if (write_real_comp[i]) { ++num_output_real; } + } const Long rChunkSize = AMREX_SPACEDIM + num_output_real; Vector rstuff(np_per_grid_local[lev][grid]*rChunkSize); @@ -1041,12 +1063,12 @@ void WriteBinaryParticleDataAsync (PC const& pc, const auto& soa = pbox.GetStructOfArrays(); const auto& p = make_particle{}(ptd, pindex); - if (p.id() <= 0) continue; + if (p.id() <= 0) { continue; } if constexpr(!PC::ParticleType::is_soa_particle) { // Real: position - for (int j = 0; j < AMREX_SPACEDIM; j++) rptr[j] = p.pos(j); + for (int j = 0; j < AMREX_SPACEDIM; j++) { rptr[j] = p.pos(j); } rptr += AMREX_SPACEDIM; // extra AoS real @@ -1061,7 +1083,7 @@ void WriteBinaryParticleDataAsync (PC const& pc, } else { // Real: position - for (int j = 0; j < AMREX_SPACEDIM; j++) rptr[j] = soa.GetRealData(j)[pindex]; + for (int j = 0; j < AMREX_SPACEDIM; j++) { rptr[j] = soa.GetRealData(j)[pindex]; } rptr += AMREX_SPACEDIM; }