Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,12 @@ endif()

if(ENABLE_INTEGRATED_TESTS)
enable_testing()

# NOTE: This can also be done by a subdirectory (useful when we have multiple tests)
# Add includes for Catch2
set(TEST_DIR "./test/include")
include_directories(${TEST_DIR})

add_subdirectory(test/integrated)

endif(ENABLE_INTEGRATED_TESTS)
Expand Down
22 changes: 10 additions & 12 deletions src/particle_operations/sort.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ struct min_max_functor {
min_max_functor(const Kokkos::View<int*>& view_) : view(view_) {}
KOKKOS_INLINE_FUNCTION
void operator()(const size_t& i, minmax_scalar& minmax) const {
if(view(i) < minmax.min_val && view(i) != 0) minmax.min_val = view(i);
if(view(i) > minmax.max_val && view(i) != 0) minmax.max_val = view(i);
if(view(i) < minmax.min_val) minmax.min_val = view(i);
if(view(i) > minmax.max_val) minmax.max_val = view(i);
}
};

Expand All @@ -23,8 +23,8 @@ struct min_max_functor_u64 {
min_max_functor_u64(const Kokkos::View<uint64_t*>& view_) : view(view_) {}
KOKKOS_INLINE_FUNCTION
void operator()(const size_t& i, minmax_scalar& minmax) const {
if(view(i) < minmax.min_val && view(i) != 0) minmax.min_val = view(i);
if(view(i) > minmax.max_val && view(i) != 0) minmax.max_val = view(i);
if(view(i) < minmax.min_val) minmax.min_val = view(i);
if(view(i) > minmax.max_val) minmax.max_val = view(i);
}
};

