diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 4420f25f..01f68736 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -57,7 +57,6 @@ jobs: -DCMAKE_BUILD_TYPE=${{ matrix.cmake_build_type }} \ -DCMAKE_CXX_COMPILER=${{ matrix.cxx }} \ -DCMAKE_INSTALL_PREFIX=$HOME/kokkos \ - -DCMAKE_CXX_STANDARD=20 \ -DKokkos_ENABLE_${{ matrix.backend }}=ON \ -DKokkos_ENABLE_HWLOC=ON cmake --build build --parallel 2 @@ -149,7 +148,6 @@ jobs: run: | cmake -B build \ -DCMAKE_INSTALL_PREFIX=$HOME/kokkos \ - -DCMAKE_CXX_STANDARD=20 \ -DKokkos_ENABLE_HIP=ON \ -DKokkos_ARCH_VEGA908=ON \ -DCMAKE_BUILD_TYPE=${{ matrix.cmake_build_type }} \ @@ -232,7 +230,6 @@ jobs: run: | cmake -B build \ -DCMAKE_INSTALL_PREFIX=$HOME/kokkos \ - -DCMAKE_CXX_STANDARD=20 \ -DKokkos_ENABLE_CUDA=ON \ -DKokkos_ARCH_VOLTA72=ON \ -DKokkos_ENABLE_CUDA_LAMBDA=ON \ diff --git a/src/CabanaPD_ForceModels.hpp b/src/CabanaPD_ForceModels.hpp index a75b7e41..9a1ff501 100644 --- a/src/CabanaPD_ForceModels.hpp +++ b/src/CabanaPD_ForceModels.hpp @@ -63,13 +63,20 @@ struct BaseForceModel BaseForceModel( const ArrayType& _delta ) : delta( view_type_1d( "delta", _delta.size() ) ) , num_types( _delta.size() ) + { + setParameters( _delta ); + } + + template + void setParameters( const ArrayType& _delta ) { max_delta = 0; - auto init_func = KOKKOS_CLASS_LAMBDA( const int i, double& max ) + auto delta_copy = delta; + auto init_func = KOKKOS_LAMBDA( const int i, double& max ) { - delta( i ) = _delta[i]; - if ( delta( i ) > max ) - max = delta( i ); + delta_copy( i ) = _delta[i]; + if ( delta_copy( i ) > max ) + max = delta_copy( i ); }; using exec_space = typename memory_space::execution_space; Kokkos::RangePolicy policy( 0, num_types ); @@ -99,7 +106,6 @@ struct BaseTemperatureModel // Temperature field TemperatureType temperature; - BaseTemperatureModel(){}; BaseTemperatureModel( const TemperatureType _temp, const double _alpha, const double _temp0 ) : alpha( _alpha ) @@ -131,17 +137,25 @@ struct BaseTemperatureModel ParticleType type; template - BaseTemperatureModel( const TemperatureType& _temp, const ArrayType _alpha, - const ArrayType _temp0, const ParticleType& _type ) + BaseTemperatureModel( const TemperatureType& _temp, const ArrayType& _alpha, + const ArrayType& _temp0, const ParticleType& _type ) : alpha( view_type_1d( "delta", _alpha.size() ) ) , temp0( view_type_1d( "delta", _temp0.size() ) ) , temperature( _temp ) , type( _type ) { - auto init_func = KOKKOS_CLASS_LAMBDA( const int i ) + setParameters( _alpha, _temp0 ); + } + + template + void setParameters( const ArrayType& _alpha, const ArrayType& _temp0 ) + { + auto alpha_copy = alpha; + auto temp0_copy = temp0; + auto init_func = KOKKOS_LAMBDA( const int i ) { - alpha( i ) = _alpha[i]; - temp0( i ) = _temp0[i]; + alpha_copy( i ) = _alpha[i]; + temp0_copy( i ) = _temp0[i]; }; using exec_space = typename memory_space::execution_space; Kokkos::RangePolicy policy( 0, alpha.size() ); diff --git a/src/force/CabanaPD_ForceModels_PMB.hpp b/src/force/CabanaPD_ForceModels_PMB.hpp index 55d189ce..dd256aeb 100644 --- a/src/force/CabanaPD_ForceModels_PMB.hpp +++ b/src/force/CabanaPD_ForceModels_PMB.hpp @@ -91,25 +91,30 @@ struct ForceModel template void setParameters( const ArrayType& _K ) { - // Initialize self interaction parameters. - auto init_self_func = KOKKOS_CLASS_LAMBDA( const int i ) + // Initialize per-type variables. + auto K_copy = K; + auto init_self_func = KOKKOS_LAMBDA( const int i ) { - K( i ) = _K[i]; - c( i, i ) = micromodulus( i ); + K_copy( i ) = _K[i]; }; using exec_space = typename memory_space::execution_space; Kokkos::RangePolicy policy( 0, num_types ); - Kokkos::parallel_for( "CabanaPD::Model::Init", policy, init_self_func ); + Kokkos::parallel_for( "CabanaPD::Model::Copy", policy, init_self_func ); Kokkos::fence(); - // Initialize cross-terms. - auto init_cross_func = KOKKOS_CLASS_LAMBDA( const int i ) + // Initialize model parameters. + Kokkos::parallel_for( "CabanaPD::Model::Init", policy, *this ); + } + + KOKKOS_INLINE_FUNCTION void operator()( const int i ) const + { + c( i, i ) = micromodulus( i ); + for ( std::size_t j = i; j < num_types; j++ ) { - for ( std::size_t j = i; j < num_types; j++ ) - c( i, j ) = ( micromodulus( i ) + micromodulus( j ) ) / 2.0; - }; - Kokkos::parallel_for( "CabanaPD::Model::Init", policy, - init_cross_func ); + c( i, j ) = ( micromodulus( i ) + micromodulus( j ) ) / 2.0; + // Set symmetric cross-terms. + c( j, i ) = c( i, j ); + } } KOKKOS_INLINE_FUNCTION @@ -217,13 +222,11 @@ struct ForceModel template void setParameters( const ArrayType& _G0 ) { - // Initialize self interaction parameters. - auto init_self_func = KOKKOS_CLASS_LAMBDA( const int i ) + // Initialize per-type variables. + auto G0_copy = G0; + auto init_self_func = KOKKOS_LAMBDA( const int i ) { - G0( i ) = _G0[i]; - s0( i, i ) = criticalStretch( i ); - bond_break_coeff( i, i ) = - ( 1.0 + s0( i, i ) ) * ( 1.0 + s0( i, i ) ); + G0_copy( i ) = _G0[i]; }; using exec_space = typename memory_space::execution_space; Kokkos::RangePolicy policy( 0, num_types ); @@ -231,17 +234,23 @@ struct ForceModel Kokkos::fence(); // Initialize cross-terms. - auto init_cross_func = KOKKOS_CLASS_LAMBDA( const int i ) + Kokkos::parallel_for( "CabanaPD::Model::Init", policy, *this ); + } + + KOKKOS_INLINE_FUNCTION void operator()( const int i ) const + { + s0( i, i ) = criticalStretch( i ); + bond_break_coeff( i, i ) = ( 1.0 + s0( i, i ) ) * ( 1.0 + s0( i, i ) ); + + for ( std::size_t j = i; j < num_types; j++ ) { - for ( std::size_t j = i; j < num_types; j++ ) - { - s0( i, j ) = criticalStretch( i, j ); - bond_break_coeff( i, j ) = - ( 1.0 + s0( i, j ) ) * ( 1.0 + s0( i, j ) ); - } - }; - Kokkos::parallel_for( "CabanaPD::Model::Init", policy, - init_cross_func ); + s0( i, j ) = criticalStretch( i, j ); + bond_break_coeff( i, j ) = + ( 1.0 + s0( i, j ) ) * ( 1.0 + s0( i, j ) ); + // Set symmetric cross-terms. + s0( j, i ) = s0( i, j ); + bond_break_coeff( j, i ) = bond_break_coeff( i, j ); + } } KOKKOS_INLINE_FUNCTION