Skip to content

Commit

Permalink
Make parallel_deepcopy safer (#711)
Browse files Browse the repository at this point in the history
* Make parallel_deepcopy safer

* Rework examples to pass assertions in parallel_deepcopy
  • Loading branch information
tpadioleau authored Dec 24, 2024
1 parent 507bafe commit ea03c48
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 70 deletions.
32 changes: 20 additions & 12 deletions examples/heat_equation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,18 +286,26 @@ int main(int argc, char** argv)

//! [boundary conditions]
// Periodic boundary conditions
ddc::parallel_deepcopy(
ghosted_last_temp[x_pre_ghost][y_domain],
ghosted_last_temp[y_domain][x_domain_end]);
ddc::parallel_deepcopy(
ghosted_last_temp[y_domain][x_post_ghost],
ghosted_last_temp[y_domain][x_domain_begin]);
ddc::parallel_deepcopy(
ghosted_last_temp[x_domain][y_pre_ghost],
ghosted_last_temp[x_domain][y_domain_end]);
ddc::parallel_deepcopy(
ghosted_last_temp[x_domain][y_post_ghost],
ghosted_last_temp[x_domain][y_domain_begin]);
for (ddc::DiscreteElement<DDimX> const ix : x_pre_ghost) {
ddc::parallel_deepcopy(
ghosted_last_temp[ix][y_domain],
ghosted_last_temp[ix + nb_x_points][y_domain]);
}
for (ddc::DiscreteElement<DDimX> const ix : x_post_ghost) {
ddc::parallel_deepcopy(
ghosted_last_temp[ix][y_domain],
ghosted_last_temp[ix - nb_x_points][y_domain]);
}
for (ddc::DiscreteElement<DDimY> const iy : y_pre_ghost) {
ddc::parallel_deepcopy(
ghosted_last_temp[x_domain][iy],
ghosted_last_temp[x_domain][iy + nb_y_points]);
}
for (ddc::DiscreteElement<DDimY> const iy : y_post_ghost) {
ddc::parallel_deepcopy(
ghosted_last_temp[x_domain][iy],
ghosted_last_temp[x_domain][iy - nb_y_points]);
}
//! [boundary conditions]

//! [manipulated views]
Expand Down
48 changes: 20 additions & 28 deletions examples/non_uniform_heat_equation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,34 +311,26 @@ int main(int argc, char** argv)
//! [time iteration]

//! [boundary conditions]
ddc::parallel_deepcopy(
ghosted_last_temp[ddc::DiscreteDomain<
DDimX,
DDimY>(x_pre_ghost, y_domain)],
ghosted_last_temp[ddc::DiscreteDomain<
DDimX,
DDimY>(y_domain, x_domain_end)]);
ddc::parallel_deepcopy(
ghosted_last_temp[ddc::DiscreteDomain<
DDimX,
DDimY>(y_domain, x_post_ghost)],
ghosted_last_temp[ddc::DiscreteDomain<
DDimX,
DDimY>(y_domain, x_domain_begin)]);
ddc::parallel_deepcopy(
ghosted_last_temp[ddc::DiscreteDomain<
DDimX,
DDimY>(x_domain, y_pre_ghost)],
ghosted_last_temp[ddc::DiscreteDomain<
DDimX,
DDimY>(x_domain, y_domain_end)]);
ddc::parallel_deepcopy(
ghosted_last_temp[ddc::DiscreteDomain<
DDimX,
DDimY>(x_domain, y_post_ghost)],
ghosted_last_temp[ddc::DiscreteDomain<
DDimX,
DDimY>(x_domain, y_domain_begin)]);
for (ddc::DiscreteElement<DDimX> const ix : x_pre_ghost) {
ddc::parallel_deepcopy(
ghosted_last_temp[ix][y_domain],
ghosted_last_temp[ix + nb_x_points][y_domain]);
}
for (ddc::DiscreteElement<DDimX> const ix : x_post_ghost) {
ddc::parallel_deepcopy(
ghosted_last_temp[ix][y_domain],
ghosted_last_temp[ix - nb_x_points][y_domain]);
}
for (ddc::DiscreteElement<DDimY> const iy : y_pre_ghost) {
ddc::parallel_deepcopy(
ghosted_last_temp[x_domain][iy],
ghosted_last_temp[x_domain][iy + nb_y_points]);
}
for (ddc::DiscreteElement<DDimY> const iy : y_post_ghost) {
ddc::parallel_deepcopy(
ghosted_last_temp[x_domain][iy],
ghosted_last_temp[x_domain][iy - nb_y_points]);
}
//! [boundary conditions]

//! [manipulated views]
Expand Down
48 changes: 20 additions & 28 deletions examples/uniform_heat_equation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,34 +231,26 @@ int main(int argc, char** argv)
//! [time iteration]

//! [boundary conditions]
ddc::parallel_deepcopy(
ghosted_last_temp[ddc::DiscreteDomain<
DDimX,
DDimY>(x_pre_ghost, y_domain)],
ghosted_last_temp[ddc::DiscreteDomain<
DDimX,
DDimY>(y_domain, x_domain_end)]);
ddc::parallel_deepcopy(
ghosted_last_temp[ddc::DiscreteDomain<
DDimX,
DDimY>(y_domain, x_post_ghost)],
ghosted_last_temp[ddc::DiscreteDomain<
DDimX,
DDimY>(y_domain, x_domain_begin)]);
ddc::parallel_deepcopy(
ghosted_last_temp[ddc::DiscreteDomain<
DDimX,
DDimY>(x_domain, y_pre_ghost)],
ghosted_last_temp[ddc::DiscreteDomain<
DDimX,
DDimY>(x_domain, y_domain_end)]);
ddc::parallel_deepcopy(
ghosted_last_temp[ddc::DiscreteDomain<
DDimX,
DDimY>(x_domain, y_post_ghost)],
ghosted_last_temp[ddc::DiscreteDomain<
DDimX,
DDimY>(x_domain, y_domain_begin)]);
for (ddc::DiscreteElement<DDimX> const ix : x_pre_ghost) {
ddc::parallel_deepcopy(
ghosted_last_temp[ix][y_domain],
ghosted_last_temp[ix + nb_x_points][y_domain]);
}
for (ddc::DiscreteElement<DDimX> const ix : x_post_ghost) {
ddc::parallel_deepcopy(
ghosted_last_temp[ix][y_domain],
ghosted_last_temp[ix - nb_x_points][y_domain]);
}
for (ddc::DiscreteElement<DDimY> const iy : y_pre_ghost) {
ddc::parallel_deepcopy(
ghosted_last_temp[x_domain][iy],
ghosted_last_temp[x_domain][iy + nb_y_points]);
}
for (ddc::DiscreteElement<DDimY> const iy : y_post_ghost) {
ddc::parallel_deepcopy(
ghosted_last_temp[x_domain][iy],
ghosted_last_temp[x_domain][iy - nb_y_points]);
}
//! [boundary conditions]

//! [manipulated views]
Expand Down
8 changes: 6 additions & 2 deletions include/ddc/parallel_deepcopy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ auto parallel_deepcopy(ChunkDst&& dst, ChunkSrc&& src)
static_assert(
std::is_assignable_v<chunk_reference_t<ChunkDst>, chunk_reference_t<ChunkSrc>>,
"Not assignable");
assert(dst.domain().extents() == src.domain().extents());
static_assert(std::is_same_v<decltype(dst.domain()), decltype(src.domain())>);
assert(dst.domain() == src.domain());
Kokkos::deep_copy(dst.allocation_kokkos_view(), src.allocation_kokkos_view());
return dst.span_view();
}
Expand All @@ -45,7 +46,10 @@ auto parallel_deepcopy(ExecSpace const& execution_space, ChunkDst&& dst, ChunkSr
static_assert(
std::is_assignable_v<chunk_reference_t<ChunkDst>, chunk_reference_t<ChunkSrc>>,
"Not assignable");
assert(dst.domain().extents() == src.domain().extents());
static_assert(
std::is_same_v<decltype(dst.domain()), decltype(src.domain())>,
"ddc::parallel_deepcopy only supports domains whose dimensions are of the same order");
assert(dst.domain() == src.domain());
Kokkos::deep_copy(execution_space, dst.allocation_kokkos_view(), src.allocation_kokkos_view());
return dst.span_view();
}
Expand Down

0 comments on commit ea03c48

Please sign in to comment.