Sacado Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Sacado_StaticArrayTraits.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Sacado Package
5 // Copyright (2006) Sandia Corporation
6 //
7 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8 // the U.S. Government retains certain rights in this software.
9 //
10 // This library is free software; you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as
12 // published by the Free Software Foundation; either version 2.1 of the
13 // License, or (at your option) any later version.
14 //
15 // This library is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
23 // USA
24 // Questions? Contact David M. Gay (dmgay@sandia.gov) or Eric T. Phipps
25 // (etphipp@sandia.gov).
26 //
27 // ***********************************************************************
28 // @HEADER
29 
30 #ifndef SACADO_STATICARRAYTRAITS_HPP
31 #define SACADO_STATICARRAYTRAITS_HPP
32 
33 #include <cstring>
34 
35 #include "Sacado_Traits.hpp"
36 
37 namespace Sacado {
38 
42  template <typename T, bool isScalar = IsScalarType<T>::value>
43  struct ss_array {
44 
47  static void copy(const T* src, T* dest, int sz) {
48  for (int i=0; i<sz; ++i)
49  *(dest++) = *(src++);
50  }
51 
54  static void zero(T* dest, int sz) {
55  for (int i=0; i<sz; ++i)
56  *(dest++) = T(0.);
57  }
58  };
59 
64  template <typename T>
65  struct ss_array<T,true> {
66 
69  static void copy(const T* src, T* dest, int sz) {
70  if (sz > 0)
71 #ifdef __CUDACC__
72  for (int i=0; i<sz; ++i)
73  dest[i] = src[i];
74 #else
75  std::memcpy(dest,src,sz*sizeof(T));
76 #endif
77  }
78 
81  static void zero(T* dest, int sz) {
82  if (sz > 0)
83 #ifdef __CUDACC__
84  for (int i=0; i<sz; ++i)
85  dest[i] = T(0.);
86 #else
87  std::memset(dest,0,sz*sizeof(T));
88 #endif
89  }
90 
91  };
92 
93 } // namespace Sacado
94 
95 #endif // SACAD0_STATICARRAYTRAITS_HPP
static KOKKOS_INLINE_FUNCTION void copy(const T *src, T *dest, int sz)
Copy array from src to dest of length sz.
static KOKKOS_INLINE_FUNCTION void zero(T *dest, int sz)
Zero out array dest of length sz.
expr true
static KOKKOS_INLINE_FUNCTION void zero(T *dest, int sz)
Zero out array dest of length sz.
#define KOKKOS_INLINE_FUNCTION
#define T
Definition: Sacado_rad.hpp:573
static KOKKOS_INLINE_FUNCTION void copy(const T *src, T *dest, int sz)
Copy array from src to dest of length sz.
Static array allocation class that works for any type.