Skip to content

Commit

Permalink
add noexcept clause to ParallelFor (#2554)
Browse files Browse the repository at this point in the history
also switch the lambdas to use AMREX_GPU_DEVICE
  • Loading branch information
zingale authored Sep 17, 2023
1 parent 5a3ce84 commit dbf68f5
Show file tree
Hide file tree
Showing 43 changed files with 233 additions and 233 deletions.
4 changes: 2 additions & 2 deletions Source/diffusion/diffusion_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fill_temp_cond(const Box& bx,
Array4<Real> const& coeff_arr) {

amrex::ParallelFor(bx,
[=] AMREX_GPU_DEVICE (int i, int j, int k)
[=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
{

eos_t eos_state;
Expand Down Expand Up @@ -64,7 +64,7 @@ fill_temp_diff_coeff(const Box& bx,
Array4<Real> const& coeff_arr) {

amrex::ParallelFor(bx,
[=] AMREX_GPU_DEVICE (int i, int j, int k)
[=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
{

eos_t eos_state;
Expand Down
92 changes: 46 additions & 46 deletions Source/driver/Castro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1061,7 +1061,7 @@ Castro::initData ()
const Box& box_x = mfi.nodaltilebox(0);

amrex::ParallelFor(box_x,
[=] AMREX_GPU_HOST_DEVICE (int i, int j, int k)
[=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
{
// C++ MHD problem initialization; has no effect if not
// implemented by a problem setup (defaults to an empty
Expand All @@ -1072,7 +1072,7 @@ Castro::initData ()
const Box& box_y = mfi.nodaltilebox(1);

amrex::ParallelFor(box_y,
[=] AMREX_GPU_HOST_DEVICE (int i, int j, int k)
[=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
{
// C++ MHD problem initialization; has no effect if not
// implemented by a problem setup (defaults to an empty
Expand All @@ -1083,7 +1083,7 @@ Castro::initData ()
const Box& box_z = mfi.nodaltilebox(2);

amrex::ParallelFor(box_z,
[=] AMREX_GPU_HOST_DEVICE (int i, int j, int k)
[=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
{
// C++ MHD problem initialization; has no effect if not
// implemented by a problem setup (defaults to an empty
Expand All @@ -1106,7 +1106,7 @@ Castro::initData ()
auto geomdata = geom.data();

amrex::ParallelFor(box,
[=] AMREX_GPU_HOST_DEVICE (int i, int j, int k)
[=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
{
// problem initialization
problem_initialize_state_data(i, j, k, s, geomdata);
Expand Down Expand Up @@ -1149,7 +1149,7 @@ Castro::initData ()
Real lsmall_dens = small_dens;

reduce_op.eval(bx, reduce_data,
[=] AMREX_GPU_HOST_DEVICE (int i, int j, int k) -> ReduceTuple
[=] AMREX_GPU_DEVICE (int i, int j, int k) -> ReduceTuple
{
// if the problem tried to initialize a thermodynamic
// state that is at or below small_temp, then we abort.
Expand Down Expand Up @@ -1199,7 +1199,7 @@ Castro::initData ()
auto S_arr = S_new.array(mfi);

amrex::ParallelFor(bx,
[=] AMREX_GPU_HOST_DEVICE (int i, int j, int k)
[=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
{
Real spec_sum = 0.0_rt;
for (int n = 0; n < NumSpec; n++) {
Expand Down Expand Up @@ -1287,7 +1287,7 @@ Castro::initData ()
auto S_arr = Sborder.array(mfi);

amrex::ParallelFor(box,
[=] AMREX_GPU_HOST_DEVICE (int i, int j, int k)
[=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
{

Real rhoInv = 1.0_rt / S_arr(i,j,k,URHO);
Expand Down Expand Up @@ -1384,7 +1384,7 @@ Castro::initData ()
#endif

amrex::ParallelFor(box,
[=] AMREX_GPU_HOST_DEVICE (int i, int j, int k)
[=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
{
// C++ problem initialization; has no effect if not implemented
// by a problem setup (defaults to an empty routine).
Expand Down Expand Up @@ -2764,32 +2764,32 @@ Castro::reflux (int crse_level, int fine_level, bool in_post_timestep)
crse_lev.limit_hydro_fluxes_on_small_dens(nbx, idir, U, V, F, A, dt, scale_by_dAdt);
#endif
amrex::ParallelFor(nbx,
[=] AMREX_GPU_DEVICE (int i, int j, int k)
{
bool zero_fluxes = false;

Real rho = U(i,j,k,URHO);
Real drhoV = F(i,j,k,URHO) / V(i,j,k);
Real rhoInvNew = 1.0_rt / (rho + drhoV);

for (int n = 0; n < NumSpec; ++n) {
Real rhoX = U(i,j,k,UFS+n);
Real drhoX = F(i,j,k,UFS+n) / V(i,j,k);
Real XNew = (rhoX + AMREX_SPACEDIM * drhoX) * rhoInvNew;

if (XNew < -castro::abundance_failure_tolerance ||
XNew > 1.0_rt + castro::abundance_failure_tolerance) {
zero_fluxes = true;
break;
}
}

if (zero_fluxes) {
for (int n = 0; n < NUM_STATE; ++n) {
F(i,j,k,n) = 0.0;
}
}
});
[=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
{
bool zero_fluxes = false;

Real rho = U(i,j,k,URHO);
Real drhoV = F(i,j,k,URHO) / V(i,j,k);
Real rhoInvNew = 1.0_rt / (rho + drhoV);

for (int n = 0; n < NumSpec; ++n) {
Real rhoX = U(i,j,k,UFS+n);
Real drhoX = F(i,j,k,UFS+n) / V(i,j,k);
Real XNew = (rhoX + AMREX_SPACEDIM * drhoX) * rhoInvNew;

if (XNew < -castro::abundance_failure_tolerance ||
XNew > 1.0_rt + castro::abundance_failure_tolerance) {
zero_fluxes = true;
break;
}
}

if (zero_fluxes) {
for (int n = 0; n < NUM_STATE; ++n) {
F(i,j,k,n) = 0.0;
}
}
});
}
}

Expand Down Expand Up @@ -3116,7 +3116,7 @@ Castro::normalize_species (MultiFab& S_new, int ng)
// then normalize them so that they sum to 1.

reduce_op.eval(bx, reduce_data,
[=] AMREX_GPU_HOST_DEVICE (int i, int j, int k) -> ReduceTuple
[=] AMREX_GPU_DEVICE (int i, int j, int k) -> ReduceTuple
{
Real rhoX_sum = 0.0_rt;
Real rhoInv = 1.0_rt / u(i,j,k,URHO);
Expand Down Expand Up @@ -3193,7 +3193,7 @@ Castro::enforce_consistent_e (
#endif

ParallelFor(box,
[=] AMREX_GPU_HOST_DEVICE (int i, int j, int k)
[=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
{
Real rhoInv = 1.0_rt / S_arr(i,j,k,URHO);
Real u = S_arr(i,j,k,UMX) * rhoInv;
Expand Down Expand Up @@ -3369,7 +3369,7 @@ Castro::enforce_speed_limit (MultiFab& state_in, int ng)
auto u = state_in[mfi].array();

amrex::ParallelFor(bx,
[=] AMREX_GPU_HOST_DEVICE (int i, int j, int k)
[=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
{
Real rho = u(i,j,k,URHO);
Real rhoInv = 1.0_rt / rho;
Expand Down Expand Up @@ -3504,7 +3504,7 @@ Castro::apply_problem_tags (TagBoxArray& tags, Real time)
const GeometryData& geomdata = geom.data();

amrex::ParallelFor(bx,
[=] AMREX_GPU_HOST_DEVICE (int i, int j, int k)
[=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
{
problem_tagging(i, j, k, tag_arr, state_arr, lev, geomdata);
});
Expand Down Expand Up @@ -3563,7 +3563,7 @@ Castro::apply_tagging_restrictions(TagBoxArray& tags, [[maybe_unused]] Real time
auto tag = tags[mfi].array();

amrex::ParallelFor(bx,
[=] AMREX_GPU_HOST_DEVICE (int i, int j, int k)
[=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
{
bool outer_boundary_test[3] = {false};

Expand Down Expand Up @@ -3607,7 +3607,7 @@ Castro::apply_tagging_restrictions(TagBoxArray& tags, [[maybe_unused]] Real time
auto tag = tags[mfi].array();

amrex::ParallelFor(bx,
[=] AMREX_GPU_HOST_DEVICE (int i, int j, int k)
[=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
{
const Real* problo = geomdata.ProbLo();
const Real* probhi = geomdata.ProbHi();
Expand Down Expand Up @@ -3700,7 +3700,7 @@ Castro::reset_internal_energy(const Box& bx,
Real ldual_energy_eta2 = dual_energy_eta2;

amrex::ParallelFor(bx,
[=] AMREX_GPU_HOST_DEVICE (int i, int j, int k)
[=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
{
Real rhoInv = 1.0_rt / u(i,j,k,URHO);
Real Up = u(i,j,k,UMX) * rhoInv;
Expand Down Expand Up @@ -3827,7 +3827,7 @@ Castro::add_magnetic_e( MultiFab& Bx,


ParallelFor(box,
[=] AMREX_GPU_HOST_DEVICE (int i, int j, int k)
[=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
{

Real bx_cell_c = 0.5_rt * (Bx_arr(i,j,k) + Bx_arr(i+1,j,k));
Expand Down Expand Up @@ -3872,7 +3872,7 @@ Castro::check_div_B( MultiFab& Bx,
const auto dx = geom.CellSizeArray();

reduce_op.eval(box, reduce_data,
[=] AMREX_GPU_HOST_DEVICE (int i, int j, int k) -> ReduceTuple
[=] AMREX_GPU_DEVICE (int i, int j, int k) -> ReduceTuple
{

Real divB = (Bx_arr(i+1,j,k) - Bx_arr(i,j,k))/dx[0] +
Expand Down Expand Up @@ -4019,7 +4019,7 @@ Castro::computeTemp(
Array4<Real> const u = u_fab.array();

amrex::ParallelFor(bx,
[=] AMREX_GPU_HOST_DEVICE (int i, int j, int k)
[=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
{

Real rhoInv = 1.0_rt / u(i,j,k,URHO);
Expand All @@ -4046,7 +4046,7 @@ Castro::computeTemp(

if (clamp_ambient_temp == 1) {
amrex::ParallelFor(bx,
[=] AMREX_GPU_DEVICE (int i, int j, int k)
[=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
{
Real rhoInv = 1.0_rt / u(i,j,k,URHO);

Expand Down Expand Up @@ -4293,7 +4293,7 @@ Castro::define_new_center(MultiFab& S, Real time)
Real cen = data(mi[0], mi[1], mi[2]);

amrex::ParallelFor(box,
[=] AMREX_GPU_HOST_DEVICE (int i, int j, int k) {
[=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
data(i,j,k) -= cen;
});

Expand Down
2 changes: 1 addition & 1 deletion Source/driver/Castro_advance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ Castro::initialize_advance(Real time, Real dt, int amr_iteration)
auto geomdata = geom.data();

amrex::ParallelFor(box,
[=] AMREX_GPU_HOST_DEVICE (int i, int j, int k)
[=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
{
// redo the problem initialization. We want to preserve
// the current velocity though, so save that and then
Expand Down
2 changes: 1 addition & 1 deletion Source/driver/Castro_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ Castro::restart (Amr& papa,
auto geomdata = geom.data();

amrex::ParallelFor(bx,
[=] AMREX_GPU_HOST_DEVICE (int i, int j, int k)
[=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
{
// C++ problem initialization; has no effect if not implemented
// by a problem setup (defaults to an empty routine).
Expand Down
Loading

0 comments on commit dbf68f5

Please sign in to comment.