Skip to content

Commit 86b41a2

Browse files
authored
Merge pull request #793 from streeve/fixup_lcl_neigh_interface
Fixup LinkedCellList neighbor interface
2 parents facdb90 + e00db62 commit 86b41a2

File tree

2 files changed

+26
-28
lines changed

2 files changed

+26
-28
lines changed

core/src/Cabana_LinkedCellList.hpp

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -761,18 +761,29 @@ class NeighborList<LinkedCellList<MemorySpace, Scalar>>
761761
//! Neighbor list type.
762762
using list_type = LinkedCellList<MemorySpace, Scalar>;
763763

764-
//! Get the maximum number of neighbors per particle.
764+
//! Get the total number of neighbors across all particles.
765765
KOKKOS_INLINE_FUNCTION static std::size_t
766766
totalNeighbor( const list_type& list )
767767
{
768-
return Impl::totalNeighbor( list, list.numParticles() );
768+
std::size_t total_n = 0;
769+
// Sum neighbors across all particles in range.
770+
for ( std::size_t p = list.getParticleBegin();
771+
p < list.getParticleEnd(); p++ )
772+
total_n += numNeighbor( list, p );
773+
return total_n;
769774
}
770775

771-
//! Get the maximum number of neighbors across all particles.
776+
//! Get the maximum number of neighbors per particles.
772777
KOKKOS_INLINE_FUNCTION
773778
static std::size_t maxNeighbor( const list_type& list )
774779
{
775-
return Impl::maxNeighbor( list, list.numParticles() );
780+
std::size_t max_n = 0;
781+
// Max neighbors across all particles in range.
782+
for ( std::size_t p = list.getParticleBegin();
783+
p < list.getParticleEnd(); p++ )
784+
if ( numNeighbor( list, p ) > max_n )
785+
max_n = numNeighbor( list, p );
786+
return max_n;
776787
}
777788

778789
//! Get the number of neighbors for a given particle index.
@@ -817,14 +828,7 @@ class NeighborList<LinkedCellList<MemorySpace, Scalar>>
817828
{
818829
int particle_id = list.binOffset( i, j, k ) +
819830
( neighbor_index - previous_count );
820-
if ( list.sorted() )
821-
{
822-
return particle_id + list.getParticleBegin();
823-
}
824-
else
825-
{
826-
return list.permutation( particle_id );
827-
}
831+
return list.getParticle( particle_id );
828832
}
829833
previous_count = total_count;
830834
}

core/src/Cabana_Parallel.hpp

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,18 +1283,15 @@ struct LinkedCellParallelReduce
12831283
// neighbors.
12841284
auto offset = _list.binOffset( gi, gj, gk );
12851285
auto size = _list.binSize( gi, gj, gk );
1286-
for ( std::size_t j = offset; j < offset + size; ++j )
1286+
for ( std::size_t n = offset; n < offset + size; ++n )
12871287
{
12881288
// Get the true id of the candidate neighbor.
1289-
std::size_t jj;
1290-
if ( !_list.sorted() )
1291-
jj = _list.permutation( j );
1292-
else
1293-
jj = j + _begin;
1289+
auto j = _list.getParticle( n );
1290+
12941291
// Avoid self interactions (dummy position args).
1295-
if ( _discriminator.isValid( i, 0, 0, 0, jj, 0, 0, 0 ) )
1292+
if ( _discriminator.isValid( i, 0, 0, 0, j, 0, 0, 0 ) )
12961293
{
1297-
Impl::functorTagDispatch<WorkTag>( _functor, i, jj,
1294+
Impl::functorTagDispatch<WorkTag>( _functor, i, j,
12981295
ival );
12991296
}
13001297
}
@@ -1322,20 +1319,17 @@ struct LinkedCellParallelReduce
13221319
auto size = _list.binSize( gi, gj, gk );
13231320
Kokkos::parallel_for(
13241321
Kokkos::TeamThreadRange( team, offset, offset + size ),
1325-
[&]( const index_type j )
1322+
[&]( const index_type n )
13261323
{
13271324
// Get the true id of the candidate neighbor.
1328-
std::size_t jj;
1329-
if ( !_list.sorted() )
1330-
jj = _list.permutation( j );
1331-
else
1332-
jj = j + _begin;
1325+
auto j = _list.getParticle( n );
1326+
13331327
// Avoid self interactions (dummy position args).
1334-
if ( _discriminator.isValid( i, 0, 0, 0, jj, 0, 0,
1328+
if ( _discriminator.isValid( i, 0, 0, 0, j, 0, 0,
13351329
0 ) )
13361330
{
13371331
Impl::functorTagDispatch<WorkTag>( _functor, i,
1338-
jj, ival );
1332+
j, ival );
13391333
}
13401334
} );
13411335
}

0 commit comments

Comments
 (0)