42#ifndef SACADO_MP_VECTOR_SFS_HPP
43#define SACADO_MP_VECTOR_SFS_HPP
47#ifdef HAVE_STOKHOS_SACADO
57 template <
typename ordinal_t,
typename value_t,
int Num,
typename device_t>
58 class Vector<
Stokhos::StaticFixedStorage<ordinal_t,value_t,Num,device_t> >{
65 typedef typename storage_type::value_type
value_type;
66 typedef typename storage_type::ordinal_type
ordinal_type;
69 typedef typename storage_type::volatile_pointer volatile_pointer;
71 typedef typename storage_type::const_volatile_pointer const_volatile_pointer;
73 typedef typename storage_type::volatile_reference volatile_reference;
75 typedef typename storage_type::const_volatile_reference const_volatile_reference;
77 typedef typename execution_space::memory_space memory_space;
81 typedef typename ScalarType<value_type>::type
scalar_type;
84 template <
class NewStorageType >
86 typedef Vector< NewStorageType > type;
90 static const int num_args = 1;
92#if STOKHOS_ALIGN_MEMORY
93 KOKKOS_INLINE_FUNCTION
94 static void*
operator new(std::size_t sz) {
95 return MemTraits::alloc(sz);
97 KOKKOS_INLINE_FUNCTION
98 static void*
operator new[](std::size_t sz) {
99 return MemTraits::alloc(sz);
101 KOKKOS_INLINE_FUNCTION
102 static void*
operator new(std::size_t sz,
void* ptr) {
105 KOKKOS_INLINE_FUNCTION
106 static void*
operator new[](std::size_t sz,
void* ptr) {
109 KOKKOS_INLINE_FUNCTION
110 static void operator delete(
void* ptr) {
111 MemTraits::free(ptr);
113 KOKKOS_INLINE_FUNCTION
114 static void operator delete[](
void* ptr) {
115 MemTraits::free(ptr);
117 KOKKOS_INLINE_FUNCTION
118 static void operator delete(
void* ptr,
void*) {
119 MemTraits::free(ptr);
121 KOKKOS_INLINE_FUNCTION
122 static void operator delete[](
void* ptr,
void*) {
123 MemTraits::free(ptr);
131 KOKKOS_INLINE_FUNCTION
138 KOKKOS_INLINE_FUNCTION
139 Vector(
const value_type& x) : s(1,
x) {}
146 KOKKOS_INLINE_FUNCTION
147 Vector(ordinal_type sz, pointer v,
bool owned) : s(sz,v,owned) {}
153 KOKKOS_INLINE_FUNCTION
154 Vector(ordinal_type sz,
const value_type& x) : s(sz,
x) {}
157 KOKKOS_INLINE_FUNCTION
161 KOKKOS_INLINE_FUNCTION
162 Vector(
const Vector& x) : s(
x.s) {}
165 KOKKOS_INLINE_FUNCTION
166 Vector(
const volatile Vector& x) : s(
x.s) {}
172 Vector(std::initializer_list<value_type> l) : s(l.size(), l.begin()) {}
175 KOKKOS_INLINE_FUNCTION
179 KOKKOS_INLINE_FUNCTION
180 void init(
const value_type& v) { s.init(v); }
183 KOKKOS_INLINE_FUNCTION
184 void init(
const value_type& v)
volatile { s.init(v); }
187 KOKKOS_INLINE_FUNCTION
188 void init(
const value_type* v) { s.init(v); }
191 KOKKOS_INLINE_FUNCTION
192 void init(
const value_type* v)
volatile { s.init(v); }
195 template <
typename S>
196 KOKKOS_INLINE_FUNCTION
197 void init(
const Vector<S>& v) {
198 s.init(v.s.coeff(), v.s.size());
202 template <
typename S>
203 KOKKOS_INLINE_FUNCTION
204 void init(
const Vector<S>& v)
volatile {
205 s.init(v.s.coeff(), v.s.size());
209 KOKKOS_INLINE_FUNCTION
210 void load(value_type* v) { s.load(v); }
213 KOKKOS_INLINE_FUNCTION
214 void load(value_type* v)
volatile { s.load(v); }
217 template <
typename S>
218 KOKKOS_INLINE_FUNCTION
219 void load(Vector<S>& v) { s.load(v.s.coeff()); }
222 template <
typename S>
223 KOKKOS_INLINE_FUNCTION
224 void load(Vector<S>& v)
volatile { s.load(v.s.coeff()); }
230 KOKKOS_INLINE_FUNCTION
231 void reset(ordinal_type sz_new) {}
237 KOKKOS_INLINE_FUNCTION
238 void reset(ordinal_type sz_new)
volatile {}
250 KOKKOS_INLINE_FUNCTION
251 void copyForWrite()
volatile { }
254 KOKKOS_INLINE_FUNCTION
255 bool isEqualTo(
const Vector& x)
const {
256 typedef IsEqual<value_type> IE;
258 for (ordinal_type i=0; i<this->size(); i++)
259 eq = eq && IE::eval(
x.coeff(i), this->coeff(i));
264 KOKKOS_INLINE_FUNCTION
265 bool isEqualTo(
const Vector& x)
const volatile {
266 typedef IsEqual<value_type> IE;
268 for (ordinal_type i=0; i<this->size(); i++)
269 eq = eq && IE::eval(
x.coeff(i), this->coeff(i));
279 KOKKOS_INLINE_FUNCTION
280 Vector& operator=(
const value_type& x) {
286 KOKKOS_INLINE_FUNCTION
287 Vector& operator=(
const value_type& x)
volatile {
289 return const_cast<Vector&
>(*this);
293 KOKKOS_INLINE_FUNCTION
294 Vector& operator=(
const Vector& x) {
303 KOKKOS_INLINE_FUNCTION
304 Vector& operator=(
const volatile Vector& x) {
313 KOKKOS_INLINE_FUNCTION
314 Vector& operator=(
const Vector& x)
volatile {
319 return const_cast<Vector&
>(*this);
323 KOKKOS_INLINE_FUNCTION
324 Vector& operator=(
const volatile Vector& x)
volatile {
329 return const_cast<Vector&
>(*this);
339 KOKKOS_INLINE_FUNCTION
340 const volatile storage_type& storage()
const volatile {
return s; }
343 KOKKOS_INLINE_FUNCTION
347 KOKKOS_INLINE_FUNCTION
351 KOKKOS_INLINE_FUNCTION
360 KOKKOS_INLINE_FUNCTION
361 const_volatile_reference
val()
const volatile {
return s[0]; }
364 KOKKOS_INLINE_FUNCTION
365 const_reference
val()
const {
return s[0]; }
368 KOKKOS_INLINE_FUNCTION
369 volatile_reference
val()
volatile {
return s[0]; }
372 KOKKOS_INLINE_FUNCTION
373 reference
val() {
return s[0]; }
383 KOKKOS_INLINE_FUNCTION
387 KOKKOS_INLINE_FUNCTION
388 static bool hasFastAccess(ordinal_type sz) {
return true; }
391 KOKKOS_INLINE_FUNCTION
392 const_pointer coeff()
const {
return s.coeff();}
395 KOKKOS_INLINE_FUNCTION
396 const_volatile_pointer coeff()
const volatile {
return s.coeff();}
399 KOKKOS_INLINE_FUNCTION
400 volatile_pointer coeff()
volatile {
return s.coeff();}
403 KOKKOS_INLINE_FUNCTION
404 pointer coeff() {
return s.coeff();}
407 KOKKOS_INLINE_FUNCTION
408 value_type coeff(ordinal_type i)
const volatile {
return s[i]; }
411 KOKKOS_INLINE_FUNCTION
412 value_type coeff(ordinal_type i)
const {
return s[i]; }
415 KOKKOS_INLINE_FUNCTION
416 value_type coeff(ordinal_type i)
volatile {
return s[i]; }
419 KOKKOS_INLINE_FUNCTION
420 value_type coeff(ordinal_type i) {
return s[i]; }
423 KOKKOS_INLINE_FUNCTION
424 const_volatile_reference
fastAccessCoeff(ordinal_type i)
const volatile {
428 KOKKOS_INLINE_FUNCTION
433 KOKKOS_INLINE_FUNCTION
438 KOKKOS_INLINE_FUNCTION
443 KOKKOS_INLINE_FUNCTION
444 const_volatile_reference operator[](ordinal_type i)
const volatile {
448 KOKKOS_INLINE_FUNCTION
449 const_reference operator[](ordinal_type i)
const {
453 KOKKOS_INLINE_FUNCTION
454 volatile_reference operator[](ordinal_type i)
volatile {
458 KOKKOS_INLINE_FUNCTION
459 reference operator[](ordinal_type i) {
463 KOKKOS_INLINE_FUNCTION
465 return s.template getCoeff<i>(); }
468 KOKKOS_INLINE_FUNCTION
470 return s.template getCoeff<i>(); }
473 KOKKOS_INLINE_FUNCTION
474 volatile_reference getCoeff()
volatile {
475 return s.template getCoeff<i>(); }
478 KOKKOS_INLINE_FUNCTION
479 reference getCoeff() {
480 return s.template getCoeff<i>(); }
483 KOKKOS_INLINE_FUNCTION
484 pointer begin() {
return s.coeff(); }
487 KOKKOS_INLINE_FUNCTION
488 const_pointer begin()
const {
return s.coeff(); }
491 KOKKOS_INLINE_FUNCTION
492 volatile_pointer begin()
volatile {
return s.coeff(); }
495 KOKKOS_INLINE_FUNCTION
496 const_volatile_pointer begin()
const volatile {
return s.coeff(); }
499 KOKKOS_INLINE_FUNCTION
500 const_pointer cbegin()
const {
return s.coeff(); }
503 KOKKOS_INLINE_FUNCTION
504 const_volatile_pointer cbegin()
const volatile {
return s.coeff(); }
507 KOKKOS_INLINE_FUNCTION
508 pointer end() {
return s.coeff() + s.size(); }
511 KOKKOS_INLINE_FUNCTION
512 const_pointer end()
const {
return s.coeff() + s.size(); }
515 KOKKOS_INLINE_FUNCTION
516 volatile_pointer end()
volatile {
return s.coeff() + s.size(); }
519 KOKKOS_INLINE_FUNCTION
520 const_volatile_pointer end()
const volatile {
return s.coeff() + s.size(); }
523 KOKKOS_INLINE_FUNCTION
524 const_pointer cend()
const {
return s.coeff()+ s.size(); }
527 KOKKOS_INLINE_FUNCTION
528 const_volatile_pointer cend()
const volatile {
return s.coeff()+ s.size(); }
538 KOKKOS_INLINE_FUNCTION
539 Vector& operator += (
const value_type& x) {
540#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
543#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
544#pragma vector aligned
546#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
549 for (ordinal_type i=0; i<s.size(); i++)
555 KOKKOS_INLINE_FUNCTION
556 Vector& operator += (
const volatile value_type& x) {
557#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
560#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
561#pragma vector aligned
563#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
566 for (ordinal_type i=0; i<s.size(); i++)
572 KOKKOS_INLINE_FUNCTION
573 Vector& operator += (
const value_type& x)
volatile {
574#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
577#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
578#pragma vector aligned
580#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
583 for (ordinal_type i=0; i<s.size(); i++)
585 return const_cast<Vector&
>(*this);
589 KOKKOS_INLINE_FUNCTION
590 Vector& operator += (
const volatile value_type& x)
volatile {
591#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
594#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
595#pragma vector aligned
597#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
600 for (ordinal_type i=0; i<s.size(); i++)
602 return const_cast<Vector&
>(*this);
606 KOKKOS_INLINE_FUNCTION
607 Vector& operator -= (
const value_type& x) {
608#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
611#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
612#pragma vector aligned
614#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
617 for (ordinal_type i=0; i<s.size(); i++)
623 KOKKOS_INLINE_FUNCTION
624 Vector& operator -= (
const volatile value_type& x) {
625#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
628#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
629#pragma vector aligned
631#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
634 for (ordinal_type i=0; i<s.size(); i++)
640 KOKKOS_INLINE_FUNCTION
641 Vector& operator -= (
const value_type& x)
volatile {
642#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
645#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
646#pragma vector aligned
648#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
651 for (ordinal_type i=0; i<s.size(); i++)
653 return const_cast<Vector&
>(*this);
657 KOKKOS_INLINE_FUNCTION
658 Vector& operator -= (
const volatile value_type& x)
volatile {
659#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
662#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
663#pragma vector aligned
665#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
668 for (ordinal_type i=0; i<s.size(); i++)
670 return const_cast<Vector&
>(*this);
674 KOKKOS_INLINE_FUNCTION
675 Vector& operator *= (
const value_type& x) {
676#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
679#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
680#pragma vector aligned
682#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
685 for (ordinal_type i=0; i<s.size(); i++)
691 KOKKOS_INLINE_FUNCTION
692 Vector& operator *= (
const volatile value_type& x) {
693#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
696#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
697#pragma vector aligned
699#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
702 for (ordinal_type i=0; i<s.size(); i++)
708 KOKKOS_INLINE_FUNCTION
709 Vector& operator *= (
const value_type& x)
volatile {
710#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
713#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
714#pragma vector aligned
716#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
719 for (ordinal_type i=0; i<s.size(); i++)
721 return const_cast<Vector&
>(*this);
725 KOKKOS_INLINE_FUNCTION
726 Vector& operator *= (
const volatile value_type& x)
volatile {
727#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
730#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
731#pragma vector aligned
733#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
736 for (ordinal_type i=0; i<s.size(); i++)
738 return const_cast<Vector&
>(*this);
742 KOKKOS_INLINE_FUNCTION
743 Vector& operator /= (
const value_type& x) {
744#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
747#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
748#pragma vector aligned
750#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
753 for (ordinal_type i=0; i<s.size(); i++)
759 KOKKOS_INLINE_FUNCTION
760 Vector& operator /= (
const volatile value_type& x) {
761#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
764#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
765#pragma vector aligned
767#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
770 for (ordinal_type i=0; i<s.size(); i++)
776 KOKKOS_INLINE_FUNCTION
777 Vector& operator /= (
const value_type& x)
volatile {
778#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
781#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
782#pragma vector aligned
784#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
787 for (ordinal_type i=0; i<s.size(); i++)
789 return const_cast<Vector&
>(*this);
793 KOKKOS_INLINE_FUNCTION
794 Vector& operator /= (
const volatile value_type& x)
volatile {
795#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
798#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
799#pragma vector aligned
801#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
804 for (ordinal_type i=0; i<s.size(); i++)
806 return const_cast<Vector&
>(*this);
810 KOKKOS_INLINE_FUNCTION
811 Vector& operator += (
const Vector& x) {
812#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
815#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
816#pragma vector aligned
818#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
821 for (ordinal_type i=0; i<s.size(); i++)
822 s[i] +=
x.fastAccessCoeff(i);
827 KOKKOS_INLINE_FUNCTION
828 Vector& operator += (
const volatile Vector& x) {
834 KOKKOS_INLINE_FUNCTION
835 Vector& operator += (
const Vector& x)
volatile {
837 return const_cast<Vector&
>(*this);
841 KOKKOS_INLINE_FUNCTION
842 Vector& operator += (
const volatile Vector& x)
volatile {
844 return const_cast<Vector&
>(*this);
848 KOKKOS_INLINE_FUNCTION
849 Vector& operator -= (
const Vector& x) {
855 KOKKOS_INLINE_FUNCTION
856 Vector& operator -= (
const volatile Vector& x) {
862 KOKKOS_INLINE_FUNCTION
863 Vector& operator -= (
const Vector& x)
volatile {
865 return const_cast<Vector&
>(*this);
869 KOKKOS_INLINE_FUNCTION
870 Vector& operator -= (
const volatile Vector& x)
volatile {
872 return const_cast<Vector&
>(*this);
876 KOKKOS_INLINE_FUNCTION
877 Vector& operator *= (
const Vector& x) {
883 KOKKOS_INLINE_FUNCTION
884 Vector& operator *= (
const volatile Vector& x) {
890 KOKKOS_INLINE_FUNCTION
891 Vector& operator *= (
const Vector& x)
volatile {
893 return const_cast<Vector&
>(*this);
897 KOKKOS_INLINE_FUNCTION
898 Vector& operator *= (
const volatile Vector& x)
volatile {
900 return const_cast<Vector&
>(*this);
904 KOKKOS_INLINE_FUNCTION
905 Vector& operator /= (
const Vector& x) {
911 KOKKOS_INLINE_FUNCTION
912 Vector& operator /= (
const volatile Vector& x) {
918 KOKKOS_INLINE_FUNCTION
919 Vector& operator /= (
const Vector& x)
volatile {
921 return const_cast<Vector&
>(*this);
925 KOKKOS_INLINE_FUNCTION
926 Vector& operator /= (
const volatile Vector& x)
volatile {
928 return const_cast<Vector&
>(*this);
932 KOKKOS_INLINE_FUNCTION
933 Vector& operator++() {
934 for (ordinal_type i=0; i<s.size(); i++)
940 KOKKOS_INLINE_FUNCTION
941 volatile Vector& operator++()
volatile {
942 for (ordinal_type i=0; i<s.size(); i++)
948 KOKKOS_INLINE_FUNCTION
949 Vector operator++(
int) {
956 KOKKOS_INLINE_FUNCTION
957 Vector operator++(
int)
volatile {
964 KOKKOS_INLINE_FUNCTION
965 Vector& operator--() {
966 for (ordinal_type i=0; i<s.size(); i++)
972 KOKKOS_INLINE_FUNCTION
973 volatile Vector& operator--()
volatile {
974 for (ordinal_type i=0; i<s.size(); i++)
980 KOKKOS_INLINE_FUNCTION
981 Vector operator--(
int) {
988 KOKKOS_INLINE_FUNCTION
989 Vector operator--(
int)
volatile {
997 KOKKOS_INLINE_FUNCTION
998 std::string name()
const volatile {
return "x"; }
expr1 expr1 expr1 expr2 expr1 expr1 c expr2 expr1 c fastAccessCoeff(j) - expr2.val(j)
Stokhos::StandardStorage< int, double > storage_type
Kokkos::DefaultExecutionSpace execution_space
const double * const_pointer
const double & const_reference
int size() const
Return size.
Statically allocated storage class.
Stokhos::StandardStorage< int, double > Storage
Top-level namespace for Stokhos classes and functions.
const IndexType const IndexType const IndexType const IndexType const ValueType const ValueType * x
Traits class encapsulting memory alignment.