From 105c4229492296340aece2735f332a6f054e872d Mon Sep 17 00:00:00 2001 From: Axel Huebl Date: Fri, 8 Dec 2023 09:17:21 -0800 Subject: [PATCH] Inline Comment, Branch Order - add an inline comment for a size - simplify branch order to avoid negation in short `if constexpr` statements --- Src/Particle/AMReX_ParticleContainerI.H | 52 ++++++++++++------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/Src/Particle/AMReX_ParticleContainerI.H b/Src/Particle/AMReX_ParticleContainerI.H index 3ce9286e946..9dd1d39b953 100644 --- a/Src/Particle/AMReX_ParticleContainerI.H +++ b/Src/Particle/AMReX_ParticleContainerI.H @@ -18,10 +18,10 @@ ParticleContainer_impl; @@ -1530,7 +1530,7 @@ ParticleContainer_implnumParticles(); ParticleLocData pld; - if constexpr(!ParticleType::is_soa_particle){ + if constexpr (!ParticleType::is_soa_particle){ if (npart != 0) { Long last = npart - 1; @@ -1647,7 +1647,7 @@ ParticleContainer_impl >& not_ours, Particle p; - if constexpr (!ParticleType::is_soa_particle) { - std::memcpy(&p, pbuf, sizeof(ParticleType)); - } else { + if constexpr (ParticleType::is_soa_particle) { std::memcpy(&p.m_idcpu, pbuf, sizeof(uint64_t)); ParticleReal pos[AMREX_SPACEDIM]; @@ -2076,6 +2074,8 @@ RedistributeMPI (std::map >& not_ours, AMREX_D_TERM(p.pos(0) = pos[0];, p.pos(1) = pos[1];, p.pos(2) = pos[2]); + } else { + std::memcpy(&p, pbuf, sizeof(ParticleType)); } bool success = Where(p, pld, lev_min, lev_max, 0); @@ -2114,16 +2114,16 @@ RedistributeMPI (std::map >& not_ours, rcv_tile[ipart])]; char* pbuf = ((char*) &recvdata[offset]) + j*superparticle_size; - if constexpr(! ParticleType::is_soa_particle) { - ParticleType p; - std::memcpy(&p, pbuf, sizeof(ParticleType)); - pbuf += sizeof(ParticleType); - ptile.push_back(p); - } else { + if constexpr (ParticleType::is_soa_particle) { uint64_t idcpudata; std::memcpy(&idcpudata, pbuf, sizeof(uint64_t)); pbuf += sizeof(uint64_t); ptile.GetStructOfArrays().GetIdCPUData().push_back(idcpudata); + } else { + ParticleType p; + std::memcpy(&p, pbuf, sizeof(ParticleType)); + pbuf += sizeof(ParticleType); + ptile.push_back(p); } int array_comp_start = AMREX_SPACEDIM + NStructReal; @@ -2188,16 +2188,16 @@ RedistributeMPI (std::map >& not_ours, host_real_attribs[lev][ind].resize(NumRealComps()); host_int_attribs[lev][ind].resize(NumIntComps()); - if constexpr(! ParticleType::is_soa_particle) { - ParticleType p; - std::memcpy(&p, pbuf, sizeof(ParticleType)); - pbuf += sizeof(ParticleType); - host_particles[lev][ind].push_back(p); - } else { + if constexpr (ParticleType::is_soa_particle) { uint64_t idcpudata; std::memcpy(&idcpudata, pbuf, sizeof(uint64_t)); pbuf += sizeof(uint64_t); host_idcpu[lev][ind].push_back(idcpudata); + } else { + ParticleType p; + std::memcpy(&p, pbuf, sizeof(ParticleType)); + pbuf += sizeof(ParticleType); + host_particles[lev][ind].push_back(p); } host_real_attribs[lev][ind].resize(NumRealComps()); @@ -2244,15 +2244,15 @@ RedistributeMPI (std::map >& not_ours, auto new_size = old_size + src_tile.size(); dst_tile.resize(new_size); - if constexpr(! ParticleType::is_soa_particle) { - Gpu::copyAsync(Gpu::hostToDevice, - src_tile.begin(), src_tile.end(), - dst_tile.GetArrayOfStructs().begin() + old_size); - } else { + if constexpr (ParticleType::is_soa_particle) { Gpu::copyAsync(Gpu::hostToDevice, host_idcpu[host_lev][std::make_pair(grid,tile)].begin(), host_idcpu[host_lev][std::make_pair(grid,tile)].end(), dst_tile.GetStructOfArrays().GetIdCPUData().begin() + old_size); + } else { + Gpu::copyAsync(Gpu::hostToDevice, + src_tile.begin(), src_tile.end(), + dst_tile.GetArrayOfStructs().begin() + old_size); } for (int i = 0; i < NumRealComps(); ++i) {