Skip to content

Commit

Permalink
Merge remote-tracking branch 'cabana_http/lcl_neighbor' into lcl_neig…
Browse files Browse the repository at this point in the history
…hbor

Reorganize the linked cell parallel options and adds neighbor-based reduce with linked cell
  • Loading branch information
lebuller committed Nov 9, 2023
2 parents 9000ec4 + 2861252 commit fe2d6ac
Show file tree
Hide file tree
Showing 4 changed files with 715 additions and 233 deletions.
47 changes: 27 additions & 20 deletions core/src/Cabana_LinkedCellList.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ class LinkedCellList
return _particle_bins;
}

auto getParticleBin() const
auto getParticleBin( const int particle_index ) const
{
return _particle_bins( particle_index );
}
Expand Down Expand Up @@ -658,36 +658,45 @@ void permute(

//---------------------------------------------------------------------------//
//! LinkedCellList NeighborList interface.
template <class DeviceType, typename Scalar>
class NeighborList<LinkedCellList<DeviceType, Scalar>>
template <class MemorySpace, typename Scalar>
class NeighborList<LinkedCellList<MemorySpace, Scalar>>
{
public:
//! Kokkos memory space.
using device_type = DeviceType;
using memory_space = MemorySpace;
//! Neighbor list type.
using list_type = LinkedCellList<DeviceType, Scalar>;
using list_type = LinkedCellList<MemorySpace, Scalar>;

//! Get the maximum number of neighbors per particle.
template <class CellIndexType>
KOKKOS_INLINE_FUNCTION static std::size_t
maxNeighbor( const list_type& list, const CellIndexType cell )
totalNeighbor( const list_type& list )
{
int total_count = 0;
for ( int p = 0; p < list.numParticles(); ++p )
total_count += numNeighbor( list, cell, p );
total_count += numNeighbor( list, p );
return total_count;
}

//! Get the maximum number of neighbors across all particles.
KOKKOS_INLINE_FUNCTION
static std::size_t maxNeighbor( const list_type& list )
{
std::size_t max_n = 0;
// Loop across all particles to find maximum number of neighbors.
for ( std::size_t p = 0; p < list.numParticles(); p++ )
if ( numNeighbor( list, p ) > max_n )
max_n = numNeighbor( list, p );
return max_n;
}

//! Get the number of neighbors for a given particle index.
template <class CellIndexType>
KOKKOS_INLINE_FUNCTION static std::size_t
numNeighbor( const list_type& list,
const std::size_t particle_index )
numNeighbor( const list_type& list, const std::size_t particle_index )
{
int total_count = 0;
int imin, imax, jmin, jmax, kmin, kmax;
list.getStencilCells( list.getParticleBin( particle_index ), imin, imax, jmin, jmax,
kmin, kmax );
list.getStencilCells( list.getParticleBin( particle_index ), imin, imax,
jmin, jmax, kmin, kmax );

// Loop over the cell stencil.
for ( int i = imin; i < imax; ++i )
Expand All @@ -701,17 +710,15 @@ class NeighborList<LinkedCellList<DeviceType, Scalar>>

//! Get the id for a neighbor for a given particle index and the index of
//! the neighbor relative to the particle.
template <class CellIndexType>
KOKKOS_INLINE_FUNCTION static std::size_t
getNeighbor( const list_type& list,
const std::size_t particle_index,
getNeighbor( const list_type& list, const std::size_t particle_index,
const std::size_t neighbor_index )
{
size_t total_count = 0;
size_t previous_count = 0;
std::size_t total_count = 0;
std::size_t previous_count = 0;
int imin, imax, jmin, jmax, kmin, kmax;
list.getStencilCells( list.getParticleBin( particle_index ), imin, imax, jmin, jmax,
kmin, kmax );
list.getStencilCells( list.getParticleBin( particle_index ), imin, imax,
jmin, jmax, kmin, kmax );

// Loop over the cell stencil.
for ( int i = imin; i < imax; ++i )
Expand Down
Loading

0 comments on commit fe2d6ac

Please sign in to comment.