// @HEADER // ***************************************************************************** // Stokhos Package // // Copyright 2009 NTESS and the Stokhos contributors. // SPDX-License-Identifier: BSD-3-Clause // ***************************************************************************** // @HEADER #ifndef STOKHOS_DYNAMIC_STRIDED_STORAGE_HPP #define STOKHOS_DYNAMIC_STRIDED_STORAGE_HPP #include "Stokhos_DynArrayTraits.hpp" #include "Kokkos_Macros.hpp" #include "Sacado_Traits.hpp" #include "Stokhos_KokkosTraits.hpp" #include namespace Stokhos { template class DynamicStridedStorage { public: static const bool is_static = false; static const int static_size = 0; static const bool supports_reset = true; typedef ordinal_t ordinal_type; typedef value_t value_type; typedef device_t execution_space; typedef value_type& reference; typedef volatile value_type& volatile_reference; typedef const value_type& const_reference; typedef const volatile value_type& const_volatile_reference; typedef value_type* pointer; typedef volatile value_type* volatile_pointer; typedef const value_type* const_pointer; typedef const volatile value_type* const_volatile_pointer; typedef Stokhos::DynArrayTraits ds; //! Turn DynamicStridedStorage into a meta-function class usable with mpl::apply template struct apply { typedef DynamicStridedStorage type; }; //! Constructor KOKKOS_INLINE_FUNCTION DynamicStridedStorage(const ordinal_type& sz = 1, const value_type& x = value_type(0.0)) : sz_(sz), stride_(1), is_owned_(true) { coeff_ = ds::get_and_fill(sz_, x); } //! Constructor from array KOKKOS_INLINE_FUNCTION DynamicStridedStorage(const ordinal_type& sz, const value_type* x) : sz_(sz), stride_(1), is_owned_(true) { coeff_ = ds::get_and_fill(x, sz_); } //! Constructor for creating a view KOKKOS_INLINE_FUNCTION DynamicStridedStorage(const ordinal_type& sz, pointer v, bool owned) : coeff_(v), sz_(sz), stride_(1), is_owned_(owned) {} //! Constructor KOKKOS_INLINE_FUNCTION DynamicStridedStorage(const DynamicStridedStorage& s) : sz_(s.sz_), stride_(1), is_owned_(true) { if (s.stride_ == 1) coeff_ = ds::get_and_fill(s.coeff_, sz_); else { coeff_ = ds::get_and_fill(sz_); for (ordinal_type i=0; i sz) my_sz = sz; if (stride_ == 1) ds::copy(coeff_, coeff_new, my_sz); else for (ordinal_type i=0; i sz) my_sz = sz; if (stride_ == 1) ds::copy(coeff_, coeff_new, my_sz); else for (ordinal_type i=0; i KOKKOS_INLINE_FUNCTION reference getCoeff() { return coeff_[i*stride_]; } template KOKKOS_INLINE_FUNCTION volatile_reference getCoeff() volatile { return coeff_[i*stride_]; } template KOKKOS_INLINE_FUNCTION const_reference getCoeff() const { return coeff_[i*stride_]; } template KOKKOS_INLINE_FUNCTION const_volatile_reference getCoeff() const volatile { return coeff_[i*stride_]; } //! Get coefficients KOKKOS_INLINE_FUNCTION const_volatile_pointer coeff() const volatile { return coeff_; } //! Get coefficients KOKKOS_INLINE_FUNCTION const_pointer coeff() const { return coeff_; } //! Get coefficients KOKKOS_INLINE_FUNCTION volatile_pointer coeff() volatile { return coeff_; } //! Get coefficients KOKKOS_INLINE_FUNCTION pointer coeff() { return coeff_; } private: //! Coefficient values pointer coeff_; //! Size of array used ordinal_type sz_; //! Stride of array ordinal_type stride_; //! Do we own the array bool is_owned_; }; } #include "Stokhos_StorageHelpers.hpp" STOKHOS_STORAGE_HELPER_STRINGNAME_DYNAMIC(DynamicStridedStorage) #endif // STOKHOS_DYNAMIC_STORAGE_HPP