From ede77327f9a79a46e15a20fd315763dc11cc5b30 Mon Sep 17 00:00:00 2001 From: Michael Zingale Date: Mon, 9 Oct 2023 11:47:56 -0400 Subject: [PATCH] convert AMREX_PARALLEL_FOR_ND loops to amrex::ParallelFor in SDC (#2623) --- Source/sdc/sdc_util.cpp | 66 +++++++++++++++++++++++++++-------------- 1 file changed, 44 insertions(+), 22 deletions(-) diff --git a/Source/sdc/sdc_util.cpp b/Source/sdc/sdc_util.cpp index 6d471ab9a3..6d2cadaf39 100644 --- a/Source/sdc/sdc_util.cpp +++ b/Source/sdc/sdc_util.cpp @@ -20,7 +20,8 @@ Castro::ca_sdc_update_advection_o2_lobatto(const Box& bx, // Gauss-Lobatto / trapezoid - AMREX_PARALLEL_FOR_4D(bx, k_n.nComp(), i, j, k, n, + amrex::ParallelFor(bx, k_n.nComp(), + [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept { k_n(i,j,k,n) = k_m(i,j,k,n) + 0.5_rt * dt * (A_0_old(i,j,k,n) + A_1_old(i,j,k,n)); }); @@ -48,7 +49,8 @@ Castro::ca_sdc_update_advection_o2_radau(const Box& bx, if (m_start == 0) { - AMREX_PARALLEL_FOR_4D(bx, k_n.nComp(), i, j, k, n, + amrex::ParallelFor(bx, k_n.nComp(), + [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept { k_n(i,j,k,n) = k_m(i,j,k,n) + dt_m * (A_m(i,j,k,n) - A_0_old(i,j,k,n)) + @@ -57,7 +59,8 @@ Castro::ca_sdc_update_advection_o2_radau(const Box& bx, } else if (m_start == 1) { - AMREX_PARALLEL_FOR_4D(bx, k_n.nComp(), i, j, k, n, + amrex::ParallelFor(bx, k_n.nComp(), + [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept { k_n(i,j,k,n) = k_m(i,j,k,n) + dt_m * (A_m(i,j,k,n) - A_1_old(i,j,k,n)) + @@ -86,7 +89,8 @@ Castro::ca_sdc_update_advection_o4_lobatto(const Box& bx, if (m_start == 0) { - AMREX_PARALLEL_FOR_4D(bx, k_n.nComp(), i, j, k, n, + amrex::ParallelFor(bx, k_n.nComp(), + [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept { k_n(i,j,k,n) = k_m(i,j,k,n) + dt_m * (A_m(i,j,k,n) - A_0_old(i,j,k,n)) + @@ -95,7 +99,8 @@ Castro::ca_sdc_update_advection_o4_lobatto(const Box& bx, } else if (m_start == 1) { - AMREX_PARALLEL_FOR_4D(bx, k_n.nComp(), i, j, k, n, + amrex::ParallelFor(bx, k_n.nComp(), + [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept { k_n(i,j,k,n) = k_m(i,j,k,n) + dt_m * (A_m(i,j,k,n) - A_1_old(i,j,k,n)) + @@ -129,7 +134,8 @@ Castro::ca_sdc_update_advection_o4_radau(const Box& bx, if (m_start == 0) { - AMREX_PARALLEL_FOR_4D(bx, k_n.nComp(), i, j, k, n, + amrex::ParallelFor(bx, k_n.nComp(), + [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept { k_n(i,j,k,n) = k_m(i,j,k,n) + dt_m * (A_m(i,j,k,n) - A_0_old(i,j,k,n)) + @@ -140,7 +146,8 @@ Castro::ca_sdc_update_advection_o4_radau(const Box& bx, } else if (m_start == 1) { - AMREX_PARALLEL_FOR_4D(bx, k_n.nComp(), i, j, k, n, + amrex::ParallelFor(bx, k_n.nComp(), + [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept { k_n(i,j,k,n) = k_m(i,j,k,n) + dt_m * (A_m(i,j,k,n) - A_1_old(i,j,k,n)) + @@ -151,7 +158,8 @@ Castro::ca_sdc_update_advection_o4_radau(const Box& bx, } else if (m_start == 2) { - AMREX_PARALLEL_FOR_4D(bx, k_n.nComp(), i, j, k, n, + amrex::ParallelFor(bx, k_n.nComp(), + [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept { k_n(i,j,k,n) = k_m(i,j,k,n) + dt_m * (A_m(i,j,k,n) - A_2_old(i,j,k,n)) + @@ -182,7 +190,8 @@ Castro::ca_sdc_compute_C2_lobatto(const Box& bx, // Here, dt_m is the timestep between time-nodes m and m+1 - AMREX_PARALLEL_FOR_4D(bx, C.nComp(), i, j, k, n, + amrex::ParallelFor(bx, C.nComp(), + [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept { // construct the source term to the update for 2nd order // Lobatto, there is no advective correction, and we have @@ -216,7 +225,8 @@ Castro::ca_sdc_compute_C2_radau(const Box& bx, if (m_start == 0) { - AMREX_PARALLEL_FOR_4D(bx, C.nComp(), i, j, k, n, + amrex::ParallelFor(bx, C.nComp(), + [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept { C(i,j,k,n) = -R_1_old(i,j,k,n) + (A_m(i,j,k,n) - A_0_old(i,j,k,n)) + @@ -227,7 +237,8 @@ Castro::ca_sdc_compute_C2_radau(const Box& bx, } else if (m_start == 1) { - AMREX_PARALLEL_FOR_4D(bx, C.nComp(), i, j, k, n, + amrex::ParallelFor(bx, C.nComp(), + [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept { C(i,j,k,n) = -R_2_old(i,j,k,n) + (A_m(i,j,k,n) - A_1_old(i,j,k,n)) + @@ -260,7 +271,8 @@ Castro::ca_sdc_compute_C4_lobatto(const Box& bx, if (m_start == 0) { // compute the integral from [t_m, t_{m+1}], normalized by dt_m - AMREX_PARALLEL_FOR_4D(bx, C.nComp(), i, j, k, n, + amrex::ParallelFor(bx, C.nComp(), + [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept { Real integral = 1.0_rt/12.0_rt * (5.0_rt*(A_0_old(i,j,k,n) + R_0_old(i,j,k,n)) + 8.0_rt*(A_1_old(i,j,k,n) + R_1_old(i,j,k,n)) - @@ -272,7 +284,8 @@ Castro::ca_sdc_compute_C4_lobatto(const Box& bx, else if (m_start == 1) { // compute the integral from [t_m, t_{m+1}], normalized by dt_m - AMREX_PARALLEL_FOR_4D(bx, C.nComp(), i, j, k, n, + amrex::ParallelFor(bx, C.nComp(), + [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept { Real integral = 1.0_rt/12.0_rt * (-(A_0_old(i,j,k,n) + R_0_old(i,j,k,n)) + 8.0_rt*(A_1_old(i,j,k,n) + R_1_old(i,j,k,n)) + @@ -312,7 +325,8 @@ Castro::ca_sdc_compute_C4_radau(const Box& bx, if (m_start == 0) { // compute the integral from [t_m, t_{m+1}], normalized by dt_m - AMREX_PARALLEL_FOR_4D(bx, C.nComp(), i, j, k, n, + amrex::ParallelFor(bx, C.nComp(), + [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept { Real integral = (dt/dt_m) * (1.0_rt/1800.0_rt) * ((-35.0_rt*std::sqrt(6.0_rt) + 440.0_rt)*(A_1_old(i,j,k,n) + R_1_old(i,j,k,n)) + @@ -325,7 +339,8 @@ Castro::ca_sdc_compute_C4_radau(const Box& bx, else if (m_start == 1) { // compute the integral from [t_m, t_{m+1}], normalized by dt_m - AMREX_PARALLEL_FOR_4D(bx, C.nComp(), i, j, k, n, + amrex::ParallelFor(bx, C.nComp(), + [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept { Real integral = (dt/dt_m) * (1.0_rt/150.0_rt) * ((-12.0_rt + 17.0_rt*std::sqrt(6.0_rt))*(A_1_old(i,j,k,n) + R_1_old(i,j,k,n)) + @@ -338,7 +353,8 @@ Castro::ca_sdc_compute_C4_radau(const Box& bx, else if (m_start == 2) { // compute the integral from [t_m, t_{m+1}], normalized by dt_m - AMREX_PARALLEL_FOR_4D(bx, C.nComp(), i, j, k, n, + amrex::ParallelFor(bx, C.nComp(), + [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept { Real integral = (dt/dt_m) * (1.0_rt/600.0_rt) * ((168.0_rt - 73.0_rt*std::sqrt(6.0_rt))*(A_1_old(i,j,k,n) + R_1_old(i,j,k,n)) + @@ -364,7 +380,8 @@ Castro::ca_sdc_conservative_update(const Box& bx, Real const dt_m, // given _old, _new, and , compute _new // now consider the reacting system - AMREX_PARALLEL_FOR_4D(bx, U_new.nComp(), i, j, k, n, + amrex::ParallelFor(bx, U_new.nComp(), + [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept { U_new(i,j,k,n) = U_old(i,j,k,n) + dt_m * R_new(i,j,k,n) + dt_m * C(i,j,k,n); }); @@ -385,14 +402,16 @@ void Castro::ca_sdc_compute_initial_guess(const Box& bx, if (sdc_iteration == 0) { - AMREX_PARALLEL_FOR_4D(bx, U_guess.nComp(), i, j, k, n, + amrex::ParallelFor(bx, U_guess.nComp(), + [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept { U_guess(i,j,k,n) = U_old(i,j,k,n) + dt_m * A_old(i,j,k,n) + dt_m * R_old(i,j,k,n); }); } else { - AMREX_PARALLEL_FOR_4D(bx, U_guess.nComp(), i, j, k, n, + amrex::ParallelFor(bx, U_guess.nComp(), + [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept { U_guess(i,j,k,n) = U_new(i,j,k,n); }); @@ -412,20 +431,23 @@ void Castro::ca_store_reaction_state(const Box& bx, // Reactions_Type if (store_omegadot) { - AMREX_PARALLEL_FOR_4D(bx, NumSpec, i, j, k, n, + amrex::ParallelFor(bx, NumSpec, + [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept { R_store(i,j,k,1+n) = R_old(i,j,k,UFS+n); }); #if NAUX_NET > 0 - AMREX_PARALLEL_FOR_4D(bx, NumAux, i, j, k, n, + amrex::ParallelFor(bx, NumAux, + [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept { R_store(i,j,k,1+NumSpec+n) = R_old(i,j,k,UFX+n); }); #endif } - AMREX_PARALLEL_FOR_3D(bx, i, j, k, + amrex::ParallelFor(bx, + [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept { R_store(i,j,k,0) = R_old(i,j,k,UEDEN); });