Skip to content

Commit

Permalink
SYCL changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel Reeve committed Aug 14, 2023
1 parent 9d7212f commit c41115f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
36 changes: 20 additions & 16 deletions cajita/src/Cajita_ParticleInit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ void filterEmpties( const ExecutionSpace& exec_space,
++count;
}
} );
Kokkos::fence();

// Compact the list so the it only has real particles.
Kokkos::parallel_scan(
Expand All @@ -92,6 +93,8 @@ void filterEmpties( const ExecutionSpace& exec_space,
++count;
}
} );
Kokkos::fence();

aosoa.resize( local_num_create );
if ( shrink_to_fit )
aosoa.shrinkToFit();
Expand Down Expand Up @@ -155,16 +158,14 @@ int createParticles(
aosoa.resize( num_particles );

// Creation status.
auto particle_created = Kokkos::View<bool*, memory_space>(
Kokkos::ViewAllocateWithoutInitializing( "particle_created" ),
num_particles );
auto count = Kokkos::View<int*, memory_space>( "particle_count", 1 );

// Initialize particles.
int local_num_create = 0;
Cajita::grid_parallel_reduce(
Cajita::grid_parallel_for(
"Cajita::ParticleInit::Random", exec_space, owned_cells,
KOKKOS_LAMBDA( const int i, const int j, const int k,
int& create_count ) {
KOKKOS_LAMBDA( const int i, const int j, const int k
) {
// Compute the owned local cell id.
int i_own = i - owned_cells.min( Dim::I );
int j_own = j - owned_cells.min( Dim::J );
Expand Down Expand Up @@ -209,23 +210,25 @@ int createParticles(

// Create a new particle with the given logical coordinates.
auto particle = particle_list.getParticle( pid );
particle_created( pid ) =
bool created =
create_functor( pid, px, pv, particle );

// If we created a new particle insert it into the list.
if ( particle_created( pid ) )
if ( created )
{
particle_list.setParticle( particle, pid );
++create_count;
auto c = Kokkos::atomic_fetch_add( &count( 0 ), 1 );
particle_list.setParticle( particle, c );
}
}
},
local_num_create );
} );
Kokkos::fence();

// Filter empties.
filterEmpties( exec_space, local_num_create, particle_created, aosoa,
shrink_to_fit );
return local_num_create;
auto count_host =
Kokkos::create_mirror_view_and_copy( Kokkos::HostSpace(), count );
aosoa.resize( count_host( 0 ) );
if ( shrink_to_fit )
aosoa.shrinkToFit();
return count_host( 0 );
}

/*!
Expand Down Expand Up @@ -494,6 +497,7 @@ int createParticles(
}
},
local_num_create );
Kokkos::fence();

// Filter empties.
filterEmpties( exec_space, local_num_create, particle_created, aosoa,
Expand Down
5 changes: 2 additions & 3 deletions cajita/unit_test/tstParticleInit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,10 @@ void initParticleListTest( InitType init_type, int ppc )
};

// Initialize particles.
Cajita::createParticles( init_type, TEST_EXECSPACE(), init_func, particles,
int num_p = Cajita::createParticles( init_type, TEST_EXECSPACE(), init_func, particles,
ppc, *local_grid );

// Check that we made particles.
int num_p = particles.size();
EXPECT_TRUE( num_p > 0 );

// Compute the global number of particles.
Expand Down Expand Up @@ -144,7 +143,7 @@ void initParticleListTest( InitType init_type, int ppc )
EXPECT_TRUE( px < box[2 * d + 1] );
}
auto pv = get( particle, Bar() );
EXPECT_EQ( pv, volume );
EXPECT_DOUBLE_EQ( pv, volume );
}
}

Expand Down

0 comments on commit c41115f

Please sign in to comment.