Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
Stokhos_StaticStorage.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Stokhos Package
5 // Copyright (2009) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Eric T. Phipps (etphipp@sandia.gov).
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 #ifndef STOKHOS_STATIC_STORAGE_HPP
43 #define STOKHOS_STATIC_STORAGE_HPP
44 
46 
47 #include "Kokkos_Macros.hpp"
48 
49 #include "Sacado_Traits.hpp"
50 #include "Stokhos_KokkosTraits.hpp"
51 #include <sstream>
52 
53 namespace Stokhos {
54 
56  template <typename ordinal_t, typename value_t, int Num, typename device_t>
57  class StaticStorage {
58  public:
59 
60  static const bool is_static = false;
61  static const int static_size = 0;
62  static const bool supports_reset = false;
63 
64  typedef ordinal_t ordinal_type;
65  typedef value_t value_type;
66  typedef device_t execution_space;
68  typedef volatile value_type& volatile_reference;
69  typedef const value_type& const_reference;
70  typedef const volatile value_type& const_volatile_reference;
71  typedef value_type* pointer;
72  typedef volatile value_type* volatile_pointer;
73  typedef const value_type* const_pointer;
74  typedef const volatile value_type* const_volatile_pointer;
76 
78  template <typename ord_t, typename val_t = value_t , typename dev_t = device_t >
79  struct apply {
81  };
82 
84  KOKKOS_INLINE_FUNCTION
85  StaticStorage(const ordinal_type& sz = 1,
86  const value_type& x = value_type(0.0)) : sz_(sz) {
87  ss::fill(coeff_, sz_, x);
88  }
89 
91  KOKKOS_INLINE_FUNCTION
92  StaticStorage(const ordinal_type& sz, const value_type* x) : sz_(sz) {
93  ss::copy(x, coeff_, sz);
94  }
95 
97  KOKKOS_INLINE_FUNCTION
98  StaticStorage(const ordinal_type& sz, pointer v, bool owned) {}
99 
101  KOKKOS_INLINE_FUNCTION
103  ss::copy(s.coeff_, coeff_, sz_);
104  }
105 
107  KOKKOS_INLINE_FUNCTION
108  StaticStorage(const volatile StaticStorage& s) : sz_(s.sz_) {
109  ss::copy(s.coeff_, coeff_, sz_);
110  }
111 
113  KOKKOS_INLINE_FUNCTION
115 
117  KOKKOS_INLINE_FUNCTION
119  sz_ = s.sz_;
120  ss::copy(s.coeff_, coeff_, sz_);
121  return *this;
122  }
123 
125  KOKKOS_INLINE_FUNCTION
126  StaticStorage& operator=(const volatile StaticStorage& s) {
127  sz_ = s.sz_;
128  ss::copy(s.coeff_, coeff_, sz_);
129  return *this;
130  }
131 
133  KOKKOS_INLINE_FUNCTION
134  volatile StaticStorage& operator=(const StaticStorage& s) volatile {
135  sz_ = s.sz_;
136  ss::copy(s.coeff_, coeff_, sz_);
137  return *this;
138  }
139 
141  KOKKOS_INLINE_FUNCTION
142  volatile StaticStorage& operator=(const volatile StaticStorage& s) volatile {
143  sz_ = s.sz_;
144  ss::copy(s.coeff_, coeff_, sz_);
145  return *this;
146  }
147 
149  KOKKOS_INLINE_FUNCTION
151  ss::fill(coeff_, sz_, v);
152  }
153 
155  KOKKOS_INLINE_FUNCTION
156  void init(const_reference v) volatile {
157  ss::fill(coeff_, sz_, v);
158  }
159 
161  KOKKOS_INLINE_FUNCTION
162  void init(const_pointer v, const ordinal_type& sz = 0) {
163  if (sz == 0)
164  ss::copy(v, coeff_, sz_);
165  else
166  ss::copy(v, coeff_, sz);
167  }
168 
170  KOKKOS_INLINE_FUNCTION
171  void init(const_pointer v, const ordinal_type& sz = 0) volatile {
172  if (sz == 0)
173  ss::copy(v, coeff_, sz_);
174  else
175  ss::copy(v, coeff_, sz);
176  }
177 
179  KOKKOS_INLINE_FUNCTION
180  void load(pointer v) {
181  ss::copy(v, coeff_, sz_);
182  }
183 
185  KOKKOS_INLINE_FUNCTION
186  void load(pointer v) volatile {
187  ss::copy(v, coeff_, sz_);
188  }
189 
191  KOKKOS_INLINE_FUNCTION
192  void resize(const ordinal_type& sz) {
193  if (sz > sz_)
194  ss::fill(coeff_+sz_, sz-sz_, value_type(0.0));
195  sz_ = sz;
196  }
197 
199  KOKKOS_INLINE_FUNCTION
200  void resize(const ordinal_type& sz) volatile {
201  if (sz > sz_)
202  ss::fill(coeff_+sz_, sz-sz_, value_type(0.0));
203  sz_ = sz;
204  }
205 
207  KOKKOS_INLINE_FUNCTION
208  void shallowReset(pointer v, const ordinal_type& sz,
209  const ordinal_type& stride, bool owned) {}
210 
212  KOKKOS_INLINE_FUNCTION
213  void shallowReset(pointer v, const ordinal_type& sz,
214  const ordinal_type& stride, bool owned) volatile {}
215 
217  KOKKOS_INLINE_FUNCTION
218  ordinal_type size() const { return sz_; }
219 
221  KOKKOS_INLINE_FUNCTION
222  ordinal_type size() const volatile { return sz_; }
223 
225  KOKKOS_INLINE_FUNCTION
227  return coeff_[i];
228  }
229 
231  KOKKOS_INLINE_FUNCTION
233  return coeff_[i];
234  }
235 
237  KOKKOS_INLINE_FUNCTION
238  reference operator[] (const ordinal_type& i) { return coeff_[i]; }
239 
241  KOKKOS_INLINE_FUNCTION
243  return coeff_[i];
244  }
245 
246  template <int i>
247  KOKKOS_INLINE_FUNCTION
248  reference getCoeff() { return coeff_[i]; }
249 
250  template <int i>
251  KOKKOS_INLINE_FUNCTION
252  volatile_reference getCoeff() volatile { return coeff_[i]; }
253 
254  template <int i>
255  KOKKOS_INLINE_FUNCTION
256  const_volatile_reference getCoeff() const volatile { return coeff_[i]; }
257 
258  template <int i>
259  KOKKOS_INLINE_FUNCTION
260  const_reference getCoeff() const { return coeff_[i]; }
261 
263  KOKKOS_INLINE_FUNCTION
264  const_volatile_pointer coeff() const volatile { return coeff_; }
265 
267  KOKKOS_INLINE_FUNCTION
268  const_pointer coeff() const { return coeff_; }
269 
271  KOKKOS_INLINE_FUNCTION
272  volatile_pointer coeff() volatile { return coeff_; }
273 
275  KOKKOS_INLINE_FUNCTION
276  pointer coeff() { return coeff_; }
277 
278  private:
279 
282 
285 
286  };
287 
288 }
289 
290 namespace Sacado {
291  template <typename ordinal_t, typename value_t, int Num, typename device_t>
292  struct StringName< Stokhos::StaticStorage<ordinal_t,
293  value_t,
294  Num,
295  device_t> > {
296  static std::string eval() {
297  std::stringstream ss;
298  ss << "Stokhos::StaticStorage<"
299  << StringName<ordinal_t>::eval() << ","
300  << StringName<value_t>::eval() << ","
301  << Num << ","
302  << StringName<device_t>::eval() << ">";
303  return ss.str();
304  }
305  };
306 }
307 
308 #endif // STOKHOS_STATIC_STORAGE_HPP
Stokhos::StaticStorage::supports_reset
static const bool supports_reset
Definition: Stokhos_StaticStorage.hpp:62
Stokhos::StaticStorage::StaticStorage
KOKKOS_INLINE_FUNCTION StaticStorage(const StaticStorage &s)
Copy constructor.
Definition: Stokhos_StaticStorage.hpp:102
Stokhos::StaticStorage::StaticStorage
KOKKOS_INLINE_FUNCTION StaticStorage(const ordinal_type &sz=1, const value_type &x=value_type(0.0))
Constructor.
Definition: Stokhos_StaticStorage.hpp:85
Stokhos::StaticStorage::operator=
KOKKOS_INLINE_FUNCTION StaticStorage & operator=(const StaticStorage &s)
Assignment operator.
Definition: Stokhos_StaticStorage.hpp:118
Stokhos::StaticStorage::StaticStorage
KOKKOS_INLINE_FUNCTION StaticStorage(const ordinal_type &sz, const value_type *x)
Constructor from array.
Definition: Stokhos_StaticStorage.hpp:92
Stokhos::StaticStorage::sz_
ordinal_type sz_
Size of array used.
Definition: Stokhos_StaticStorage.hpp:284
Stokhos::StaticStorage::getCoeff
KOKKOS_INLINE_FUNCTION const_reference getCoeff() const
Definition: Stokhos_StaticStorage.hpp:260
Stokhos::StaticStorage::value_type
value_t value_type
Definition: Stokhos_StaticStorage.hpp:65
Stokhos::StaticStorage::load
KOKKOS_INLINE_FUNCTION void load(pointer v)
Load values to an array of values.
Definition: Stokhos_StaticStorage.hpp:180
Stokhos::StaticStorage::operator=
KOKKOS_INLINE_FUNCTION volatile StaticStorage & operator=(const StaticStorage &s) volatile
Assignment operator.
Definition: Stokhos_StaticStorage.hpp:134
Stokhos::StaticStorage::const_volatile_reference
const typedef volatile value_type & const_volatile_reference
Definition: Stokhos_StaticStorage.hpp:70
Stokhos::StaticStorage::ordinal_type
ordinal_t ordinal_type
Definition: Stokhos_StaticStorage.hpp:64
Stokhos::StaticStorage::StaticStorage
KOKKOS_INLINE_FUNCTION StaticStorage(const volatile StaticStorage &s)
Copy constructor.
Definition: Stokhos_StaticStorage.hpp:108
Stokhos::StaticStorage::resize
KOKKOS_INLINE_FUNCTION void resize(const ordinal_type &sz)
Resize to new size (values are preserved)
Definition: Stokhos_StaticStorage.hpp:192
Stokhos::StaticStorage::execution_space
device_t execution_space
Definition: Stokhos_StaticStorage.hpp:66
Stokhos::StaticStorage::operator=
KOKKOS_INLINE_FUNCTION StaticStorage & operator=(const volatile StaticStorage &s)
Assignment operator.
Definition: Stokhos_StaticStorage.hpp:126
Stokhos::StaticStorage::shallowReset
KOKKOS_INLINE_FUNCTION void shallowReset(pointer v, const ordinal_type &sz, const ordinal_type &stride, bool owned)
Reset storage to given array, size, and stride.
Definition: Stokhos_StaticStorage.hpp:208
Stokhos::StaticStorage::volatile_reference
volatile value_type & volatile_reference
Definition: Stokhos_StaticStorage.hpp:68
Stokhos::StaticStorage::getCoeff
KOKKOS_INLINE_FUNCTION const_volatile_reference getCoeff() const volatile
Definition: Stokhos_StaticStorage.hpp:256
Stokhos::StaticStorage::volatile_pointer
volatile value_type * volatile_pointer
Definition: Stokhos_StaticStorage.hpp:72
Stokhos::StaticStorage::coeff
KOKKOS_INLINE_FUNCTION const_volatile_pointer coeff() const volatile
Get coefficients.
Definition: Stokhos_StaticStorage.hpp:264
Stokhos::StaticStorage::ss
Stokhos::StaticArrayTraits< value_type, execution_space > ss
Definition: Stokhos_StaticStorage.hpp:75
Stokhos::StaticStorage::apply::type
StaticStorage< ord_t, val_t, Num, dev_t > type
Definition: Stokhos_StaticStorage.hpp:80
Stokhos::StaticStorage::size
KOKKOS_INLINE_FUNCTION ordinal_type size() const volatile
Return size.
Definition: Stokhos_StaticStorage.hpp:222
Stokhos::StaticStorage::operator[]
KOKKOS_INLINE_FUNCTION const_reference operator[](const ordinal_type &i) const
Coefficient access (avoid if possible)
Definition: Stokhos_StaticStorage.hpp:226
Stokhos::StaticStorage::reference
value_type & reference
Definition: Stokhos_StaticStorage.hpp:67
Stokhos::StaticStorage::operator=
KOKKOS_INLINE_FUNCTION volatile StaticStorage & operator=(const volatile StaticStorage &s) volatile
Assignment operator.
Definition: Stokhos_StaticStorage.hpp:142
Sacado
Definition: Kokkos_View_UQ_PCE_Utils.hpp:48
Stokhos::StaticStorage::getCoeff
KOKKOS_INLINE_FUNCTION reference getCoeff()
Definition: Stokhos_StaticStorage.hpp:248
Stokhos
Top-level namespace for Stokhos classes and functions.
Definition: Stokhos_AbstractPreconditionerFactory.hpp:48
Stokhos::StaticStorage::pointer
value_type * pointer
Definition: Stokhos_StaticStorage.hpp:71
Stokhos::StaticStorage::StaticStorage
KOKKOS_INLINE_FUNCTION StaticStorage(const ordinal_type &sz, pointer v, bool owned)
Constructor for creating a view (not allowed)
Definition: Stokhos_StaticStorage.hpp:98
Stokhos::StaticStorage::coeff
KOKKOS_INLINE_FUNCTION volatile_pointer coeff() volatile
Get coefficients.
Definition: Stokhos_StaticStorage.hpp:272
Stokhos::StaticStorage::const_pointer
const typedef value_type * const_pointer
Definition: Stokhos_StaticStorage.hpp:73
KokkosBlas::fill
std::enable_if< Kokkos::is_view_uq_pce< Kokkos::View< XD, XP... > >::value >::type fill(const Kokkos::View< XD, XP... > &x, const typename Kokkos::View< XD, XP... >::non_const_value_type &val)
Definition: Kokkos_Blas1_UQ_PCE.hpp:98
Stokhos::StaticStorage::~StaticStorage
KOKKOS_INLINE_FUNCTION ~StaticStorage()
Destructor.
Definition: Stokhos_StaticStorage.hpp:114
Stokhos::StaticStorage::load
KOKKOS_INLINE_FUNCTION void load(pointer v) volatile
Load values to an array of values.
Definition: Stokhos_StaticStorage.hpp:186
Stokhos_KokkosTraits.hpp
Stokhos::StaticStorage::init
KOKKOS_INLINE_FUNCTION void init(const_reference v) volatile
Initialize values to a constant value.
Definition: Stokhos_StaticStorage.hpp:156
Stokhos::StaticStorage::const_volatile_pointer
const typedef volatile value_type * const_volatile_pointer
Definition: Stokhos_StaticStorage.hpp:74
Stokhos::StaticStorage::coeff
KOKKOS_INLINE_FUNCTION pointer coeff()
Get coefficients.
Definition: Stokhos_StaticStorage.hpp:276
Stokhos::StaticStorage::coeff
KOKKOS_INLINE_FUNCTION const_pointer coeff() const
Get coefficients.
Definition: Stokhos_StaticStorage.hpp:268
cusp::detail::device::x
const IndexType const IndexType const IndexType const IndexType const ValueType const ValueType * x
Definition: csr_vector.h:260
Stokhos::StaticStorage::shallowReset
KOKKOS_INLINE_FUNCTION void shallowReset(pointer v, const ordinal_type &sz, const ordinal_type &stride, bool owned) volatile
Reset storage to given array, size, and stride.
Definition: Stokhos_StaticStorage.hpp:213
Stokhos::StaticStorage::static_size
static const int static_size
Definition: Stokhos_StaticStorage.hpp:61
Stokhos::StaticStorage
Statically allocated storage class.
Definition: Stokhos_StaticStorage.hpp:57
Stokhos_StaticArrayTraits.hpp
Stokhos::StaticStorage::init
KOKKOS_INLINE_FUNCTION void init(const_pointer v, const ordinal_type &sz=0) volatile
Initialize values to an array of values.
Definition: Stokhos_StaticStorage.hpp:171
Stokhos::StaticStorage::resize
KOKKOS_INLINE_FUNCTION void resize(const ordinal_type &sz) volatile
Resize to new size (values are preserved)
Definition: Stokhos_StaticStorage.hpp:200
Stokhos::StaticStorage::const_reference
const typedef value_type & const_reference
Definition: Stokhos_StaticStorage.hpp:69
Stokhos::StaticStorage::getCoeff
KOKKOS_INLINE_FUNCTION volatile_reference getCoeff() volatile
Definition: Stokhos_StaticStorage.hpp:252
Sacado::StringName< Stokhos::StaticStorage< ordinal_t, value_t, Num, device_t > >::eval
static std::string eval()
Definition: Stokhos_StaticStorage.hpp:296
Stokhos::StaticArrayTraits
Static array allocation class.
Definition: Stokhos_StaticArrayTraits.hpp:60
Stokhos::StaticStorage::coeff_
value_type coeff_[Num]
Coefficient values.
Definition: Stokhos_StaticStorage.hpp:281
Stokhos::StaticStorage::init
KOKKOS_INLINE_FUNCTION void init(const_pointer v, const ordinal_type &sz=0)
Initialize values to an array of values.
Definition: Stokhos_StaticStorage.hpp:162
Stokhos::StaticStorage::init
KOKKOS_INLINE_FUNCTION void init(const_reference v)
Initialize values to a constant value.
Definition: Stokhos_StaticStorage.hpp:150
Stokhos::StaticStorage::apply
Turn StaticStorage into a meta-function class usable with mpl::apply.
Definition: Stokhos_StaticStorage.hpp:79
Stokhos::StaticStorage::is_static
static const bool is_static
Definition: Stokhos_StaticStorage.hpp:60
Stokhos::StaticStorage::size
KOKKOS_INLINE_FUNCTION ordinal_type size() const
Return size.
Definition: Stokhos_StaticStorage.hpp:218