Skip to content

Commit

Permalink
TestDerivs: remove usage of funciton pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
lwJi committed Dec 25, 2024
1 parent 2d169e8 commit 8791c63
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 60 deletions.
40 changes: 16 additions & 24 deletions Derivs/src/derivs.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,8 @@ calc_derivs(const GF3D5<T> &gf, const vec<GF3D5<T>, dim> &dgf,
grid.nghostzones,
[=] CCTK_DEVICE(const PointDesc &p) CCTK_ATTRIBUTE_ALWAYS_INLINE {
const vbool mask = mask_for_loop_tail<vbool>(p.i, p.imax);
// Take account of ghost points
const vbool mask1 =
mask_for_loop_tail<vbool>(p.i, p.imax + deriv_order / 2);
// Take ghost points into account
const vbool mask1 = mask_for_loop_tail<vbool>(p.i, p.imax + 2 / 2);
const GF3D5index index(layout, p.I);
const auto val = gf0(mask, p.I);
const auto dval = calc_deriv<2>(gf0, mask1, p.I, dx);
Expand All @@ -77,9 +76,8 @@ calc_derivs(const GF3D5<T> &gf, const vec<GF3D5<T>, dim> &dgf,
grid.nghostzones,
[=] CCTK_DEVICE(const PointDesc &p) CCTK_ATTRIBUTE_ALWAYS_INLINE {
const vbool mask = mask_for_loop_tail<vbool>(p.i, p.imax);
// Take account of ghost points
const vbool mask1 =
mask_for_loop_tail<vbool>(p.i, p.imax + deriv_order / 2);
// Take ghost points into account
const vbool mask1 = mask_for_loop_tail<vbool>(p.i, p.imax + 4 / 2);
const GF3D5index index(layout, p.I);
const auto val = gf0(mask, p.I);
const auto dval = calc_deriv<4>(gf0, mask1, p.I, dx);
Expand All @@ -93,9 +91,8 @@ calc_derivs(const GF3D5<T> &gf, const vec<GF3D5<T>, dim> &dgf,
grid.nghostzones,
[=] CCTK_DEVICE(const PointDesc &p) CCTK_ATTRIBUTE_ALWAYS_INLINE {
const vbool mask = mask_for_loop_tail<vbool>(p.i, p.imax);
// Take account of ghost points
const vbool mask1 =
mask_for_loop_tail<vbool>(p.i, p.imax + deriv_order / 2);
// Take ghost points into account
const vbool mask1 = mask_for_loop_tail<vbool>(p.i, p.imax + 6 / 2);
const GF3D5index index(layout, p.I);
const auto val = gf0(mask, p.I);
const auto dval = calc_deriv<6>(gf0, mask1, p.I, dx);
Expand All @@ -109,9 +106,8 @@ calc_derivs(const GF3D5<T> &gf, const vec<GF3D5<T>, dim> &dgf,
grid.nghostzones,
[=] CCTK_DEVICE(const PointDesc &p) CCTK_ATTRIBUTE_ALWAYS_INLINE {
const vbool mask = mask_for_loop_tail<vbool>(p.i, p.imax);
// Take account of ghost points
const vbool mask1 =
mask_for_loop_tail<vbool>(p.i, p.imax + deriv_order / 2);
// Take ghost points into account
const vbool mask1 = mask_for_loop_tail<vbool>(p.i, p.imax + 8 / 2);
const GF3D5index index(layout, p.I);
const auto val = gf0(mask, p.I);
const auto dval = calc_deriv<8>(gf0, mask1, p.I, dx);
Expand Down Expand Up @@ -166,9 +162,8 @@ calc_derivs2(const GF3D5<T> &gf, const vec<GF3D5<T>, dim> &dgf,
grid.nghostzones,
[=] CCTK_DEVICE(const PointDesc &p) CCTK_ATTRIBUTE_ALWAYS_INLINE {
const vbool mask = mask_for_loop_tail<vbool>(p.i, p.imax);
// Take account of ghost points
const vbool mask1 =
mask_for_loop_tail<vbool>(p.i, p.imax + deriv_order / 2);
// Take ghost points into account
const vbool mask1 = mask_for_loop_tail<vbool>(p.i, p.imax + 2 / 2);
const GF3D5index index(layout, p.I);
const auto val = gf0(mask, p.I);
const auto dval = calc_deriv<2>(gf0, mask1, p.I, dx);
Expand All @@ -184,9 +179,8 @@ calc_derivs2(const GF3D5<T> &gf, const vec<GF3D5<T>, dim> &dgf,
grid.nghostzones,
[=] CCTK_DEVICE(const PointDesc &p) CCTK_ATTRIBUTE_ALWAYS_INLINE {
const vbool mask = mask_for_loop_tail<vbool>(p.i, p.imax);
// Take account of ghost points
const vbool mask1 =
mask_for_loop_tail<vbool>(p.i, p.imax + deriv_order / 2);
// Take ghost points into account
const vbool mask1 = mask_for_loop_tail<vbool>(p.i, p.imax + 4 / 2);
const GF3D5index index(layout, p.I);
const auto val = gf0(mask, p.I);
const auto dval = calc_deriv<4>(gf0, mask1, p.I, dx);
Expand All @@ -202,9 +196,8 @@ calc_derivs2(const GF3D5<T> &gf, const vec<GF3D5<T>, dim> &dgf,
grid.nghostzones,
[=] CCTK_DEVICE(const PointDesc &p) CCTK_ATTRIBUTE_ALWAYS_INLINE {
const vbool mask = mask_for_loop_tail<vbool>(p.i, p.imax);
// Take account of ghost points
const vbool mask1 =
mask_for_loop_tail<vbool>(p.i, p.imax + deriv_order / 2);
// Take ghost points into account
const vbool mask1 = mask_for_loop_tail<vbool>(p.i, p.imax + 6 / 2);
const GF3D5index index(layout, p.I);
const auto val = gf0(mask, p.I);
const auto dval = calc_deriv<6>(gf0, mask1, p.I, dx);
Expand All @@ -220,9 +213,8 @@ calc_derivs2(const GF3D5<T> &gf, const vec<GF3D5<T>, dim> &dgf,
grid.nghostzones,
[=] CCTK_DEVICE(const PointDesc &p) CCTK_ATTRIBUTE_ALWAYS_INLINE {
const vbool mask = mask_for_loop_tail<vbool>(p.i, p.imax);
// Take account of ghost points
const vbool mask1 =
mask_for_loop_tail<vbool>(p.i, p.imax + deriv_order / 2);
// Take ghost points into account
const vbool mask1 = mask_for_loop_tail<vbool>(p.i, p.imax + 8 / 2);
const GF3D5index index(layout, p.I);
const auto val = gf0(mask, p.I);
const auto dval = calc_deriv<8>(gf0, mask1, p.I, dx);
Expand Down
90 changes: 58 additions & 32 deletions TestDerivs/src/test.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,8 @@ extern "C" void TestDerivs_Set(CCTK_ARGUMENTS) {
const vreal x0 = p.x + Arith::iota<vreal>() * p.dx;
const CCTK_REAL y0 = p.y;
const CCTK_REAL z0 = p.z;
chi.store(
mask, p.I,
poly(kxx, kxy, kyz, cos(x0), std::sin(y0), std::sin(z0)));
chi.store(mask, p.I,
poly(kxx, kxy, kyz, cos(x0), std::sin(y0), std::sin(z0)));
});

grid.loop_int_device<0, 0, 0>(
Expand Down Expand Up @@ -200,52 +199,79 @@ extern "C" void TestDerivs_CalcDerivs(CCTK_ARGUMENTS) {
typedef Arith::simdl<CCTK_REAL> vbool;
constexpr size_t vsize = std::tuple_size_v<vreal>;

vreal (*calc_deriv_upwind)(const GF3D2<const CCTK_REAL> &, const vbool &,
const Arith::vect<int, dim> &,
const Arith::vect<CCTK_REAL, dim> &,
const Arith::vec<vreal, dim> &);
vreal (*calc_diss)(const GF3D2<const CCTK_REAL> &, const vbool &,
const Arith::vect<int, dim> &,
const Arith::vect<CCTK_REAL, dim> &);

switch (deriv_order) {
case 2: {
calc_deriv_upwind = &Derivs::calc_deriv_upwind<2>;
calc_diss = &Derivs::calc_diss<2>;
grid.loop_int_device<0, 0, 0, vsize>(
grid.nghostzones, [=] ARITH_DEVICE(const PointDesc &p) ARITH_INLINE {
const vbool mask = Arith::mask_for_loop_tail<vbool>(p.i, p.imax);
const GF3D2index index2(layout2, p.I);
const GF3D5index index5(layout5, p.I);
gf_dchi.store(mask, index2, t5_dchi(mask, index5));
gf_ddchi.store(mask, index2, t5_ddchi(mask, index5));
gf_chi_diss.store(mask, index2,
Derivs::calc_diss<2>(gf2_chi, mask, p.I, dx));
gf_chi_upwind.store(
mask, index2,
Derivs::calc_deriv_upwind<2>(gf2_chi, mask, p.I, dx,
gf_beta(mask, index2)));
});
break;
}
case 4: {
calc_deriv_upwind = &Derivs::calc_deriv_upwind<4>;
calc_diss = &Derivs::calc_diss<4>;
grid.loop_int_device<0, 0, 0, vsize>(
grid.nghostzones, [=] ARITH_DEVICE(const PointDesc &p) ARITH_INLINE {
const vbool mask = Arith::mask_for_loop_tail<vbool>(p.i, p.imax);
const GF3D2index index2(layout2, p.I);
const GF3D5index index5(layout5, p.I);
gf_dchi.store(mask, index2, t5_dchi(mask, index5));
gf_ddchi.store(mask, index2, t5_ddchi(mask, index5));
gf_chi_diss.store(mask, index2,
Derivs::calc_diss<4>(gf2_chi, mask, p.I, dx));
gf_chi_upwind.store(
mask, index2,
Derivs::calc_deriv_upwind<4>(gf2_chi, mask, p.I, dx,
gf_beta(mask, index2)));
});
break;
}
case 6: {
calc_deriv_upwind = &Derivs::calc_deriv_upwind<6>;
calc_diss = &Derivs::calc_diss<6>;
grid.loop_int_device<0, 0, 0, vsize>(
grid.nghostzones, [=] ARITH_DEVICE(const PointDesc &p) ARITH_INLINE {
const vbool mask = Arith::mask_for_loop_tail<vbool>(p.i, p.imax);
const GF3D2index index2(layout2, p.I);
const GF3D5index index5(layout5, p.I);
gf_dchi.store(mask, index2, t5_dchi(mask, index5));
gf_ddchi.store(mask, index2, t5_ddchi(mask, index5));
gf_chi_diss.store(mask, index2,
Derivs::calc_diss<6>(gf2_chi, mask, p.I, dx));
gf_chi_upwind.store(
mask, index2,
Derivs::calc_deriv_upwind<6>(gf2_chi, mask, p.I, dx,
gf_beta(mask, index2)));
});
break;
}
case 8: {
calc_deriv_upwind = &Derivs::calc_deriv_upwind<8>;
calc_diss = &Derivs::calc_diss<8>;
grid.loop_int_device<0, 0, 0, vsize>(
grid.nghostzones, [=] ARITH_DEVICE(const PointDesc &p) ARITH_INLINE {
const vbool mask = Arith::mask_for_loop_tail<vbool>(p.i, p.imax);
const GF3D2index index2(layout2, p.I);
const GF3D5index index5(layout5, p.I);
gf_dchi.store(mask, index2, t5_dchi(mask, index5));
gf_ddchi.store(mask, index2, t5_ddchi(mask, index5));
gf_chi_diss.store(mask, index2,
Derivs::calc_diss<8>(gf2_chi, mask, p.I, dx));
gf_chi_upwind.store(
mask, index2,
Derivs::calc_deriv_upwind<8>(gf2_chi, mask, p.I, dx,
gf_beta(mask, index2)));
});
break;
}
default:
assert(0);
}

grid.loop_int_device<0, 0, 0, vsize>(
grid.nghostzones, [=] ARITH_DEVICE(const PointDesc &p) ARITH_INLINE {
const vbool mask = Arith::mask_for_loop_tail<vbool>(p.i, p.imax);
const GF3D2index index2(layout2, p.I);
const GF3D5index index5(layout5, p.I);
gf_dchi.store(mask, index2, t5_dchi(mask, index5));
gf_ddchi.store(mask, index2, t5_ddchi(mask, index5));
gf_chi_diss.store(mask, index2, calc_diss(gf2_chi, mask, p.I, dx));
gf_chi_upwind.store(
mask, index2,
calc_deriv_upwind(gf2_chi, mask, p.I, dx, gf_beta(mask, index2)));
});

#if CCTK_DEBUG
grid.loop_int_device<0, 0, 0>(
grid.nghostzones, [=] ARITH_DEVICE(const PointDesc &p) ARITH_INLINE {
Expand Down
9 changes: 5 additions & 4 deletions TestDerivs/test/derivs-8th-order.par
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ CarpetX::xmax = 0.1234567+$pi
CarpetX::ymax = 0.2345678+$pi
CarpetX::zmax = 0.3456789+$pi

CarpetX::periodic_x = "yes"
CarpetX::periodic_y = "yes"
CarpetX::periodic_z = "yes"
Driver::periodic = "yes"
Driver::periodic_x = "yes"
Driver::periodic_y = "yes"
Driver::periodic_z = "yes"

CarpetX::ncells_x = $ncells
CarpetX::ncells_y = $ncells
Expand All @@ -39,7 +40,7 @@ CarpetX::blocking_factor_z = $blocking_factor

CarpetX::max_num_levels = $nlevels
CarpetX::regrid_every = 1
CarpetX::regrid_error_threshold = 0.01
Driver::regrid_error_threshold = 0.01

CarpetX::dtfac = 0.5

Expand Down

0 comments on commit 8791c63

Please sign in to comment.