Skip to content

Commit

Permalink
Rename linked_cell_parallel to neighbor_parallel and add enable_if to…
Browse files Browse the repository at this point in the history
… avoid ambiguity
  • Loading branch information
lebuller committed Dec 5, 2023
1 parent 7ad8731 commit d4ff4f2
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 142 deletions.
48 changes: 34 additions & 14 deletions core/src/Cabana_Parallel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,9 @@ template <class FunctorType, class NeighborListType, class... ExecParameters>
inline void neighbor_parallel_for(
const Kokkos::RangePolicy<ExecParameters...>& exec_policy,
const FunctorType& functor, const NeighborListType& list,
const FirstNeighborsTag, const SerialOpTag, const std::string& str = "" )
const FirstNeighborsTag, const SerialOpTag, const std::string& str = "",
typename std::enable_if<( !is_linked_cell_list<NeighborListType>::value ),
int>::type* = 0 )
{
Kokkos::Profiling::pushRegion( "Cabana::neighbor_parallel_for" );

Expand Down Expand Up @@ -317,7 +319,9 @@ template <class FunctorType, class NeighborListType, class... ExecParameters>
inline void neighbor_parallel_for(
const Kokkos::RangePolicy<ExecParameters...>& exec_policy,
const FunctorType& functor, const NeighborListType& list,
const SecondNeighborsTag, const SerialOpTag, const std::string& str = "" )
const SecondNeighborsTag, const SerialOpTag, const std::string& str = "",
typename std::enable_if<( !is_linked_cell_list<NeighborListType>::value ),
int>::type* = 0)
{
Kokkos::Profiling::pushRegion( "Cabana::neighbor_parallel_for" );

Expand Down Expand Up @@ -388,7 +392,9 @@ template <class FunctorType, class NeighborListType, class... ExecParameters>
inline void neighbor_parallel_for(
const Kokkos::RangePolicy<ExecParameters...>& exec_policy,
const FunctorType& functor, const NeighborListType& list,
const FirstNeighborsTag, const TeamOpTag, const std::string& str = "" )
const FirstNeighborsTag, const TeamOpTag, const std::string& str = "",
typename std::enable_if<( !is_linked_cell_list<NeighborListType>::value ),
int>::type* = 0)
{
Kokkos::Profiling::pushRegion( "Cabana::neighbor_parallel_for" );

Expand Down Expand Up @@ -460,7 +466,9 @@ template <class FunctorType, class NeighborListType, class... ExecParameters>
inline void neighbor_parallel_for(
const Kokkos::RangePolicy<ExecParameters...>& exec_policy,
const FunctorType& functor, const NeighborListType& list,
const SecondNeighborsTag, const TeamOpTag, const std::string& str = "" )
const SecondNeighborsTag, const TeamOpTag, const std::string& str = "",
typename std::enable_if<( !is_linked_cell_list<NeighborListType>::value ),
int>::type* = 0)
{
Kokkos::Profiling::pushRegion( "Cabana::neighbor_parallel_for" );

Expand Down Expand Up @@ -539,7 +547,9 @@ inline void neighbor_parallel_for(
const Kokkos::RangePolicy<ExecParameters...>& exec_policy,
const FunctorType& functor, const NeighborListType& list,
const SecondNeighborsTag, const TeamVectorOpTag,
const std::string& str = "" )
const std::string& str = "",
typename std::enable_if<( !is_linked_cell_list<NeighborListType>::value ),
int>::type* = 0)
{
Kokkos::Profiling::pushRegion( "Cabana::neighbor_parallel_for" );

Expand Down Expand Up @@ -642,7 +652,9 @@ inline void neighbor_parallel_reduce(
const Kokkos::RangePolicy<ExecParameters...>& exec_policy,
const FunctorType& functor, const NeighborListType& list,
const FirstNeighborsTag, const SerialOpTag, ReduceType& reduce_val,
const std::string& str = "" )
const std::string& str = "",
typename std::enable_if<( !is_linked_cell_list<NeighborListType>::value ),
int>::type* = 0)
{
Kokkos::Profiling::pushRegion( "Cabana::neighbor_parallel_reduce" );

Expand Down Expand Up @@ -712,7 +724,9 @@ inline void neighbor_parallel_reduce(
const Kokkos::RangePolicy<ExecParameters...>& exec_policy,
const FunctorType& functor, const NeighborListType& list,
const SecondNeighborsTag, const SerialOpTag, ReduceType& reduce_val,
const std::string& str = "" )
const std::string& str = "",
typename std::enable_if<( !is_linked_cell_list<NeighborListType>::value ),
int>::type* = 0)
{
Kokkos::Profiling::pushRegion( "Cabana::neighbor_parallel_reduce" );

Expand Down Expand Up @@ -789,7 +803,9 @@ inline void neighbor_parallel_reduce(
const Kokkos::RangePolicy<ExecParameters...>& exec_policy,
const FunctorType& functor, const NeighborListType& list,
const FirstNeighborsTag, const TeamOpTag, ReduceType& reduce_val,
const std::string& str = "" )
const std::string& str = "",
typename std::enable_if<( !is_linked_cell_list<NeighborListType>::value ),
int>::type* = 0)
{
Kokkos::Profiling::pushRegion( "Cabana::neighbor_parallel_reduce" );

Expand Down Expand Up @@ -870,7 +886,9 @@ inline void neighbor_parallel_reduce(
const Kokkos::RangePolicy<ExecParameters...>& exec_policy,
const FunctorType& functor, const NeighborListType& list,
const SecondNeighborsTag, const TeamOpTag, ReduceType& reduce_val,
const std::string& str = "" )
const std::string& str = "",
typename std::enable_if<( !is_linked_cell_list<NeighborListType>::value ),
int>::type* = 0)
{
Kokkos::Profiling::pushRegion( "Cabana::neighbor_parallel_reduce" );

Expand Down Expand Up @@ -956,7 +974,9 @@ inline void neighbor_parallel_reduce(
const Kokkos::RangePolicy<ExecParameters...>& exec_policy,
const FunctorType& functor, const NeighborListType& list,
const SecondNeighborsTag, const TeamVectorOpTag, ReduceType& reduce_val,
const std::string& str = "" )
const std::string& str = "",
typename std::enable_if<( !is_linked_cell_list<NeighborListType>::value ),
int>::type* = 0)
{
Kokkos::Profiling::pushRegion( "Cabana::neighbor_parallel_reduce" );

Expand Down Expand Up @@ -1393,7 +1413,7 @@ struct LinkedCellParallelReduce
*/

template <class FunctorType, class LinkedCellType, class... ExecParameters>
inline void linked_cell_parallel_for(
inline void neighbor_parallel_for(
const Kokkos::RangePolicy<ExecParameters...>& exec_policy,
const FunctorType& functor, const LinkedCellType& list,
const FirstNeighborsTag, const SerialOpTag, const std::string& str = "",
Expand Down Expand Up @@ -1445,7 +1465,7 @@ inline void linked_cell_parallel_for(
*/

template <class FunctorType, class LinkedCellType, class... ExecParameters>
inline void linked_cell_parallel_for(
inline void neighbor_parallel_for(
const Kokkos::RangePolicy<ExecParameters...>& exec_policy,
const FunctorType& functor, const LinkedCellType& list,
const FirstNeighborsTag, const TeamOpTag, const std::string& str = "",
Expand Down Expand Up @@ -1516,7 +1536,7 @@ inline void linked_cell_parallel_for(
*/
template <class FunctorType, class LinkedCellType, class ReduceType,
class... ExecParameters>
inline void linked_cell_parallel_reduce(
inline void neighbor_parallel_reduce(
const Kokkos::RangePolicy<ExecParameters...>& exec_policy,
const FunctorType& functor, const LinkedCellType& list,
const FirstNeighborsTag, const SerialOpTag, ReduceType& reduce_val,
Expand Down Expand Up @@ -1571,7 +1591,7 @@ inline void linked_cell_parallel_reduce(
*/
template <class FunctorType, class LinkedCellType, class ReduceType,
class... ExecParameters>
inline void linked_cell_parallel_reduce(
inline void neighbor_parallel_reduce(
const Kokkos::RangePolicy<ExecParameters...>& exec_policy,
const FunctorType& functor, const LinkedCellType& list,
const FirstNeighborsTag, const TeamOpTag, ReduceType& reduce_val,
Expand Down
129 changes: 1 addition & 128 deletions core/unit_test/tstLinkedCellList.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,76 +407,6 @@ void testLinkedListSlice()
}
}

//---------------------------------------------------------------------------//
// linked_list_parallel
//---------------------------------------------------------------------------//
template <class ListType, class TestListType, class PositionType>
void checkLinkedCellParallel( const ListType& nlist,
const TestListType& N2_list_copy,
const int num_particle,
const PositionType positions,
const double cutoff )
{
// Create Kokkos views for the write operation.
using memory_space = typename TEST_MEMSPACE::memory_space;
Kokkos::View<int*, memory_space> serial_result( "serial_result",
num_particle );
Kokkos::View<int*, memory_space> team_result( "team_result", num_particle );

// Test the list parallel operation by adding a value from each neighbor
// to the particle (within cutoff) and compare to counts.
auto c2 = cutoff * cutoff;
auto serial_count_op = KOKKOS_LAMBDA( const int i, const int j )
{
const double dx = positions( i, 0 ) - positions( j, 0 );
const double dy = positions( i, 1 ) - positions( j, 1 );
const double dz = positions( i, 2 ) - positions( j, 2 );
const double r2 = dx * dx + dy * dy + dz * dz;
if ( r2 <= c2 )
{
if ( nlist.sorted() )
{
Kokkos::atomic_add( &serial_result( nlist.permutation( i ) ),
nlist.permutation( j ) );
}
else
{
Kokkos::atomic_add( &serial_result( i ), j );
}
}
};
auto team_count_op = KOKKOS_LAMBDA( const int i, const int j )
{
const double dx = positions( i, 0 ) - positions( j, 0 );
const double dy = positions( i, 1 ) - positions( j, 1 );
const double dz = positions( i, 2 ) - positions( j, 2 );
const double r2 = dx * dx + dy * dy + dz * dz;
if ( r2 <= c2 )
{
if ( nlist.sorted() )
{
Kokkos::atomic_add( &team_result( nlist.permutation( i ) ),
nlist.permutation( j ) );
}
else
{
Kokkos::atomic_add( &team_result( i ), j );
}
}
};
Kokkos::RangePolicy<TEST_EXECSPACE> policy( 0, num_particle );
Cabana::linked_cell_parallel_for(
policy, serial_count_op, nlist, Cabana::FirstNeighborsTag(),
Cabana::SerialOpTag(), "test_1st_serial" );
Cabana::linked_cell_parallel_for( policy, team_count_op, nlist,
Cabana::FirstNeighborsTag(),
Cabana::TeamOpTag(), "test_1st_team" );
Kokkos::fence();

checkFirstNeighborParallelFor( N2_list_copy, serial_result, team_result,
1 );
}

//---------------------------------------------------------------------------//
// linked_list_parallel
//---------------------------------------------------------------------------//
Expand Down Expand Up @@ -550,54 +480,6 @@ void checkLinkedCellNeighborParallel( const ListType& nlist,
1 );
}

//---------------------------------------------------------------------------//
// linked_list_parallel
//---------------------------------------------------------------------------//
template <class ListType, class TestListType, class AoSoAType>
void checkLinkedCellReduce( const ListType& nlist,
const TestListType& N2_list_copy,
const AoSoAType& aosoa, const int num_particle,
const double cutoff )
{
auto position = Cabana::slice<0>( aosoa );

// Test the list parallel operation by adding a value from each neighbor
// to the particle (within cutoff) and compare to counts.
auto c2 = cutoff * cutoff;
auto sum_op = KOKKOS_LAMBDA( const int i, const int j, double& sum )
{
const double dx = position( i, 0 ) - position( j, 0 );
const double dy = position( i, 1 ) - position( j, 1 );
const double dz = position( i, 2 ) - position( j, 2 );
const double r2 = dx * dx + dy * dy + dz * dz;
if ( r2 <= c2 )
{
if ( nlist.sorted() )
{
sum += position( nlist.permutation( i ), 0 ) +
position( nlist.permutation( j ), 0 );
}
else
{
sum += position( i, 0 ) + position( j, 0 );
}
}
};
Kokkos::RangePolicy<TEST_EXECSPACE> policy( 0, num_particle );
double serial_sum = 0;
Cabana::linked_cell_parallel_reduce(
policy, sum_op, nlist, Cabana::FirstNeighborsTag(),
Cabana::SerialOpTag(), serial_sum, "test_1st_serial" );
double team_sum = 0;
Cabana::linked_cell_parallel_reduce(
policy, sum_op, nlist, Cabana::FirstNeighborsTag(), Cabana::TeamOpTag(),
team_sum, "test_1st_team" );
Kokkos::fence();

checkFirstNeighborParallelReduce( N2_list_copy, aosoa, serial_sum, team_sum,
1 );
}

//---------------------------------------------------------------------------//
// linked_list_parallel
//---------------------------------------------------------------------------//
Expand Down Expand Up @@ -664,27 +546,18 @@ void testLinkedCellParallel()
positions, grid_delta, test_data.grid_min, test_data.grid_max,
test_data.test_radius, test_data.cell_size_ratio );

checkLinkedCellParallel( nlist, test_data.N2_list_copy,
test_data.num_particle, positions,
test_data.test_radius );
checkLinkedCellNeighborParallel( nlist, test_data.N2_list_copy,
test_data.num_particle, positions,
test_data.test_radius );
checkLinkedCellReduce( nlist, test_data.N2_list_copy, test_data.aosoa,
test_data.num_particle, test_data.test_radius );
checkLinkedCellNeighborReduce( nlist, test_data.N2_list_copy,
test_data.aosoa, test_data.num_particle,
test_data.test_radius );

Cabana::permute( nlist, positions );
checkLinkedCellParallel( nlist, test_data.N2_list_copy,
test_data.num_particle, positions,
test_data.test_radius );

checkLinkedCellNeighborParallel( nlist, test_data.N2_list_copy,
test_data.num_particle, positions,
test_data.test_radius );
checkLinkedCellReduce( nlist, test_data.N2_list_copy, test_data.aosoa,
test_data.num_particle, test_data.test_radius );
checkLinkedCellNeighborReduce( nlist, test_data.N2_list_copy,
test_data.aosoa, test_data.num_particle,
test_data.test_radius );
Expand Down

0 comments on commit d4ff4f2

Please sign in to comment.