Expand Down Expand Up @@ -201,21 +201,19 @@ struct DefaultSort {
Kokkos::deep_copy(bin_counter, 0);
// Count number of particles in each cell
Kokkos::parallel_for("get max nppc", Kokkos::RangePolicy<>(0, np), KOKKOS_LAMBDA(const int i) {
Kokkos::atomic_increment(&(bin_counter(key_view(i))));
Kokkos::atomic_inc(&(bin_counter(key_view(i))));
});
// Find the max and min number of particles per cell
Kokkos::parallel_reduce("Get max/min nppc", Kokkos::RangePolicy<>(0,num_bins),
min_max_functor(bin_counter), nppc_reducer);
const int chunk_size = tile_size*(nppc_result.max_val+1);
// Reset bin_counter
Kokkos::deep_copy(bin_counter, 0);
// Update particle indices
Kokkos::parallel_for("Update keys", Kokkos::RangePolicy<>(0, np), KOKKOS_LAMBDA(const int i) {
int count = Kokkos::atomic_fetch_add(&(bin_counter(key_view(i))), 1);
int chunk_size = tile_size*nppc_result.max_val;
int chunk = (key_view(i)-result.min_val)/tile_size;
int min_idx = result.min_val + chunk*tile_size;
int offset = count*nppc_result.max_val;
key_view(i) += chunk*chunk_size + offset - min_idx + 1;
const int count = Kokkos::atomic_fetch_add(&(bin_counter(key_view(i))), 1);
const int chunk_idx = (key_view(i)-(result.min_val))/tile_size;
key_view(i) += chunk_idx*chunk_size + count*tile_size - result.min_val;
});
// Find smallest and largest index
Kokkos::parallel_reduce("Get min/max bin", Kokkos::RangePolicy<>(0,particles_i.extent(0)),
Expand All @@ -228,7 +226,7 @@ struct DefaultSort {
Comparator comp(np, result.min_val, result.max_val);

// Sort and create permutation View
int sort_within_bins = 0;
int sort_within_bins = 1;
Kokkos::BinSort<key_type, Comparator> bin_sort(keys, 0, np, comp, sort_within_bins );
bin_sort.create_permute_vector();

Expand Down
61 changes: 48 additions & 13 deletions src/species_advance/species_advance.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@ class species_t {
k_particle_movers_t::HostMirror k_pm_h; // kokkos particle movers on host
k_particle_i_movers_t::HostMirror k_pm_i_h; // kokkos particle movers on host

k_counter_t num_temp_movers_d;
k_counter_t::HostMirror num_temp_movers_h;
k_particle_movers_t temp_movers;
k_particle_i_movers_t temp_movers_i;

// TODO: what is an iterator here??
k_counter_t k_nm_d; // nm iterator
k_counter_t::HostMirror k_nm_h;
Expand Down Expand Up @@ -227,6 +232,11 @@ class species_t {
k_nm_h = Kokkos::create_mirror_view(k_nm_d);

clean_up_from_count_h = Kokkos::create_mirror_view(clean_up_from_count);

num_temp_movers_d = k_counter_t("Num temp movers");
num_temp_movers_h = Kokkos::create_mirror_view(num_temp_movers_d);
temp_movers = k_particle_movers_t("Temp movers", n_particles);
temp_movers_i = k_particle_i_movers_t("Temp mover indices", n_particles);
}

/**
Expand Down Expand Up @@ -442,14 +452,23 @@ move_p_kokkos(
auto scatter_access = scatter_view.access();

q = qsp*p_w;
int ii = pii;
float r[3];
r[0] = p_dx;
r[1] = p_dy;
r[2] = p_dz;

//printf("in move %d \n", pi);

for(;;) {
int ii = pii;
s_midx = p_dx;
s_midy = p_dy;
s_midz = p_dz;
// int ii = pii;
// s_midx = p_dx;
// s_midy = p_dy;
// s_midz = p_dz;

s_midx = r[0];
s_midy = r[1];
s_midz = r[2];


s_dispx = pm->dispx;
Expand Down Expand Up @@ -570,14 +589,23 @@ move_p_kokkos(

//printf("pre axis %d x %e y %e z %e disp x %e y %e z %e\n", axis, p_dx, p_dy, p_dz, s_dispx, s_dispy, s_dispz);
// Compute the new particle offset
p_dx += s_dispx+s_dispx;
p_dy += s_dispy+s_dispy;
p_dz += s_dispz+s_dispz;
// p_dx += s_dispx+s_dispx;
// p_dy += s_dispy+s_dispy;
// p_dz += s_dispz+s_dispz;
r[0] += s_dispx+s_dispx;
r[1] += s_dispy+s_dispy;
r[2] += s_dispz+s_dispz;

// If an end streak, return success (should be ~50% of the time)
//printf("axis %d x %e y %e z %e disp x %e y %e z %e\n", axis, p_dx, p_dy, p_dz, s_dispx, s_dispy, s_dispz);

if( axis==3 ) break;
if( axis==3 ) {
pii = ii;
p_dx = r[0];
p_dy = r[1];
p_dz = r[2];
break;
}

// Determine if the particle crossed into a local cell or if it
// hit a boundary and convert the coordinate system accordingly.
Expand All @@ -587,7 +615,8 @@ move_p_kokkos(
// +/-1 _exactly_ for the particle.

v0 = s_dir[axis];
k_particles(pi, particle_var::dx + axis) = v0; // Avoid roundoff fiascos--put the particle
//k_particles(pi, particle_var::dx + axis) = v0; // Avoid roundoff fiascos--put the particle
r[axis] = v0; // Avoid roundoff fiascos--put the particle
// _exactly_ on the boundary.
face = axis; if( v0>0 ) face += 3;

Expand Down Expand Up @@ -617,16 +646,22 @@ move_p_kokkos(
// Cannot handle the boundary condition here. Save the updated
// particle position, face it hit and update the remaining
// displacement in the particle mover.
pii = 8*pii + face;
//pii = 8*pii + face;
pii = 8*ii + face;
p_dx = r[0];
p_dy = r[1];
p_dz = r[2];
return 1; // Return "mover still in use"
}
}

// Crossed into a normal voxel. Update the voxel index, convert the
// particle coordinate system and keep moving the particle.

pii = neighbor - rangel;
//pii = neighbor - rangel;
ii = neighbor - rangel;
/**/ // Note: neighbor - rangel < 2^31 / 6
k_particles(pi, particle_var::dx + axis) = -v0; // Convert coordinate system
//k_particles(pi, particle_var::dx + axis) = -v0; // Convert coordinate system
r[axis] = -v0; // Convert coordinate system
}
#undef p_dx
#undef p_dy
Expand Down
Loading
Loading