diff --git a/core/src/Cabana_Parallel.hpp b/core/src/Cabana_Parallel.hpp index b33659315..d9dbe6159 100644 --- a/core/src/Cabana_Parallel.hpp +++ b/core/src/Cabana_Parallel.hpp @@ -1195,7 +1195,7 @@ struct LinkedCellParallelFor if ( !_list.sorted() ) jj = _list.permutation( j ); else - jj = j; + jj = j + _begin; // Avoid self interactions (dummy position args). if ( _discriminator.isValid( i, 0, 0, 0, jj, 0, 0, 0 ) ) { @@ -1233,7 +1233,7 @@ struct LinkedCellParallelFor if ( !_list.sorted() ) jj = _list.permutation( j ); else - jj = j; + jj = j + _begin; // Avoid self interactions (dummy position args). if ( _discriminator.isValid( i, 0, 0, 0, jj, 0, 0, 0 ) ) @@ -1313,7 +1313,7 @@ struct LinkedCellParallelReduce if ( !_list.sorted() ) jj = _list.permutation( j ); else - jj = j; + jj = j + _begin; // Avoid self interactions (dummy position args). if ( _discriminator.isValid( i, 0, 0, 0, jj, 0, 0, 0 ) ) { @@ -1352,7 +1352,7 @@ struct LinkedCellParallelReduce if ( !_list.sorted() ) jj = _list.permutation( j ); else - jj = j; + jj = j + _begin; // Avoid self interactions (dummy position args). if ( _discriminator.isValid( i, 0, 0, 0, jj, 0, 0, 0 ) ) @@ -1435,7 +1435,7 @@ inline void neighbor_parallel_for( Impl::LinkedCellParallelFor - lcl_par( str, linear_exec_policy, functor, list ); + lcl_par( str, linear_exec_policy, functor, list, exec_policy.begin() ); } //---------------------------------------------------------------------------// @@ -1562,7 +1562,8 @@ inline void neighbor_parallel_reduce( Impl::LinkedCellParallelReduce< work_tag, FunctorType, linear_policy_type, LinkedCellType, typename LinkedCellType::CountView, ReduceType> - lcl_par( str, linear_exec_policy, functor, list, reduce_val ); + lcl_par( str, linear_exec_policy, functor, list, reduce_val, + exec_policy.begin() ); } //---------------------------------------------------------------------------// diff --git a/core/unit_test/neighbor_unit_test.hpp b/core/unit_test/neighbor_unit_test.hpp index 68ce08cd1..e6e2eefbb 100644 --- a/core/unit_test/neighbor_unit_test.hpp +++ b/core/unit_test/neighbor_unit_test.hpp @@ -298,9 +298,13 @@ void checkFirstNeighborParallelFor( const TestListType& N2_list_copy, num_particle ); // Use a full N^2 neighbor list to check against. - for ( std::size_t p = 0; p < num_particle; ++p ) + for ( std::size_t p = begin; p < end; ++p ) for ( int n = 0; n < N2_list_copy.counts( p ); ++n ) - N2_result( p ) += N2_list_copy.neighbors( p, n ); + { + if ( N2_list_copy.neighbors( p, n ) >= begin && + N2_list_copy.neighbors( p, n ) < end ) + N2_result( p ) += N2_list_copy.neighbors( p, n ); + } // Check the result. auto serial_mirror = Kokkos::create_mirror_view_and_copy( @@ -369,8 +373,11 @@ void checkFirstNeighborParallelReduce( for ( int n = 0; n < N2_list_copy.counts( p ); ++n ) if ( p >= begin && p < end ) { - N2_sum += positions_mirror( p, 0 ) + - positions_mirror( N2_list_copy.neighbors( p, n ), 0 ); + if ( N2_list_copy.neighbors( p, n ) >= begin && + N2_list_copy.neighbors( p, n ) < end ) + N2_sum += + positions_mirror( p, 0 ) + + positions_mirror( N2_list_copy.neighbors( p, n ), 0 ); } // Check the result. diff --git a/core/unit_test/tstLinkedCellList.hpp b/core/unit_test/tstLinkedCellList.hpp index 3b052b68c..0fa356b05 100644 --- a/core/unit_test/tstLinkedCellList.hpp +++ b/core/unit_test/tstLinkedCellList.hpp @@ -420,12 +420,32 @@ void checkLinkedCellNeighborInterface( const ListType& nlist, // Purposely using zero-init. Kokkos::View num_n2_neighbors( "num_n2_neighbors", positions.size() ); + Kokkos::View N2_copy_neighbors( "num_n2_neighbors", + positions.size() ); Cabana::NeighborDiscriminator _discriminator; std::size_t max_n2_neighbors = 0; std::size_t sum_n2_neighbors = 0; + std::size_t N2_copy_max = 0; + std::size_t N2_copy_sum = 0; + + for ( int p = begin; p < end; ++p ) + { + for ( int n = 0; n < N2_list_copy.counts( p ); ++n ) + { + if ( N2_list_copy.neighbors( p, n ) >= begin && + N2_list_copy.neighbors( p, n ) < end ) + { + N2_copy_neighbors( p ) += 1; + } + } + if ( N2_copy_neighbors( p ) > N2_copy_max ) + N2_copy_max = N2_copy_neighbors( p ); + N2_copy_sum += N2_copy_neighbors( p ); + } + double c2 = cutoff * cutoff; Kokkos::RangePolicy policy( begin, end ); @@ -440,16 +460,22 @@ void checkLinkedCellNeighborInterface( const ListType& nlist, int np = Cabana::NeighborList::getNeighbor( nlist, pid, i ); + if ( nlist.sorted() ) + np += begin; + const double dx = positions( pid, 0 ) - positions( np, 0 ); const double dy = positions( pid, 1 ) - positions( np, 1 ); const double dz = positions( pid, 2 ) - positions( np, 2 ); const double r2 = dx * dx + dy * dy + dz * dz; + if ( r2 <= c2 && _discriminator.isValid( pid, 0, 0, 0, np, 0, 0, 0 ) ) { if ( nlist.sorted() ) Kokkos::atomic_add( - &num_n2_neighbors( nlist.permutation( pid ) ), 1 ); + &num_n2_neighbors( + nlist.permutation( pid - begin ) ), + 1 ); else Kokkos::atomic_add( &num_n2_neighbors( pid ), 1 ); } @@ -462,18 +488,21 @@ void checkLinkedCellNeighborInterface( const ListType& nlist, for ( std::size_t pid = 0; pid < positions.size(); ++pid ) { if ( pid >= begin && pid < end ) - EXPECT_EQ( num_n2_neighbors_host( pid ), - N2_list_copy.counts( pid ) ); + { + EXPECT_EQ( num_n2_neighbors_host( pid ), N2_copy_neighbors( pid ) ); + } else + { EXPECT_EQ( num_n2_neighbors_host( pid ), 0 ); + } sum_n2_neighbors += num_n2_neighbors_host( pid ); if ( num_n2_neighbors_host( pid ) > max_n2_neighbors ) max_n2_neighbors = num_n2_neighbors_host( pid ); } - EXPECT_EQ( max_n2_neighbors, N2_list_copy.max ); - EXPECT_EQ( sum_n2_neighbors, N2_list_copy.total ); + EXPECT_EQ( max_n2_neighbors, N2_copy_max ); + EXPECT_EQ( sum_n2_neighbors, N2_copy_sum ); } //---------------------------------------------------------------------------// @@ -509,8 +538,9 @@ void checkLinkedCellNeighborParallel( const ListType& nlist, { if ( nlist.sorted() ) { - Kokkos::atomic_add( &serial_result( nlist.permutation( i ) ), - nlist.permutation( j ) ); + Kokkos::atomic_add( + &serial_result( nlist.permutation( i - begin ) ), + nlist.permutation( j - begin ) ); } else { @@ -528,8 +558,9 @@ void checkLinkedCellNeighborParallel( const ListType& nlist, { if ( nlist.sorted() ) { - Kokkos::atomic_add( &team_result( nlist.permutation( i ) ), - nlist.permutation( j ) ); + Kokkos::atomic_add( + &team_result( nlist.permutation( i - begin ) ), + nlist.permutation( j - begin ) ); } else { @@ -577,8 +608,8 @@ void checkLinkedCellNeighborReduce( const ListType& nlist, { if ( nlist.sorted() ) { - sum += position( nlist.permutation( i ), 0 ) + - position( nlist.permutation( j ), 0 ); + sum += position( nlist.permutation( i - begin ), 0 ) + + position( nlist.permutation( j - begin ), 0 ); } else {