@@ -31,41 +31,39 @@ namespace Cabana
3131 keep.
3232 \param num_particles_ignore The number of particles to ignore (which precede
3333 those which may be kept/removed).
34- \param keep_particle Boolean Kokkos View of particles to keep (true) or remove
35- (false).
36- \param particles The AoSoA containing particles.
37- \param shrink_to_fit Whether to remove additional AoSoA capacity or not.
34+ \param remove_particle Boolean Kokkos View of particles to remove (true) or
35+ keep (false). \param particles The AoSoA containing particles. \param
36+ shrink_to_fit Whether to remove additional AoSoA capacity or not.
3837*/
3938template <class ExecutionSpace , class KeepView , class ParticleAoSoA >
4039void remove ( const ExecutionSpace& exec_space, const int num_keep,
41- const KeepView& keep_particle , ParticleAoSoA& particles,
40+ const KeepView& remove_particle , ParticleAoSoA& particles,
4241 const int num_particles_ignore = 0 ,
4342 const bool shrink_to_fit = true )
4443{
4544 using memory_space = typename KeepView::memory_space;
4645
47- // Determine the empty particle positions in the compaction zone.
4846 int num_particles = particles.size ();
49- // This View is either empty indices to be filled or the created particle
50- // indices, depending on the ratio of allocated space to the number
51- // created .
47+ int new_num_particles = num_particles_ignore + num_keep;
48+
49+ // Determine the keep particle positions in the compaction zone .
5250 Kokkos::View<int *, memory_space> indices (
5351 Kokkos::ViewAllocateWithoutInitializing ( " empty_or_filled" ),
54- std::min ( num_particles - num_particles_ignore - num_keep, num_keep ) );
52+ num_keep );
5553
56- int new_num_particles = num_particles_ignore + num_keep;
5754 // parallel_scan will break if not keeping any particles.
5855 if ( num_keep > 0 )
5956 {
6057 Kokkos::parallel_scan (
6158 " Cabana::remove::FindEmpty" ,
62- Kokkos::RangePolicy<ExecutionSpace>( exec_space, 0 , num_keep ),
59+ Kokkos::RangePolicy<ExecutionSpace>(
60+ exec_space, num_particles_ignore, num_particles ),
6361 KOKKOS_LAMBDA ( const int i, int & count, const bool final_pass ) {
64- if ( !keep_particle ( i ) )
62+ if ( !remove_particle ( i ) )
6563 {
6664 if ( final_pass )
6765 {
68- indices ( count ) = i + num_particles_ignore ;
66+ indices ( count ) = i;
6967 }
7068 ++count;
7169 }
@@ -75,10 +73,10 @@ void remove( const ExecutionSpace& exec_space, const int num_keep,
7573 // Compact the list so the it only has real particles.
7674 Kokkos::parallel_scan (
7775 " Cabana::remove::RemoveEmpty" ,
78- Kokkos::RangePolicy<ExecutionSpace>( exec_space, new_num_particles,
79- num_particles ),
76+ Kokkos::RangePolicy<ExecutionSpace>(
77+ exec_space, num_particles_ignore, num_particles ),
8078 KOKKOS_LAMBDA ( const int i, int & count, const bool final_pass ) {
81- if ( keep_particle ( i - num_particles_ignore ) )
79+ if ( ! remove_particle ( i ) )
8280 {
8381 if ( final_pass )
8482 {
0 commit comments