Skip to content

Commit 6f039ae

Browse files
authored
Bins: Index Type int (AMReX-Codes#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 BLAST-WarpX/warpx#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
1 parent 30caf09 commit 6f039ae

File tree

5 files changed

+10
-10
lines changed

5 files changed

+10
-10
lines changed

Src/Particle/AMReX_BinIterator.H

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ constexpr bool IsParticleTileData (Args...) {
2222
template <typename T>
2323
struct BinIterator
2424
{
25-
using index_type = unsigned int;
25+
using index_type = int;
2626

2727
using const_pointer_type = std::conditional_t<IsParticleTileData<T>(),
2828
T,

Src/Particle/AMReX_DenseBins.H

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace BinPolicy
3030
template <typename T>
3131
struct DenseBinIteratorFactory
3232
{
33-
using index_type = unsigned int;
33+
using index_type = int;
3434

3535
using const_pointer_type = std::conditional_t<IsParticleTileData<T>(),
3636
T,
@@ -78,7 +78,7 @@ class DenseBins
7878
public:
7979

8080
using BinIteratorFactory = DenseBinIteratorFactory<T>;
81-
using index_type = unsigned int;
81+
using index_type = int;
8282

8383
using const_pointer_type = std::conditional_t<IsParticleTileData<T>(),
8484
T,

Src/Particle/AMReX_NeighborList.H

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,8 @@ public:
310310
m_pstruct = aos().dataPtr();
311311
auto* const pstruct_ptr = aos().dataPtr();
312312

313-
const size_t np_total = aos.size();
314-
const size_t np_real = src_tile.numRealParticles();
313+
const int np_total = aos.size();
314+
const int np_real = src_tile.numRealParticles();
315315

316316
auto const* off_bins_p = off_bins_v.data();
317317
auto const* dxi_p = dxi_v.data();
@@ -333,7 +333,7 @@ public:
333333

334334
// First pass: count the number of neighbors for each particle
335335
//---------------------------------------------------------------------------------------------------------
336-
const size_t np_size = (num_bin_types > 1) ? np_total : np_real;
336+
const int np_size = (num_bin_types > 1) ? np_total : np_real;
337337
m_nbor_counts.resize( np_size+1, 0);
338338
m_nbor_offsets.resize(np_size+1);
339339

Src/Particle/AMReX_NeighborParticlesI.H

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1065,7 +1065,7 @@ selectActualNeighbors (CheckPair const& check_pair, int num_cells)
10651065
if (isActualNeighbor) { break; }
10661066
int nbr_cell_id = (ii * ny + jj) * nz + kk;
10671067
for (auto p = poffset[nbr_cell_id]; p < poffset[nbr_cell_id+1]; ++p) {
1068-
if (pperm[p] == i) { continue; }
1068+
if (pperm[p] == int(i)) { continue; }
10691069
if (detail::call_check_pair(check_pair, ptile_data, ptile_data, i, pperm[p])) {
10701070
IntVect cell_ijk = getParticleCell(pstruct[pperm[p]], plo, dxi, domain);
10711071
if (!box.contains(cell_ijk)) {

Src/Particle/AMReX_SparseBins.H

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ template <typename T>
1414
struct SparseBinIteratorFactory
1515
{
1616

17-
using index_type = unsigned int;
17+
using index_type = int;
1818

1919
using const_pointer_type = std::conditional_t<IsParticleTileData<T>(),
2020
T,
@@ -33,7 +33,7 @@ struct SparseBinIteratorFactory
3333
: m_bins_ptr(bins.dataPtr()),
3434
m_offsets_ptr(offsets.dataPtr()),
3535
m_permutation_ptr(permutation.dataPtr()),
36-
m_items(items), m_num_bins(bins.size())
36+
m_items(items), m_num_bins(int(bins.size()))
3737
{}
3838

3939
[[nodiscard]] AMREX_GPU_HOST_DEVICE
@@ -97,7 +97,7 @@ public:
9797

9898
using BinIteratorFactory = SparseBinIteratorFactory<T>;
9999
using bin_type = IntVect;
100-
using index_type = unsigned int;
100+
using index_type = int;
101101

102102
using const_pointer_type = std::conditional_t<IsParticleTileData<T>(),
103103
T,

0 commit comments

Comments
 (0)