From 6f039ae18e892c606c06fab7111bf11b57c8975a Mon Sep 17 00:00:00 2001 From: Axel Huebl Date: Tue, 6 Aug 2024 17:55:40 -0500 Subject: [PATCH] Bins: Index Type `int` (#3684) ## Summary For performance reasons, `int`/`long` are better index types since they do not have over/underflow checks and thus vectorize better. Also, I see narrowing warnings casting from `int` to AMReX' `unsigned int` in WarpX. ## Additional background Seen with clang-tidy in https://github.com/ECP-WarpX/WarpX/pull/3850 ## Checklist The proposed changes: - [ ] fix a bug or incorrect behavior in AMReX - [ ] add new capabilities to AMReX - [ ] changes answers in the test suite to more than roundoff level - [ ] are likely to significantly affect the results of downstream AMReX users - [ ] include documentation in the code and/or rst files, if appropriate --- Src/Particle/AMReX_BinIterator.H | 2 +- Src/Particle/AMReX_DenseBins.H | 4 ++-- Src/Particle/AMReX_NeighborList.H | 6 +++--- Src/Particle/AMReX_NeighborParticlesI.H | 2 +- Src/Particle/AMReX_SparseBins.H | 6 +++--- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Src/Particle/AMReX_BinIterator.H b/Src/Particle/AMReX_BinIterator.H index f57b61a0371..a5422a48fac 100644 --- a/Src/Particle/AMReX_BinIterator.H +++ b/Src/Particle/AMReX_BinIterator.H @@ -22,7 +22,7 @@ constexpr bool IsParticleTileData (Args...) { template struct BinIterator { - using index_type = unsigned int; + using index_type = int; using const_pointer_type = std::conditional_t(), T, diff --git a/Src/Particle/AMReX_DenseBins.H b/Src/Particle/AMReX_DenseBins.H index 24c9cc293cb..ec5aebd6a20 100644 --- a/Src/Particle/AMReX_DenseBins.H +++ b/Src/Particle/AMReX_DenseBins.H @@ -30,7 +30,7 @@ namespace BinPolicy template struct DenseBinIteratorFactory { - using index_type = unsigned int; + using index_type = int; using const_pointer_type = std::conditional_t(), T, @@ -78,7 +78,7 @@ class DenseBins public: using BinIteratorFactory = DenseBinIteratorFactory; - using index_type = unsigned int; + using index_type = int; using const_pointer_type = std::conditional_t(), T, diff --git a/Src/Particle/AMReX_NeighborList.H b/Src/Particle/AMReX_NeighborList.H index 53434ec7c3c..6233a41002a 100644 --- a/Src/Particle/AMReX_NeighborList.H +++ b/Src/Particle/AMReX_NeighborList.H @@ -310,8 +310,8 @@ public: m_pstruct = aos().dataPtr(); auto* const pstruct_ptr = aos().dataPtr(); - const size_t np_total = aos.size(); - const size_t np_real = src_tile.numRealParticles(); + const int np_total = aos.size(); + const int np_real = src_tile.numRealParticles(); auto const* off_bins_p = off_bins_v.data(); auto const* dxi_p = dxi_v.data(); @@ -333,7 +333,7 @@ public: // First pass: count the number of neighbors for each particle //--------------------------------------------------------------------------------------------------------- - const size_t np_size = (num_bin_types > 1) ? np_total : np_real; + const int np_size = (num_bin_types > 1) ? np_total : np_real; m_nbor_counts.resize( np_size+1, 0); m_nbor_offsets.resize(np_size+1); diff --git a/Src/Particle/AMReX_NeighborParticlesI.H b/Src/Particle/AMReX_NeighborParticlesI.H index ca1747b6b8b..8e5bb2b2563 100644 --- a/Src/Particle/AMReX_NeighborParticlesI.H +++ b/Src/Particle/AMReX_NeighborParticlesI.H @@ -1065,7 +1065,7 @@ selectActualNeighbors (CheckPair const& check_pair, int num_cells) 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] == int(i)) { continue; } if (detail::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)) { diff --git a/Src/Particle/AMReX_SparseBins.H b/Src/Particle/AMReX_SparseBins.H index fb026a8ca88..1629a997597 100644 --- a/Src/Particle/AMReX_SparseBins.H +++ b/Src/Particle/AMReX_SparseBins.H @@ -14,7 +14,7 @@ template struct SparseBinIteratorFactory { - using index_type = unsigned int; + using index_type = int; using const_pointer_type = std::conditional_t(), T, @@ -33,7 +33,7 @@ struct SparseBinIteratorFactory : m_bins_ptr(bins.dataPtr()), m_offsets_ptr(offsets.dataPtr()), m_permutation_ptr(permutation.dataPtr()), - m_items(items), m_num_bins(bins.size()) + m_items(items), m_num_bins(int(bins.size())) {} [[nodiscard]] AMREX_GPU_HOST_DEVICE @@ -97,7 +97,7 @@ public: using BinIteratorFactory = SparseBinIteratorFactory; using bin_type = IntVect; - using index_type = unsigned int; + using index_type = int; using const_pointer_type = std::conditional_t(), T,