From 9721942b17b8fc4332045fb7b28107d93c2e85fe Mon Sep 17 00:00:00 2001 From: Ben Ryan Date: Sat, 21 Sep 2024 15:15:15 -0600 Subject: [PATCH] soft_equiv used for testing --- src/utils/robust.hpp | 2 +- tst/unit/kokkos_abstraction.cpp | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/utils/robust.hpp b/src/utils/robust.hpp index 10b3462c5921..1a3d1ef1b445 100644 --- a/src/utils/robust.hpp +++ b/src/utils/robust.hpp @@ -65,7 +65,7 @@ KOKKOS_FORCEINLINE_FUNCTION bool soft_equiv(const Real &val, const Real &ref, const Real eps = 10. * std::numeric_limits::epsilon(), const bool pass_on_small = true) { - if (std::fabs(val - ref) < precision * fabs(ref)) { + if (std::fabs(val - ref) < eps * fabs(ref)) { // Return true equivalence if value and reference differ by less than precision return true; } else { diff --git a/tst/unit/kokkos_abstraction.cpp b/tst/unit/kokkos_abstraction.cpp index 525877375121..0d6afbe00d5b 100644 --- a/tst/unit/kokkos_abstraction.cpp +++ b/tst/unit/kokkos_abstraction.cpp @@ -26,12 +26,14 @@ #include "basic_types.hpp" #include "kokkos_abstraction.hpp" +#include "utils/robust.hpp" using parthenon::DevExecSpace; using parthenon::ParArray1D; using parthenon::ParArray2D; using parthenon::ParArray3D; using parthenon::ParArray4D; +using parthenon::robust::soft_equiv; using Real = double; template @@ -316,7 +318,6 @@ bool test_wrapper_nested_3d(OuterLoopPattern outer_loop_pattern, // Copy array back from device to host Kokkos::deep_copy(host_du, dev_du); - Real max_rel_err = -1; const Real rel_tol = std::numeric_limits::epsilon(); // compare data on the host @@ -326,12 +327,14 @@ bool test_wrapper_nested_3d(OuterLoopPattern outer_loop_pattern, const Real analytic = 2.0 * (i + 1) * pow((j + 2) * (k + 3), 2.0); const Real err = host_du(k, j, i - 1) - analytic; - max_rel_err = fmax(fabs(err / analytic), max_rel_err); + if (!soft_equiv(err, analytic, max_rel_err)) { + return false; + } } } } - return max_rel_err < rel_tol; + return true; } template @@ -385,7 +388,6 @@ bool test_wrapper_nested_4d(OuterLoopPattern outer_loop_pattern, // Copy array back from device to host Kokkos::deep_copy(host_du, dev_du); - Real max_rel_err = -1; const Real rel_tol = std::numeric_limits::epsilon(); // compare data on the host @@ -396,13 +398,15 @@ bool test_wrapper_nested_4d(OuterLoopPattern outer_loop_pattern, const Real analytic = 2.0 * (i + 1) * pow((j + 2) * (k + 3) * (n + 4), 2.0); const Real err = host_du(n, k, j, i - 1) - analytic; - max_rel_err = fmax(fabs(err / analytic), max_rel_err); + if (!soft_equiv(err, analytic, max_rel_err)) { + return false; + } } } } } - return max_rel_err < rel_tol; + return true; } TEST_CASE("nested par_for loops", "[wrapper]") {