diff --git a/benchmarks/impl_point.hpp b/benchmarks/impl_point.hpp index 5dc1d932..5150c438 100644 --- a/benchmarks/impl_point.hpp +++ b/benchmarks/impl_point.hpp @@ -6,7 +6,7 @@ namespace specfem { namespace benchmarks { -#define PROPERTIES_CONSTRUCTOR \ +#define DEFINE_PROP_CONSTRUCTORS \ KOKKOS_FUNCTION \ properties() = default; \ KOKKOS_FUNCTION \ @@ -18,6 +18,10 @@ namespace benchmarks { compute(); \ } +#define DEFINE_PROP(prop, i) \ + KOKKOS_INLINE_FUNCTION value_type prop() const { return Base::data[i]; } \ + KOKKOS_INLINE_FUNCTION void prop(value_type val) { Base::data[i] = val; } + namespace impl { template struct impl_properties { using simd = specfem::datatype::simd; ///< SIMD type @@ -114,31 +118,21 @@ struct propertieslambdaplus2mu = lambdaplus2mu; - // this->mu = mu; - // this->rho = rho; - // compute(); - // } + DEFINE_PROP_CONSTRUCTORS KOKKOS_INLINE_FUNCTION void compute() { - rho_vp = Kokkos::sqrt(rho * lambdaplus2mu); - rho_vs = Kokkos::sqrt(rho * mu); - lambda = lambdaplus2mu - (static_cast(2.0)) * mu; + rho_vp(Kokkos::sqrt(rho() * lambdaplus2mu())); + rho_vs(Kokkos::sqrt(rho() * mu())); + lambda(lambdaplus2mu() - (static_cast(2.0)) * mu()); } }; @@ -169,46 +163,27 @@ struct propertiesc11 = c11; - // this->c13 = c13; - // this->c15 = c15; - // this->c33 = c33; - // this->c35 = c35; - // this->c55 = c55; - // this->c12 = c12; - // this->c23 = c23; - // this->c25 = c25; - // this->rho = rho; - // compute(); - // } + DEFINE_PROP(rho, 9); ///< Density @f$ \rho @f$ + DEFINE_PROP(rho_vp, 10); ///< P-wave velocity @f$ \rho v_p @f$ + DEFINE_PROP(rho_vs, 11); ///< S-wave velocity @f$ \rho v_s @f$ + + DEFINE_PROP_CONSTRUCTORS KOKKOS_INLINE_FUNCTION void compute() { - rho_vp = Kokkos::sqrt(rho * c33); - rho_vs = Kokkos::sqrt(rho * c55); + rho_vp(Kokkos::sqrt(rho() * c33())); + rho_vs(Kokkos::sqrt(rho() * c55())); } }; @@ -240,30 +215,23 @@ struct propertiesrho_inverse = rho_inverse; - // this->kappa = kappa; - // compute(); - // } + DEFINE_PROP(rho_inverse, 0) ///< @f$ \frac{1}{\rho} @f$ + DEFINE_PROP(kappa, 1) ///< Bulk modulus @f$ \kappa @f$ + DEFINE_PROP(kappa_inverse, 2) ///< @f$ \frac{1}{\lambda + 2\mu} @f$ + DEFINE_PROP(rho_vpinverse, 3) ///< @f$ \frac{1}{\rho v_p} @f$ +private: KOKKOS_INLINE_FUNCTION void compute() { - kappa_inverse = (static_cast(1.0)) / kappa; - rho_vpinverse = Kokkos::sqrt(rho_inverse * kappa_inverse); + kappa_inverse((static_cast(1.0)) / kappa()); + rho_vpinverse(Kokkos::sqrt(rho_inverse() * kappa_inverse())); } }; -#undef PROPERTIES_CONSTRUCTOR +#undef DEFINE_PROP_CONSTRUCTORS +#undef DEFINE_PROP } // namespace benchmarks } // namespace specfem diff --git a/benchmarks/main.cpp b/benchmarks/main.cpp index 060acfae..e00c8792 100644 --- a/benchmarks/main.cpp +++ b/benchmarks/main.cpp @@ -1,4 +1,4 @@ -// #include "archive/stiffness1.hpp" +#include "archive/stiffness1.hpp" #include "execute.hpp" #include "stiffness.hpp" // #include "divide.hpp" @@ -47,26 +47,30 @@ void benchmark(specfem::compute::assembly &assembly, // field.elastic.nglob, field.elastic.components); for (const auto [istep, dt] : time_scheme->iterate_forward()) { - compute_stiffness_interaction(assembly, istep); - compute_stiffness_interaction(assembly, istep); - compute_stiffness_interaction(assembly, istep); + // compute_stiffness_interaction(assembly, + // istep); compute_stiffness_interaction(assembly, + // istep); compute_stiffness_interaction(assembly, istep); // compute_stiffness_interaction2(assembly, // istep); compute_stiffness_interaction2(assembly, istep); compute_stiffness_interaction2(assembly, istep); - // if constexpr (flag) { - // compute_stiffness_interaction(assembly, - // istep); compute_stiffness_interaction(assembly, istep); compute_stiffness_interaction(assembly, istep); - // } else { - // compute_stiffness_interaction2(assembly, - // istep); compute_stiffness_interaction2(assembly, istep); compute_stiffness_interaction2(assembly, istep); - // } + if constexpr (flag) { + compute_stiffness_interaction(assembly, + istep); + compute_stiffness_interaction(assembly, istep); + compute_stiffness_interaction(assembly, + istep); + } else { + compute_stiffness_interaction2(assembly, + istep); + compute_stiffness_interaction2(assembly, + istep); + compute_stiffness_interaction2(assembly, + istep); + } // divide_mass_matrix(assembly); // divide_mass_matrix(assembly); diff --git a/benchmarks/stiffness.hpp b/benchmarks/stiffness.hpp index 81d70d79..045196af 100644 --- a/benchmarks/stiffness.hpp +++ b/benchmarks/stiffness.hpp @@ -187,15 +187,9 @@ void compute_stiffness_interaction(const specfem::compute::assembly &assembly, xiz * df_dxi[icomponent] + gammaz * df_dgamma[icomponent]; } - auto point_property = [&]() { - if constexpr (flag) { - return specfem::point::properties< - dimension, medium_tag, property_tag, using_simd>(); - } else { - return specfem::benchmarks::properties< - dimension, medium_tag, property_tag, using_simd>(); - } - }(); + specfem::benchmarks::properties + point_property; specfem::point::field_derivatives @@ -211,14 +205,14 @@ void compute_stiffness_interaction(const specfem::compute::assembly &assembly, specfem::element::medium_tag::acoustic && PropertyTag == specfem::element::property_tag::isotropic) { - point_property.rho_inverse = - container.rho_inverse(ispec, iz, ix); - point_property.kappa = container.kappa(ispec, iz, ix); - point_property.kappa_inverse = - static_cast(1.0) / point_property.kappa; - point_property.rho_vpinverse = - sqrt(point_property.rho_inverse * - point_property.kappa_inverse); + point_property.rho_inverse( + container.rho_inverse(ispec, iz, ix)); + point_property.kappa(container.kappa(ispec, iz, ix)); + point_property.kappa_inverse(static_cast(1.0) / + point_property.kappa()); + point_property.rho_vpinverse( + sqrt(point_property.rho_inverse() * + point_property.kappa_inverse())); const auto &du = field_derivatives.du; @@ -226,8 +220,8 @@ void compute_stiffness_interaction(const specfem::compute::assembly &assembly, using_simd> T; - T(0, 0) = point_property.rho_inverse * du(0, 0); - T(1, 0) = point_property.rho_inverse * du(1, 0); + T(0, 0) = point_property.rho_inverse() * du(0, 0); + T(1, 0) = point_property.rho_inverse() * du(1, 0); return specfem::point::stress< specfem::dimension::type::dim2, @@ -237,16 +231,16 @@ void compute_stiffness_interaction(const specfem::compute::assembly &assembly, MediumTag == specfem::element::medium_tag::elastic && PropertyTag == specfem::element::property_tag::isotropic) { - point_property.rho = container.rho(ispec, iz, ix); - point_property.mu = container.mu(ispec, iz, ix); - point_property.lambdaplus2mu = - container.lambdaplus2mu(ispec, iz, ix); - point_property.lambda = - point_property.lambdaplus2mu - 2 * point_property.mu; - point_property.rho_vp = - sqrt(point_property.rho * point_property.lambdaplus2mu); - point_property.rho_vs = - sqrt(point_property.rho * point_property.mu); + point_property.rho(container.rho(ispec, iz, ix)); + point_property.mu(container.mu(ispec, iz, ix)); + point_property.lambdaplus2mu( + container.lambdaplus2mu(ispec, iz, ix)); + point_property.lambda(point_property.lambdaplus2mu() - + 2 * point_property.mu()); + point_property.rho_vp(sqrt(point_property.rho() * + point_property.lambdaplus2mu())); + point_property.rho_vs( + sqrt(point_property.rho() * point_property.mu())); using datatype = typename specfem::datatype::simd @@ -277,21 +271,21 @@ void compute_stiffness_interaction(const specfem::compute::assembly &assembly, MediumTag == specfem::element::medium_tag::elastic && PropertyTag == specfem::element::property_tag::anisotropic) { - point_property.rho = container.rho(ispec, iz, ix); - point_property.c11 = container.c11(ispec, iz, ix); - point_property.c12 = container.c12(ispec, iz, ix); - point_property.c13 = container.c13(ispec, iz, ix); - point_property.c15 = container.c15(ispec, iz, ix); - point_property.c33 = container.c33(ispec, iz, ix); - point_property.c35 = container.c35(ispec, iz, ix); - point_property.c55 = container.c55(ispec, iz, ix); - point_property.c23 = container.c23(ispec, iz, ix); - point_property.c25 = container.c25(ispec, iz, ix); - - point_property.rho_vp = - sqrt(point_property.rho * point_property.c33); - point_property.rho_vs = - sqrt(point_property.rho * point_property.c55); + point_property.rho(container.rho(ispec, iz, ix)); + point_property.c11(container.c11(ispec, iz, ix)); + point_property.c12(container.c12(ispec, iz, ix)); + point_property.c13(container.c13(ispec, iz, ix)); + point_property.c15(container.c15(ispec, iz, ix)); + point_property.c33(container.c33(ispec, iz, ix)); + point_property.c35(container.c35(ispec, iz, ix)); + point_property.c55(container.c55(ispec, iz, ix)); + point_property.c23(container.c23(ispec, iz, ix)); + point_property.c25(container.c25(ispec, iz, ix)); + + point_property.rho_vp( + sqrt(point_property.rho() * point_property.c33())); + point_property.rho_vs( + sqrt(point_property.rho() * point_property.c55())); using datatype = typename specfem::datatype::simd