42 #ifndef SACADO_MP_VECTOR_HPP
43 #define SACADO_MP_VECTOR_HPP
47 #ifdef HAVE_STOKHOS_SACADO
50 #include <initializer_list>
52 #include "Kokkos_Macros.hpp"
56 #include "Sacado_Traits.hpp"
57 #include "Sacado_mpl_apply.hpp"
58 #include "Sacado_mpl_range_c.hpp"
93 typedef T derived_type;
100 KOKKOS_INLINE_FUNCTION
101 const derived_type& derived()
const {
102 return static_cast<const derived_type&
>(*this);
110 KOKKOS_INLINE_FUNCTION
111 const volatile derived_type& derived()
const volatile {
112 return static_cast<const volatile derived_type&
>(*this);
118 template <
typename Storage>
119 class Vector :
public Expr< Vector<Storage> > {
129 typedef typename storage_type::volatile_pointer volatile_pointer;
131 typedef typename storage_type::const_volatile_pointer const_volatile_pointer;
133 typedef typename storage_type::volatile_reference volatile_reference;
135 typedef typename storage_type::const_volatile_reference const_volatile_reference;
137 typedef typename execution_space::memory_space memory_space;
141 typedef typename ScalarType<value_type>::type
scalar_type;
143 typedef Vector base_expr_type;
146 template <
class NewStorageType >
148 typedef Vector< NewStorageType > type;
152 static const int num_args = 1;
154 #if STOKHOS_ALIGN_MEMORY
155 KOKKOS_INLINE_FUNCTION
156 static void*
operator new(std::size_t sz) {
157 return MemTraits::alloc(sz);
159 KOKKOS_INLINE_FUNCTION
160 static void*
operator new[](std::size_t sz) {
161 return MemTraits::alloc(sz);
163 KOKKOS_INLINE_FUNCTION
164 static void*
operator new(std::size_t sz,
void* ptr) {
167 KOKKOS_INLINE_FUNCTION
168 static void*
operator new[](std::size_t sz,
void* ptr) {
171 KOKKOS_INLINE_FUNCTION
172 static void operator delete(
void* ptr) {
173 MemTraits::free(ptr);
175 KOKKOS_INLINE_FUNCTION
176 static void operator delete[](
void* ptr) {
177 MemTraits::free(ptr);
179 KOKKOS_INLINE_FUNCTION
180 static void operator delete(
void* ptr,
void*) {
181 MemTraits::free(ptr);
183 KOKKOS_INLINE_FUNCTION
184 static void operator delete[](
void* ptr,
void*) {
185 MemTraits::free(ptr);
193 KOKKOS_INLINE_FUNCTION
200 KOKKOS_INLINE_FUNCTION
208 KOKKOS_INLINE_FUNCTION
209 Vector(
ordinal_type sz, pointer v,
bool owned) : s(sz,v,owned) {}
215 KOKKOS_INLINE_FUNCTION
219 KOKKOS_INLINE_FUNCTION
223 KOKKOS_INLINE_FUNCTION
224 Vector(
const Vector& x) =
default;
227 KOKKOS_INLINE_FUNCTION
228 Vector(
const volatile Vector& x) : s(x.s) {}
231 template <
typename S>
232 KOKKOS_INLINE_FUNCTION
233 Vector(
const Expr<S>& xx) :
234 s(xx.derived().size()) {
235 typedef typename Expr<S>::derived_type expr_type;
236 const expr_type& x = xx.derived();
239 if (s.size() != x.size())
243 if (x.hasFastAccess(s.size())) {
244 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
247 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
248 #pragma vector aligned
250 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
254 s[i] = x.fastAccessCoeff(i);
266 Vector(std::initializer_list<value_type> l) : s(l.size(), l.begin()) {}
269 KOKKOS_INLINE_FUNCTION
273 KOKKOS_INLINE_FUNCTION
277 KOKKOS_INLINE_FUNCTION
278 void init(
const value_type& v)
volatile { s.init(v); }
281 KOKKOS_INLINE_FUNCTION
285 KOKKOS_INLINE_FUNCTION
286 void init(
const value_type* v)
volatile { s.init(v); }
289 template <
typename S>
290 KOKKOS_INLINE_FUNCTION
291 void init(
const Vector<S>& v) {
292 s.init(v.s.coeff(), v.s.size());
296 template <
typename S>
297 KOKKOS_INLINE_FUNCTION
298 void init(
const Vector<S>& v)
volatile {
299 s.init(v.s.coeff(), v.s.size());
303 KOKKOS_INLINE_FUNCTION
307 KOKKOS_INLINE_FUNCTION
308 void load(
value_type* v)
volatile { s.load(v); }
311 template <
typename S>
312 KOKKOS_INLINE_FUNCTION
313 void load(Vector<S>& v) { s.load(v.s.coeff()); }
316 template <
typename S>
317 KOKKOS_INLINE_FUNCTION
318 void load(Vector<S>& v)
volatile { s.load(v.s.coeff()); }
324 KOKKOS_INLINE_FUNCTION
328 if (sz == 1 && sz_new > sz)
337 KOKKOS_INLINE_FUNCTION
341 if (sz == 1 && sz_new > sz)
356 KOKKOS_INLINE_FUNCTION
357 void copyForWrite()
volatile { }
360 template <
typename S>
361 KOKKOS_INLINE_FUNCTION
362 bool isEqualTo(
const Expr<S>& xx)
const {
363 const typename Expr<S>::derived_type& x = xx.derived();
364 typedef IsEqual<value_type> IE;
365 if (x.size() != this->size())
return false;
368 eq = eq && IE::eval(x.coeff(i), this->coeff(i));
373 template <
typename S>
374 KOKKOS_INLINE_FUNCTION
375 bool isEqualTo(
const Expr<S>& xx)
const volatile {
376 const typename Expr<S>::derived_type& x = xx.derived();
377 typedef IsEqual<value_type> IE;
378 if (x.size() != this->size())
return false;
381 eq = eq && IE::eval(x.coeff(i), this->coeff(i));
394 Vector& operator=(std::initializer_list<value_type> l) {
398 s.init(l.begin(), lsz);
407 operator=(std::initializer_list<value_type> l)
volatile {
411 s.init(l.begin(), lsz);
412 return const_cast<Vector&
>(*this);
416 KOKKOS_INLINE_FUNCTION
423 KOKKOS_INLINE_FUNCTION
424 Vector& operator=(
const value_type& x)
volatile {
426 return const_cast<Vector&
>(*this);
430 KOKKOS_INLINE_FUNCTION
431 Vector& operator=(
const Vector& x) {
445 if (s.size() > x.s.size())
454 KOKKOS_INLINE_FUNCTION
455 Vector& operator=(
const volatile Vector& x) {
469 if (s.size() > x.s.size())
478 KOKKOS_INLINE_FUNCTION
479 Vector& operator=(
const Vector& x)
volatile {
493 if (s.size() > x.s.size())
498 return const_cast<Vector&
>(*this);
502 KOKKOS_INLINE_FUNCTION
503 Vector& operator=(
const volatile Vector& x)
volatile {
517 if (s.size() > x.s.size())
522 return const_cast<Vector&
>(*this);
526 template <
typename S>
527 KOKKOS_INLINE_FUNCTION
528 Vector& operator=(
const Expr<S>& xx) {
529 typedef typename Expr<S>::derived_type expr_type;
530 const expr_type& x = xx.derived();
532 this->reset(x.size());
535 if (s.size() != x.size())
539 if (x.hasFastAccess(s.size())) {
540 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
543 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
544 #pragma vector aligned
546 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
550 s[i] = x.fastAccessCoeff(i);
560 template <
typename S>
561 KOKKOS_INLINE_FUNCTION
562 Vector& operator=(
const Expr<S>& xx)
volatile {
563 typedef typename Expr<S>::derived_type expr_type;
564 const expr_type& x = xx.derived();
566 this->reset(x.size());
569 if (s.size() != x.size())
573 if (x.hasFastAccess(s.size())) {
574 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
577 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
578 #pragma vector aligned
580 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
584 s[i] = x.fastAccessCoeff(i);
590 return const_cast<Vector&
>(*this);
594 template<
typename S >
595 KOKKOS_INLINE_FUNCTION
596 typename Kokkos::Impl::enable_if<( ! Kokkos::Impl::is_same<S,void>::value &&
599 ::type
const &
operator = (
const Expr<S> & xx )
const
601 const typename Expr<S>::derived_type & x = xx.derived();
603 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
606 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
607 #pragma vector aligned
609 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
612 for (
ordinal_type i = 0 ; i < s.size() ; ++i ) { s[i] = x.coeff(i); }
618 template<
typename S >
619 KOKKOS_INLINE_FUNCTION
621 typename Kokkos::Impl::enable_if<( ! Kokkos::Impl::is_same<S,void>::value &&
624 ::type
const &
operator = (
const Expr<S> & xx )
const volatile
626 const typename Expr<S>::derived_type & x = xx.derived();
628 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
631 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
632 #pragma vector aligned
634 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
637 for (
ordinal_type i = 0 ; i < s.size() ; ++i ) { s[i] = x.coeff(i); }
648 KOKKOS_INLINE_FUNCTION
650 const volatile storage_type& storage()
const volatile {
return s; }
653 KOKKOS_INLINE_FUNCTION
657 KOKKOS_INLINE_FUNCTION
661 KOKKOS_INLINE_FUNCTION
670 KOKKOS_INLINE_FUNCTION
671 const_volatile_reference
val()
const volatile {
return s[0]; }
674 KOKKOS_INLINE_FUNCTION
675 const_reference
val()
const {
return s[0]; }
678 KOKKOS_INLINE_FUNCTION
679 volatile_reference
val()
volatile {
return s[0]; }
682 KOKKOS_INLINE_FUNCTION
683 reference
val() {
return s[0]; }
693 KOKKOS_INLINE_FUNCTION
697 KOKKOS_INLINE_FUNCTION
701 KOKKOS_INLINE_FUNCTION
702 bool hasFastAccess(
ordinal_type sz)
const {
return s.size()>=sz;}
705 KOKKOS_INLINE_FUNCTION
706 bool hasFastAccess(
ordinal_type sz)
const volatile {
return s.size()>=sz;}
709 KOKKOS_INLINE_FUNCTION
710 const_pointer coeff()
const {
return s.coeff();}
713 KOKKOS_INLINE_FUNCTION
714 const_volatile_pointer coeff()
const volatile {
return s.coeff();}
717 KOKKOS_INLINE_FUNCTION
718 volatile_pointer coeff()
volatile {
return s.coeff();}
721 KOKKOS_INLINE_FUNCTION
722 pointer coeff() {
return s.coeff();}
725 KOKKOS_INLINE_FUNCTION
727 return i<s.size() ? s[i] : s[0]; }
730 KOKKOS_INLINE_FUNCTION
732 return i<s.size() ? s[i] : s[0]; }
735 KOKKOS_INLINE_FUNCTION
737 return i<s.size() ? s[i] : s[0]; }
740 KOKKOS_INLINE_FUNCTION
742 return i<s.size() ? s[i] : s[0]; }
745 KOKKOS_INLINE_FUNCTION
750 KOKKOS_INLINE_FUNCTION
755 KOKKOS_INLINE_FUNCTION
760 KOKKOS_INLINE_FUNCTION
765 KOKKOS_INLINE_FUNCTION
766 const_volatile_reference operator[](
ordinal_type i)
const volatile {
770 KOKKOS_INLINE_FUNCTION
775 KOKKOS_INLINE_FUNCTION
776 volatile_reference operator[](
ordinal_type i)
volatile {
780 KOKKOS_INLINE_FUNCTION
785 KOKKOS_INLINE_FUNCTION
787 return s.template getCoeff<i>(); }
790 KOKKOS_INLINE_FUNCTION
792 return s.template getCoeff<i>(); }
795 KOKKOS_INLINE_FUNCTION
796 volatile_reference getCoeff()
volatile {
797 return s.template getCoeff<i>(); }
800 KOKKOS_INLINE_FUNCTION
801 reference getCoeff() {
802 return s.template getCoeff<i>(); }
805 KOKKOS_INLINE_FUNCTION
806 pointer begin() {
return s.coeff(); }
809 KOKKOS_INLINE_FUNCTION
810 const_pointer begin()
const {
return s.coeff(); }
813 KOKKOS_INLINE_FUNCTION
814 volatile_pointer begin()
volatile {
return s.coeff(); }
817 KOKKOS_INLINE_FUNCTION
818 const_volatile_pointer begin()
const volatile {
return s.coeff(); }
821 KOKKOS_INLINE_FUNCTION
822 const_pointer cbegin()
const {
return s.coeff(); }
825 KOKKOS_INLINE_FUNCTION
826 const_volatile_pointer cbegin()
const volatile {
return s.coeff(); }
829 KOKKOS_INLINE_FUNCTION
830 pointer end() {
return s.coeff() + s.size(); }
833 KOKKOS_INLINE_FUNCTION
834 const_pointer end()
const {
return s.coeff() + s.size(); }
837 KOKKOS_INLINE_FUNCTION
838 volatile_pointer end()
volatile {
return s.coeff() + s.size(); }
841 KOKKOS_INLINE_FUNCTION
842 const_volatile_pointer end()
const volatile {
return s.coeff() + s.size(); }
845 KOKKOS_INLINE_FUNCTION
846 const_pointer cend()
const {
return s.coeff()+ s.size(); }
849 KOKKOS_INLINE_FUNCTION
850 const_volatile_pointer cend()
const volatile {
return s.coeff()+ s.size(); }
860 KOKKOS_INLINE_FUNCTION
862 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
865 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
866 #pragma vector aligned
868 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
877 KOKKOS_INLINE_FUNCTION
878 Vector& operator += (
const volatile value_type& x) {
879 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
882 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
883 #pragma vector aligned
885 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
894 KOKKOS_INLINE_FUNCTION
895 Vector& operator += (
const value_type& x)
volatile {
896 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
899 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
900 #pragma vector aligned
902 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
907 return const_cast<Vector&
>(*this);
911 KOKKOS_INLINE_FUNCTION
912 Vector& operator += (
const volatile value_type& x)
volatile {
913 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
916 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
917 #pragma vector aligned
919 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
924 return const_cast<Vector&
>(*this);
928 KOKKOS_INLINE_FUNCTION
930 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
933 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
934 #pragma vector aligned
936 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
945 KOKKOS_INLINE_FUNCTION
946 Vector& operator -= (
const volatile value_type& x) {
947 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
950 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
951 #pragma vector aligned
953 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
962 KOKKOS_INLINE_FUNCTION
963 Vector& operator -= (
const value_type& x)
volatile {
964 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
967 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
968 #pragma vector aligned
970 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
975 return const_cast<Vector&
>(*this);
979 KOKKOS_INLINE_FUNCTION
980 Vector& operator -= (
const volatile value_type& x)
volatile {
981 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
984 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
985 #pragma vector aligned
987 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
992 return const_cast<Vector&
>(*this);
996 KOKKOS_INLINE_FUNCTION
998 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1001 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1002 #pragma vector aligned
1004 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1013 KOKKOS_INLINE_FUNCTION
1014 Vector& operator *= (
const volatile value_type& x) {
1015 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1018 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1019 #pragma vector aligned
1021 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1030 KOKKOS_INLINE_FUNCTION
1031 Vector& operator *= (
const value_type& x)
volatile {
1032 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1035 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1036 #pragma vector aligned
1038 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1043 return const_cast<Vector&
>(*this);
1047 KOKKOS_INLINE_FUNCTION
1048 Vector& operator *= (
const volatile value_type& x)
volatile {
1049 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1052 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1053 #pragma vector aligned
1055 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1060 return const_cast<Vector&
>(*this);
1064 KOKKOS_INLINE_FUNCTION
1066 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1069 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1070 #pragma vector aligned
1072 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1081 KOKKOS_INLINE_FUNCTION
1082 Vector& operator /= (
const volatile value_type& x) {
1083 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1086 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1087 #pragma vector aligned
1089 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1098 KOKKOS_INLINE_FUNCTION
1099 Vector& operator /= (
const value_type& x)
volatile {
1100 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1103 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1104 #pragma vector aligned
1106 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1111 return const_cast<Vector&
>(*this);
1115 KOKKOS_INLINE_FUNCTION
1116 Vector& operator /= (
const volatile value_type& x)
volatile {
1117 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1120 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1121 #pragma vector aligned
1123 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1128 return const_cast<Vector&
>(*this);
1132 template <
typename S>
1133 KOKKOS_INLINE_FUNCTION
1134 Vector& operator += (
const Expr<S>& xx) {
1136 typedef typename Expr<S>::derived_type expr_type;
1137 const expr_type& x = xx.derived();
1139 if (x.size() > s.size())
1140 this->reset(x.size());
1142 #ifdef STOKHOS_DEBUG
1143 if (s.size() < x.size())
1147 if (x.hasFastAccess(s.size())) {
1148 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1151 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1152 #pragma vector aligned
1154 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1158 s[i] += x.fastAccessCoeff(i);
1168 template <
typename S>
1169 KOKKOS_INLINE_FUNCTION
1170 Vector& operator += (
const volatile Expr<S>& xx) {
1172 typedef typename Expr<S>::derived_type expr_type;
1173 const volatile expr_type& x = xx.derived();
1175 if (x.size() > s.size())
1176 this->reset(x.size());
1178 #ifdef STOKHOS_DEBUG
1179 if (s.size() < x.size())
1183 if (x.hasFastAccess(s.size())) {
1184 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1187 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1188 #pragma vector aligned
1190 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1194 s[i] += x.fastAccessCoeff(i);
1204 template <
typename S>
1205 KOKKOS_INLINE_FUNCTION
1206 Vector& operator += (
const Expr<S>& xx)
volatile {
1208 typedef typename Expr<S>::derived_type expr_type;
1209 const expr_type& x = xx.derived();
1211 if (x.size() > s.size())
1212 this->reset(x.size());
1214 #ifdef STOKHOS_DEBUG
1215 if (s.size() < x.size())
1219 if (x.hasFastAccess(s.size())) {
1220 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1223 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1224 #pragma vector aligned
1226 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1230 s[i] += x.fastAccessCoeff(i);
1236 return const_cast<Vector&
>(*this);
1240 template <
typename S>
1241 KOKKOS_INLINE_FUNCTION
1242 Vector& operator += (
const volatile Expr<S>& xx)
volatile {
1244 typedef typename Expr<S>::derived_type expr_type;
1245 const volatile expr_type& x = xx.derived();
1247 if (x.size() > s.size())
1248 this->reset(x.size());
1250 #ifdef STOKHOS_DEBUG
1251 if (s.size() < x.size())
1255 if (x.hasFastAccess(s.size())) {
1256 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1259 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1260 #pragma vector aligned
1262 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1266 s[i] += x.fastAccessCoeff(i);
1272 return const_cast<Vector&
>(*this);
1276 template <
typename S>
1277 KOKKOS_INLINE_FUNCTION
1278 Vector& operator -= (
const Expr<S>& xx) {
1280 typedef typename Expr<S>::derived_type expr_type;
1281 const expr_type& x = xx.derived();
1283 if (x.size() > s.size())
1284 this->reset(x.size());
1286 #ifdef STOKHOS_DEBUG
1287 if (s.size() < x.size())
1291 if (x.hasFastAccess(s.size())) {
1292 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1295 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1296 #pragma vector aligned
1298 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1302 s[i] -= x.fastAccessCoeff(i);
1312 template <
typename S>
1313 KOKKOS_INLINE_FUNCTION
1314 Vector& operator -= (
const volatile Expr<S>& xx) {
1316 typedef typename Expr<S>::derived_type expr_type;
1317 const volatile expr_type& x = xx.derived();
1319 if (x.size() > s.size())
1320 this->reset(x.size());
1322 #ifdef STOKHOS_DEBUG
1323 if (s.size() < x.size())
1327 if (x.hasFastAccess(s.size())) {
1328 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1331 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1332 #pragma vector aligned
1334 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1338 s[i] -= x.fastAccessCoeff(i);
1348 template <
typename S>
1349 KOKKOS_INLINE_FUNCTION
1350 Vector& operator -= (
const Expr<S>& xx)
volatile {
1352 typedef typename Expr<S>::derived_type expr_type;
1353 const expr_type& x = xx.derived();
1355 if (x.size() > s.size())
1356 this->reset(x.size());
1358 #ifdef STOKHOS_DEBUG
1359 if (s.size() < x.size())
1363 if (x.hasFastAccess(s.size())) {
1364 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1367 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1368 #pragma vector aligned
1370 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1374 s[i] -= x.fastAccessCoeff(i);
1380 return const_cast<Vector&
>(*this);
1384 template <
typename S>
1385 KOKKOS_INLINE_FUNCTION
1386 Vector& operator -= (
const volatile Expr<S>& xx)
volatile {
1388 typedef typename Expr<S>::derived_type expr_type;
1389 const volatile expr_type& x = xx.derived();
1391 if (x.size() > s.size())
1392 this->reset(x.size());
1394 #ifdef STOKHOS_DEBUG
1395 if (s.size() < x.size())
1399 if (x.hasFastAccess(s.size())) {
1400 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1403 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1404 #pragma vector aligned
1406 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1410 s[i] -= x.fastAccessCoeff(i);
1416 return const_cast<Vector&
>(*this);
1420 template <
typename S>
1421 KOKKOS_INLINE_FUNCTION
1422 Vector& operator *= (
const Expr<S>& xx) {
1424 typedef typename Expr<S>::derived_type expr_type;
1425 const expr_type& x = xx.derived();
1427 if (x.size() > s.size())
1428 this->reset(x.size());
1430 #ifdef STOKHOS_DEBUG
1431 if (s.size() < x.size())
1435 if (x.hasFastAccess(s.size())) {
1436 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1439 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1440 #pragma vector aligned
1442 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1446 s[i] *= x.fastAccessCoeff(i);
1456 template <
typename S>
1457 KOKKOS_INLINE_FUNCTION
1458 Vector& operator *= (
const volatile Expr<S>& xx) {
1460 typedef typename Expr<S>::derived_type expr_type;
1461 const volatile expr_type& x = xx.derived();
1463 if (x.size() > s.size())
1464 this->reset(x.size());
1466 #ifdef STOKHOS_DEBUG
1467 if (s.size() < x.size())
1471 if (x.hasFastAccess(s.size())) {
1472 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1475 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1476 #pragma vector aligned
1478 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1482 s[i] *= x.fastAccessCoeff(i);
1492 template <
typename S>
1493 KOKKOS_INLINE_FUNCTION
1494 Vector& operator *= (
const Expr<S>& xx)
volatile {
1496 typedef typename Expr<S>::derived_type expr_type;
1497 const expr_type& x = xx.derived();
1499 if (x.size() > s.size())
1500 this->reset(x.size());
1502 #ifdef STOKHOS_DEBUG
1503 if (s.size() < x.size())
1507 if (x.hasFastAccess(s.size())) {
1508 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1511 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1512 #pragma vector aligned
1514 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1518 s[i] *= x.fastAccessCoeff(i);
1524 return const_cast<Vector&
>(*this);
1528 template <
typename S>
1529 KOKKOS_INLINE_FUNCTION
1530 Vector& operator *= (
const volatile Expr<S>& xx)
volatile {
1532 typedef typename Expr<S>::derived_type expr_type;
1533 const volatile expr_type& x = xx.derived();
1535 if (x.size() > s.size())
1536 this->reset(x.size());
1538 #ifdef STOKHOS_DEBUG
1539 if (s.size() < x.size())
1543 if (x.hasFastAccess(s.size())) {
1544 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1547 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1548 #pragma vector aligned
1550 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1554 s[i] *= x.fastAccessCoeff(i);
1560 return const_cast<Vector&
>(*this);
1564 template <
typename S>
1565 KOKKOS_INLINE_FUNCTION
1566 Vector& operator /= (
const Expr<S>& xx) {
1568 typedef typename Expr<S>::derived_type expr_type;
1569 const expr_type& x = xx.derived();
1571 if (x.size() > s.size())
1572 this->reset(x.size());
1574 #ifdef STOKHOS_DEBUG
1575 if (s.size() < x.size())
1579 if (x.hasFastAccess(s.size())) {
1580 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1583 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1584 #pragma vector aligned
1586 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1590 s[i] /= x.fastAccessCoeff(i);
1600 template <
typename S>
1601 KOKKOS_INLINE_FUNCTION
1602 Vector& operator /= (
const volatile Expr<S>& xx) {
1604 typedef typename Expr<S>::derived_type expr_type;
1605 const volatile expr_type& x = xx.derived();
1607 if (x.size() > s.size())
1608 this->reset(x.size());
1610 #ifdef STOKHOS_DEBUG
1611 if (s.size() < x.size())
1615 if (x.hasFastAccess(s.size())) {
1616 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1619 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1620 #pragma vector aligned
1622 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1626 s[i] /= x.fastAccessCoeff(i);
1636 template <
typename S>
1637 KOKKOS_INLINE_FUNCTION
1638 Vector& operator /= (
const Expr<S>& xx)
volatile {
1640 typedef typename Expr<S>::derived_type expr_type;
1641 const expr_type& x = xx.derived();
1643 if (x.size() > s.size())
1644 this->reset(x.size());
1646 #ifdef STOKHOS_DEBUG
1647 if (s.size() < x.size())
1651 if (x.hasFastAccess(s.size())) {
1652 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1655 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1656 #pragma vector aligned
1658 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1662 s[i] /= x.fastAccessCoeff(i);
1668 return const_cast<Vector&
>(*this);
1672 template <
typename S>
1673 KOKKOS_INLINE_FUNCTION
1674 Vector& operator /= (
const volatile Expr<S>& xx)
volatile {
1676 typedef typename Expr<S>::derived_type expr_type;
1677 const volatile expr_type& x = xx.derived();
1679 if (x.size() > s.size())
1680 this->reset(x.size());
1682 #ifdef STOKHOS_DEBUG
1683 if (s.size() < x.size())
1687 if (x.hasFastAccess(s.size())) {
1688 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1691 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1692 #pragma vector aligned
1694 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1698 s[i] /= x.fastAccessCoeff(i);
1704 return const_cast<Vector&
>(*this);
1708 KOKKOS_INLINE_FUNCTION
1709 Vector& operator++() {
1716 KOKKOS_INLINE_FUNCTION
1717 volatile Vector& operator++()
volatile {
1724 KOKKOS_INLINE_FUNCTION
1725 Vector operator++(
int) {
1732 KOKKOS_INLINE_FUNCTION
1733 Vector operator++(
int)
volatile {
1740 KOKKOS_INLINE_FUNCTION
1741 Vector& operator--() {
1748 KOKKOS_INLINE_FUNCTION
1749 volatile Vector& operator--()
volatile {
1756 KOKKOS_INLINE_FUNCTION
1757 Vector operator--(
int) {
1764 KOKKOS_INLINE_FUNCTION
1765 Vector operator--(
int)
volatile {
1773 KOKKOS_INLINE_FUNCTION
1774 std::string name()
const volatile {
return "x"; }
1780 template <
typename expr_type>
1785 KOKKOS_INLINE_FUNCTION
1786 StaticOp(
storage_type& s_,
const expr_type& x_) : s(s_), x(x_) {}
1788 template <
typename ArgT>
1789 KOKKOS_INLINE_FUNCTION
1790 void operator() (ArgT arg)
const {
1791 const int Arg = ArgT::value;
1792 s.template getCoeff<Arg>() = x.template getCoeff<Arg>();
1801 #if STOKHOS_USE_MP_VECTOR_SFS_SPEC
1813 template <
typename T>
struct const_expr_ref {
1814 typedef const T type;
1822 template <
typename S>
struct const_expr_ref< Vector<S> > {
1823 typedef const Vector<S>& type;
1831 template <
typename S>
struct const_expr_ref< volatile Vector<S> > {
1832 typedef const volatile Vector<S>& type;
1836 template <
typename T>
struct remove_volatile {
1839 template <
typename T>
struct remove_volatile<volatile T> {
1844 template <
typename T>
struct add_volatile {
1845 typedef volatile T type;
1847 template <
typename T>
struct add_volatile<volatile T> {
1848 typedef volatile T type;
1851 template <
typename Storage>
1853 operator << (std::ostream& os, const Vector<Storage>& a)
1859 for (ordinal_type i=0; i<a.size(); i++) {
1860 os << a.coeff(i) <<
" ";
1867 template <
typename Storage>
1869 operator << (std::ostream& os, const volatile Vector<Storage>& a)
1875 for (ordinal_type i=0; i<a.size(); i++) {
1876 os << a.coeff(i) <<
" ";
1883 template <
typename Storage>
1885 operator >> (std::istream& is, Vector<Storage>& a)
1895 if (Storage::is_static) {
1897 for (ordinal_type i=0; i<a.size(); i++) {
1898 is >> a.fastAccessCoeff(i);
1903 std::vector<value_type> c;
1906 while (is >> b && b !=
']') {
1911 ordinal_type
n = c.size();
1913 for (ordinal_type i=0; i<n; ++i)
1914 a.fastAccessCoeff(i) = c[i];
1924 template <
unsigned Size = 0>
1925 struct VectorPartition {
1926 static const unsigned PartitionSize = Size;
1930 template<
typename iType0 ,
typename iType1 >
1931 KOKKOS_INLINE_FUNCTION
1932 VectorPartition(
const iType0 & i0 ,
const iType1 & i1 ) :
1933 begin(i0), end(i1) {
1937 template <
typename T>
1938 struct is_vector_partition {
1939 static const bool value =
false;
1942 template <
unsigned Size>
1943 struct is_vector_partition< VectorPartition<Size> > {
1944 static const bool value =
true;
1949 template <
typename T>
1950 struct IsExpr< MP::Expr<T> > {
1951 static const bool value =
true;
1954 template <
typename T>
1955 struct BaseExprType< MP::Expr<T> > {
1956 typedef typename MP::Expr<T>::derived_type derived_type;
1957 typedef typename derived_type::base_expr_type type;
1960 template <
typename S>
1961 struct IsExpr< MP::Vector<S> > {
1962 static const bool value =
true;
1965 template <
typename S>
1966 struct BaseExprType< MP::Vector<S> > {
1967 typedef MP::Vector<S> type;
1971 template <
typename T>
struct is_mp_vector {
1972 static const bool value =
false;
1974 template <
typename S>
struct is_mp_vector< MP::Vector<S> > {
1975 static const bool value =
true;
1977 template <
typename T>
struct is_mp_vector< const T > {
1978 static const bool value = is_mp_vector<T>::value;
1980 template <
typename T>
struct is_mp_vector< T* > {
1981 static const bool value = is_mp_vector<T>::value;
1983 template <
typename T>
struct is_mp_vector< T[] > {
1984 static const bool value = is_mp_vector<T>::value;
1986 template <
typename T,
unsigned N>
struct is_mp_vector< T[N] > {
1987 static const bool value = is_mp_vector<T>::value;
1991 template <
typename Storage>
1998 const ordinal_type sz = x.size();
1999 if (sz == 1)
return true;
2002 const value_type
val = x.fastAccessCoeff(0);
2003 for (ordinal_type i=1; i<sz; ++i)
2004 if (x.fastAccessCoeff(i) !=
val)
return false;
2013 #if STOKHOS_ALIGN_MEMORY
2019 template <
typename Storage>
2020 class allocator< Sacado::MP::Vector< Storage > >
2026 typedef typename Base::pointer pointer;
2027 typedef typename Base::const_pointer const_pointer;
2028 typedef typename Base::reference reference;
2029 typedef typename Base::const_reference const_reference;
2030 typedef typename Base::size_type size_type;
2031 typedef typename Base::difference_type difference_type;
2033 template <
class U>
struct rebind {
typedef allocator<U> other; };
2035 template <
class U> allocator(
const allocator<U>&) {}
2038 template <
typename Storage>
2039 class allocator< const Sacado::MP::Vector< Storage > >
2045 typedef typename Base::pointer pointer;
2046 typedef typename Base::const_pointer const_pointer;
2047 typedef typename Base::reference reference;
2048 typedef typename Base::const_reference const_reference;
2049 typedef typename Base::size_type size_type;
2050 typedef typename Base::difference_type difference_type;
2052 template <
class U>
struct rebind {
typedef allocator<U> other; };
2054 template <
class U> allocator(
const allocator<U>&) {}
2061 #endif // HAVE_STOKHOS_SACADO
2063 #include "Kokkos_NumericTraits.hpp"
2067 template <
typename Storage>
2068 struct reduction_identity< Sacado::MP::Vector<Storage> > {
2071 typedef reduction_identity<scalar>
RIS;
2072 KOKKOS_FORCEINLINE_FUNCTION constexpr
static Vector
sum() {
2075 KOKKOS_FORCEINLINE_FUNCTION constexpr
static Vector
prod() {
2076 return Vector(RIS::prod());
2078 KOKKOS_FORCEINLINE_FUNCTION constexpr
static Vector
max() {
2081 KOKKOS_FORCEINLINE_FUNCTION constexpr
static Vector
min() {
2088 #endif // SACADO_MP_VECTOR_HPP
An aligned STL allocator.
Stokhos::StandardStorage< int, double > storage_type
const double & const_reference
Kokkos::DefaultExecutionSpace execution_space
Sacado::MP::Vector< Storage > Vector
KOKKOS_INLINE_FUNCTION void raise_error(const char *msg)
KOKKOS_INLINE_FUNCTION PCE< Storage > min(const typename PCE< Storage >::value_type &a, const PCE< Storage > &b)
KOKKOS_FORCEINLINE_FUNCTION static constexpr Vector sum()
std::istream & operator>>(std::istream &is, PCE< Storage > &a)
KOKKOS_FORCEINLINE_FUNCTION static constexpr Vector min()
const double * const_pointer
Storage::value_type scalar
KOKKOS_INLINE_FUNCTION PCE< Storage > max(const typename PCE< Storage >::value_type &a, const PCE< Storage > &b)
Traits class encapsulting memory alignment.
An aligned STL allocator.
KOKKOS_FORCEINLINE_FUNCTION static constexpr Vector prod()
KOKKOS_INLINE_FUNCTION bool is_constant(const T &x)
expr1 expr1 expr1 expr2 expr1 expr1 c expr2 expr1 c fastAccessCoeff(j)-expr2.val(j)
KOKKOS_FORCEINLINE_FUNCTION static constexpr Vector max()
reduction_identity< scalar > RIS
std::enable_if< Kokkos::is_view_uq_pce< Kokkos::View< RD, RP...> >::value &&Kokkos::is_view_uq_pce< Kokkos::View< XD, XP...> >::value >::type sum(const Kokkos::View< RD, RP...> &r, const Kokkos::View< XD, XP...> &x)