Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Sacado_MP_Vector.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Stokhos Package
4 //
5 // Copyright 2009 NTESS and the Stokhos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef SACADO_MP_VECTOR_HPP
11 #define SACADO_MP_VECTOR_HPP
12 
13 #include "Stokhos_ConfigDefs.h"
14 
15 #ifdef HAVE_STOKHOS_SACADO
16 
17 #include <ostream> // for std::ostream
18 #include <initializer_list>
19 
20 #include "Kokkos_Macros.hpp"
21 
24 #include "Sacado_Traits.hpp"
25 #include "Sacado_mpl_apply.hpp"
26 #include "Sacado_mpl_range_c.hpp"
27 #include "Stokhos_mpl_for_each.hpp"
28 #include "Stokhos_MemoryTraits.hpp"
29 #include "Stokhos_Is_Constant.hpp"
30 #include "Stokhos_ViewStorage.hpp"
31 
32 #include "Kokkos_View_Utils.hpp"
33 
34 namespace Sacado {
35 
37  namespace MP {
38 
40 
53  template <typename T>
54  class Expr {
55  public:
56 
58 
62  typedef T derived_type;
63 
65 
69  KOKKOS_INLINE_FUNCTION
70  const derived_type& derived() const {
71  return static_cast<const derived_type&>(*this);
72  }
73 
75 
79  KOKKOS_INLINE_FUNCTION
80  const volatile derived_type& derived() const volatile {
81  return static_cast<const volatile derived_type&>(*this);
82  }
83 
84  // Allow explicit casting to integral types, since we don't have an
85  // integral ensemble type.
86  template <typename U, typename Enabled = typename std::enable_if<std::is_integral<U>::value>::type>
87  KOKKOS_INLINE_FUNCTION
88  explicit operator U() const { return static_cast<U>(derived().val()); }
89 
90  };
91 
93  template <typename Storage>
94  class Vector : public Expr< Vector<Storage> > {
95  public:
96 
98  typedef Storage storage_type;
99 
100  typedef typename storage_type::value_type value_type;
101  typedef typename storage_type::ordinal_type ordinal_type;
103  typedef typename storage_type::pointer pointer;
104  typedef typename storage_type::volatile_pointer volatile_pointer;
105  typedef typename storage_type::const_pointer const_pointer;
106  typedef typename storage_type::const_volatile_pointer const_volatile_pointer;
107  typedef typename storage_type::reference reference;
108  typedef typename storage_type::volatile_reference volatile_reference;
109  typedef typename storage_type::const_reference const_reference;
110  typedef typename storage_type::const_volatile_reference const_volatile_reference;
111 
112  typedef typename execution_space::memory_space memory_space;
113  typedef typename Stokhos::MemoryTraits<memory_space> MemTraits;
114 
116  typedef typename ScalarType<value_type>::type scalar_type;
117 
118  typedef Vector base_expr_type;
119 
121  template < class NewStorageType >
122  struct apply {
123  typedef Vector< NewStorageType > type;
124  };
125 
127  static const int num_args = 1;
128 
129 #if STOKHOS_ALIGN_MEMORY
130  KOKKOS_INLINE_FUNCTION
131  static void* operator new(std::size_t sz) {
132  return MemTraits::alloc(sz);
133  }
134  KOKKOS_INLINE_FUNCTION
135  static void* operator new[](std::size_t sz) {
136  return MemTraits::alloc(sz);
137  }
138  KOKKOS_INLINE_FUNCTION
139  static void* operator new(std::size_t sz, void* ptr) {
140  return ptr;
141  }
142  KOKKOS_INLINE_FUNCTION
143  static void* operator new[](std::size_t sz, void* ptr) {
144  return ptr;
145  }
146  KOKKOS_INLINE_FUNCTION
147  static void operator delete(void* ptr) {
148  MemTraits::free(ptr);
149  }
150  KOKKOS_INLINE_FUNCTION
151  static void operator delete[](void* ptr) {
152  MemTraits::free(ptr);
153  }
154  KOKKOS_INLINE_FUNCTION
155  static void operator delete(void* ptr, void*) {
156  MemTraits::free(ptr);
157  }
158  KOKKOS_INLINE_FUNCTION
159  static void operator delete[](void* ptr, void*) {
160  MemTraits::free(ptr);
161  }
162 #endif
163 
165 
168  KOKKOS_DEFAULTED_FUNCTION
169  Vector() = default;
170 
172 
175  KOKKOS_INLINE_FUNCTION
176  Vector(const value_type& x) : s(1,x) {}
177 
179 
183  KOKKOS_INLINE_FUNCTION
184  Vector(ordinal_type sz, pointer v, bool owned) : s(sz,v,owned) {}
185 
187 
190  KOKKOS_INLINE_FUNCTION
191  Vector(ordinal_type sz, const value_type& x) : s(sz,x) {}
192 
194  KOKKOS_INLINE_FUNCTION
195  Vector(const storage_type& ss) : s(ss) {}
196 
198  KOKKOS_DEFAULTED_FUNCTION
199  Vector(const Vector& x) = default;
200 
202  KOKKOS_INLINE_FUNCTION
203  Vector(const volatile Vector& x) : s(x.s) {}
204 
206  template <typename S>
207  KOKKOS_INLINE_FUNCTION
208  Vector(const Expr<S>& xx) :
209  s(xx.derived().size()) {
210  typedef typename Expr<S>::derived_type expr_type;
211  const expr_type& x = xx.derived();
212 
213 #ifdef STOKHOS_DEBUG
214  if (s.size() != x.size())
215  Kokkos::Impl::raise_error("Vector(): Mismatched sizes");
216 #endif
217 
218  if (x.hasFastAccess(s.size())) {
219 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
220 #pragma ivdep
221 #endif
222 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
223 #pragma vector aligned
224 #endif
225 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
226 #pragma unroll
227 #endif
228  for (ordinal_type i=0; i<s.size(); i++)
229  s[i] = x.fastAccessCoeff(i);
230  }
231  else {
232  for (ordinal_type i=0; i<s.size(); i++)
233  s[i] = x.coeff(i);
234  }
235  }
236 
238 
244  KOKKOS_INLINE_FUNCTION
245  Vector(std::initializer_list<value_type> l) : s(l.size(), l.begin()) {
246  if constexpr (Storage::is_static) {
247  const auto lsz = static_cast<ordinal_type>(l.size());
248  const ordinal_type sz = this->size();
249  if (lsz < sz) {
250  if (lsz > 1) {
251  Kokkos::abort("Size mismatch in list initialization of MP Vector with static fixed storage.");
252  }
253  else {
254  const value_type v = lsz > 0 ? *l.begin() : value_type(0);
255  s.init(v);
256  }
257  }
258  }
259  }
260 
262  KOKKOS_DEFAULTED_FUNCTION
263  ~Vector() = default;
264 
266  KOKKOS_INLINE_FUNCTION
267  void init(const value_type& v) { s.init(v); }
268 
270  KOKKOS_INLINE_FUNCTION
271  void init(const value_type& v) volatile { s.init(v); }
272 
274  KOKKOS_INLINE_FUNCTION
275  void init(const value_type* v) { s.init(v); }
276 
278  KOKKOS_INLINE_FUNCTION
279  void init(const value_type* v) volatile { s.init(v); }
280 
282  template <typename S>
283  KOKKOS_INLINE_FUNCTION
284  void init(const Vector<S>& v) {
285  s.init(v.s.coeff(), v.s.size());
286  }
287 
289  template <typename S>
290  KOKKOS_INLINE_FUNCTION
291  void init(const Vector<S>& v) volatile {
292  s.init(v.s.coeff(), v.s.size());
293  }
294 
296  KOKKOS_INLINE_FUNCTION
297  void load(value_type* v) { s.load(v); }
298 
300  KOKKOS_INLINE_FUNCTION
301  void load(value_type* v) volatile { s.load(v); }
302 
304  template <typename S>
305  KOKKOS_INLINE_FUNCTION
306  void load(Vector<S>& v) { s.load(v.s.coeff()); }
307 
309  template <typename S>
310  KOKKOS_INLINE_FUNCTION
311  void load(Vector<S>& v) volatile { s.load(v.s.coeff()); }
312 
314 
317  KOKKOS_INLINE_FUNCTION
318  void reset(ordinal_type sz_new) {
319  ordinal_type sz = this->size();
320  s.resize(sz_new);
321  if (sz == 1 && sz_new > sz)
322  for (ordinal_type i=1; i<sz_new; i++)
323  s[i] = s[0];
324  }
325 
327 
330  KOKKOS_INLINE_FUNCTION
331  void reset(ordinal_type sz_new) volatile {
332  ordinal_type sz = this->size();
333  s.resize(sz_new);
334  if (sz == 1 && sz_new > sz)
335  for (ordinal_type i=1; i<sz_new; i++)
336  s[i] = s[0];
337  }
338 
340 
349  KOKKOS_INLINE_FUNCTION
350  void copyForWrite() volatile { }
351 
353  template <typename S>
354  KOKKOS_INLINE_FUNCTION
355  bool isEqualTo(const Expr<S>& xx) const {
356  const typename Expr<S>::derived_type& x = xx.derived();
357  typedef IsEqual<value_type> IE;
358  if (x.size() != this->size()) return false;
359  bool eq = true;
360  for (ordinal_type i=0; i<this->size(); i++)
361  eq = eq && IE::eval(x.coeff(i), this->coeff(i));
362  return eq;
363  }
364 
366  template <typename S>
367  KOKKOS_INLINE_FUNCTION
368  bool isEqualTo(const Expr<S>& xx) const volatile {
369  const typename Expr<S>::derived_type& x = xx.derived();
370  typedef IsEqual<value_type> IE;
371  if (x.size() != this->size()) return false;
372  bool eq = true;
373  for (ordinal_type i=0; i<this->size(); i++)
374  eq = eq && IE::eval(x.coeff(i), this->coeff(i));
375  return eq;
376  }
377 
382 
384 
387  Vector& operator=(std::initializer_list<value_type> l) {
388  const ordinal_type lsz = l.size();
389  if (lsz != s.size())
390  s.resize(lsz);
391  s.init(l.begin(), lsz);
392  return *this;
393  }
394 
396 
399  /*volatile*/ Vector&
400  operator=(std::initializer_list<value_type> l) volatile {
401  const ordinal_type lsz = l.size();
402  if (lsz != s.size())
403  s.resize(lsz);
404  s.init(l.begin(), lsz);
405  return const_cast<Vector&>(*this);
406  }
407 
409  KOKKOS_INLINE_FUNCTION
410  Vector& operator=(const value_type& x) {
411  s.init(x);
412  return *this;
413  }
414 
416  KOKKOS_INLINE_FUNCTION
417  /*volatile*/ Vector& operator=(const value_type& x) volatile {
418  s.init(x);
419  return const_cast<Vector&>(*this);
420  }
421 
423  KOKKOS_INLINE_FUNCTION
424  Vector& operator=(const Vector& x) {
425  if (this != &x) {
426  s = x.s;
427 
428  // For DyamicStorage as a view (is_owned=false), we need to set
429  // the trailing entries when assigning a constant vector (because
430  // the copy constructor in this case doesn't reset the size of this)
431  //
432  // Note: supporting this technically makes the Vector non-POD, even
433  // with a static storage type where this branch will get optimized
434  // out. We would have to remove DynamicStorage-as-a view as an option
435  // or partial specialize on StaticFixedStorage to fix this. However
436  // the volatile operator=() and copy constructor overloads make
437  // Vector non-POD anyway.
438  if (s.size() > x.s.size())
439  for (ordinal_type i=x.s.size(); i<s.size(); i++)
440  s[i] = s[0];
441  }
442 
443  return *this;
444  }
445 
447  KOKKOS_INLINE_FUNCTION
448  Vector& operator=(const volatile Vector& x) {
449  if (this != &x) {
450  s = x.s;
451 
452  // For DyamicStorage as a view (is_owned=false), we need to set
453  // the trailing entries when assigning a constant vector (because
454  // the copy constructor in this case doesn't reset the size of this)
455  //
456  // Note: supporting this technically makes the Vector non-POD, even
457  // with a static storage type where this branch will get optimized
458  // out. We would have to remove DynamicStorage-as-a view as an option
459  // or partial specialize on StaticFixedStorage to fix this. However
460  // the volatile operator=() and copy constructor overloads make
461  // Vector non-POD anyway.
462  if (s.size() > x.s.size())
463  for (ordinal_type i=x.s.size(); i<s.size(); i++)
464  s[i] = s[0];
465  }
466 
467  return *this;
468  }
469 
471  KOKKOS_INLINE_FUNCTION
472  /*volatile*/ Vector& operator=(const Vector& x) volatile {
473  if (this != &x) {
474  s = x.s;
475 
476  // For DyamicStorage as a view (is_owned=false), we need to set
477  // the trailing entries when assigning a constant vector (because
478  // the copy constructor in this case doesn't reset the size of this)
479  //
480  // Note: supporting this technically makes the Vector non-POD, even
481  // with a static storage type where this branch will get optimized
482  // out. We would have to remove DynamicStorage-as-a view as an option
483  // or partial specialize on StaticFixedStorage to fix this. However
484  // the volatile operator=() and copy constructor overloads make
485  // Vector non-POD anyway.
486  if (s.size() > x.s.size())
487  for (ordinal_type i=x.s.size(); i<s.size(); i++)
488  s[i] = s[0];
489  }
490 
491  return const_cast<Vector&>(*this);
492  }
493 
495  KOKKOS_INLINE_FUNCTION
496  /*volatile*/ Vector& operator=(const volatile Vector& x) volatile {
497  if (this != &x) {
498  s = x.s;
499 
500  // For DyamicStorage as a view (is_owned=false), we need to set
501  // the trailing entries when assigning a constant vector (because
502  // the copy constructor in this case doesn't reset the size of this)
503  //
504  // Note: supporting this technically makes the Vector non-POD, even
505  // with a static storage type where this branch will get optimized
506  // out. We would have to remove DynamicStorage-as-a view as an option
507  // or partial specialize on StaticFixedStorage to fix this. However
508  // the volatile operator=() and copy constructor overloads make
509  // Vector non-POD anyway.
510  if (s.size() > x.s.size())
511  for (ordinal_type i=x.s.size(); i<s.size(); i++)
512  s[i] = s[0];
513  }
514 
515  return const_cast<Vector&>(*this);
516  }
517 
519  template <typename S>
520  KOKKOS_INLINE_FUNCTION
521  Vector& operator=(const Expr<S>& xx) {
522  typedef typename Expr<S>::derived_type expr_type;
523  const expr_type& x = xx.derived();
524 
525  this->reset(x.size());
526 
527 #ifdef STOKHOS_DEBUG
528  if (s.size() != x.size())
529  Kokkos::Impl::raise_error("Vector::operator=(): Mismatched sizes");
530 #endif
531 
532  if (x.hasFastAccess(s.size())) {
533 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
534 #pragma ivdep
535 #endif
536 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
537 #pragma vector aligned
538 #endif
539 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
540 #pragma unroll
541 #endif
542  for (ordinal_type i=0; i<s.size(); i++)
543  s[i] = x.fastAccessCoeff(i);
544  }
545  else {
546  for (ordinal_type i=0; i<s.size(); i++)
547  s[i] = x.coeff(i);
548  }
549  return *this;
550  }
551 
553  template <typename S>
554  KOKKOS_INLINE_FUNCTION
555  /*volatile*/ Vector& operator=(const Expr<S>& xx) volatile {
556  typedef typename Expr<S>::derived_type expr_type;
557  const expr_type& x = xx.derived();
558 
559  this->reset(x.size());
560 
561 #ifdef STOKHOS_DEBUG
562  if (s.size() != x.size())
563  Kokkos::Impl::raise_error("Vector::operator=(): Mismatched sizes");
564 #endif
565 
566  if (x.hasFastAccess(s.size())) {
567 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
568 #pragma ivdep
569 #endif
570 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
571 #pragma vector aligned
572 #endif
573 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
574 #pragma unroll
575 #endif
576  for (ordinal_type i=0; i<s.size(); i++)
577  s[i] = x.fastAccessCoeff(i);
578  }
579  else {
580  for (ordinal_type i=0; i<s.size(); i++)
581  s[i] = x.coeff(i);
582  }
583  return const_cast<Vector&>(*this);
584  }
585 
587  template< typename S >
588  KOKKOS_INLINE_FUNCTION
589  typename std::enable_if<( ! std::is_same<S,void>::value &&
591  ), Vector >
592  ::type const & operator = ( const Expr<S> & xx ) const
593  {
594  const typename Expr<S>::derived_type & x = xx.derived();
595 
596 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
597 #pragma ivdep
598 #endif
599 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
600 #pragma vector aligned
601 #endif
602 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
603 #pragma unroll
604 #endif
605  for ( ordinal_type i = 0 ; i < s.size() ; ++i ) { s[i] = x.coeff(i); }
606 
607  return *this ;
608  }
609 
611  template< typename S >
612  KOKKOS_INLINE_FUNCTION
613  volatile
614  typename std::enable_if<( ! std::is_same<S,void>::value &&
616  ), Vector >
617  ::type const & operator = ( const Expr<S> & xx ) const volatile
618  {
619  const typename Expr<S>::derived_type & x = xx.derived();
620 
621 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
622 #pragma ivdep
623 #endif
624 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
625 #pragma vector aligned
626 #endif
627 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
628 #pragma unroll
629 #endif
630  for ( ordinal_type i = 0 ; i < s.size() ; ++i ) { s[i] = x.coeff(i); }
631 
632  return *this ;
633  }
634 
636 
641  KOKKOS_INLINE_FUNCTION
643  const volatile storage_type& storage() const volatile { return s; }
644 
646  KOKKOS_INLINE_FUNCTION
647  const storage_type& storage() const { return s; }
648 
650  KOKKOS_INLINE_FUNCTION
651  volatile storage_type& storage() volatile { return s; }
652 
654  KOKKOS_INLINE_FUNCTION
655  storage_type& storage() { return s; }
656 
661 
663  KOKKOS_INLINE_FUNCTION
664  const_volatile_reference val() const volatile { return s[0]; }
665 
667  KOKKOS_INLINE_FUNCTION
668  const_reference val() const { return s[0]; }
669 
671  KOKKOS_INLINE_FUNCTION
672  volatile_reference val() volatile { return s[0]; }
673 
675  KOKKOS_INLINE_FUNCTION
676  reference val() { return s[0]; }
677 
679 
684 
686  KOKKOS_INLINE_FUNCTION
687  ordinal_type size() const { return s.size();}
688 
690  KOKKOS_INLINE_FUNCTION
691  ordinal_type size() const volatile { return s.size();}
692 
694  KOKKOS_INLINE_FUNCTION
695  bool hasFastAccess(ordinal_type sz) const { return s.size()>=sz;}
696 
698  KOKKOS_INLINE_FUNCTION
699  bool hasFastAccess(ordinal_type sz) const volatile { return s.size()>=sz;}
700 
702  KOKKOS_INLINE_FUNCTION
703  const_pointer coeff() const { return s.coeff();}
704 
706  KOKKOS_INLINE_FUNCTION
707  const_volatile_pointer coeff() const volatile { return s.coeff();}
708 
710  KOKKOS_INLINE_FUNCTION
711  volatile_pointer coeff() volatile { return s.coeff();}
712 
714  KOKKOS_INLINE_FUNCTION
715  pointer coeff() { return s.coeff();}
716 
718  KOKKOS_INLINE_FUNCTION
719  value_type coeff(ordinal_type i) const volatile {
720  return i<s.size() ? s[i] : s[0]; }
721 
723  KOKKOS_INLINE_FUNCTION
724  value_type coeff(ordinal_type i) const {
725  return i<s.size() ? s[i] : s[0]; }
726 
728  KOKKOS_INLINE_FUNCTION
729  value_type coeff(ordinal_type i) volatile {
730  return i<s.size() ? s[i] : s[0]; }
731 
733  KOKKOS_INLINE_FUNCTION
734  value_type coeff(ordinal_type i) {
735  return i<s.size() ? s[i] : s[0]; }
736 
738  KOKKOS_INLINE_FUNCTION
739  const_volatile_reference fastAccessCoeff(ordinal_type i) const volatile {
740  return s[i];}
741 
743  KOKKOS_INLINE_FUNCTION
744  const_reference fastAccessCoeff(ordinal_type i) const {
745  return s[i];}
746 
748  KOKKOS_INLINE_FUNCTION
749  volatile_reference fastAccessCoeff(ordinal_type i) volatile {
750  return s[i];}
751 
753  KOKKOS_INLINE_FUNCTION
754  reference fastAccessCoeff(ordinal_type i) {
755  return s[i];}
756 
758  KOKKOS_INLINE_FUNCTION
759  const_volatile_reference operator[](ordinal_type i) const volatile {
760  return s[i];}
761 
763  KOKKOS_INLINE_FUNCTION
764  const_reference operator[](ordinal_type i) const {
765  return s[i];}
766 
768  KOKKOS_INLINE_FUNCTION
769  volatile_reference operator[](ordinal_type i) volatile {
770  return s[i];}
771 
773  KOKKOS_INLINE_FUNCTION
774  reference operator[](ordinal_type i) {
775  return s[i];}
776 
777  template <int i>
778  KOKKOS_INLINE_FUNCTION
779  value_type getCoeff() const volatile {
780  return s.template getCoeff<i>(); }
781 
782  template <int i>
783  KOKKOS_INLINE_FUNCTION
784  value_type getCoeff() const {
785  return s.template getCoeff<i>(); }
786 
787  template <int i>
788  KOKKOS_INLINE_FUNCTION
789  volatile_reference getCoeff() volatile {
790  return s.template getCoeff<i>(); }
791 
792  template <int i>
793  KOKKOS_INLINE_FUNCTION
794  reference getCoeff() {
795  return s.template getCoeff<i>(); }
796 
798  KOKKOS_INLINE_FUNCTION
799  pointer begin() { return s.coeff(); }
800 
802  KOKKOS_INLINE_FUNCTION
803  const_pointer begin() const { return s.coeff(); }
804 
806  KOKKOS_INLINE_FUNCTION
807  volatile_pointer begin() volatile { return s.coeff(); }
808 
810  KOKKOS_INLINE_FUNCTION
811  const_volatile_pointer begin() const volatile { return s.coeff(); }
812 
814  KOKKOS_INLINE_FUNCTION
815  const_pointer cbegin() const { return s.coeff(); }
816 
818  KOKKOS_INLINE_FUNCTION
819  const_volatile_pointer cbegin() const volatile { return s.coeff(); }
820 
822  KOKKOS_INLINE_FUNCTION
823  pointer end() { return s.coeff() + s.size(); }
824 
826  KOKKOS_INLINE_FUNCTION
827  const_pointer end() const { return s.coeff() + s.size(); }
828 
830  KOKKOS_INLINE_FUNCTION
831  volatile_pointer end() volatile { return s.coeff() + s.size(); }
832 
834  KOKKOS_INLINE_FUNCTION
835  const_volatile_pointer end() const volatile { return s.coeff() + s.size(); }
836 
838  KOKKOS_INLINE_FUNCTION
839  const_pointer cend() const { return s.coeff()+ s.size(); }
840 
842  KOKKOS_INLINE_FUNCTION
843  const_volatile_pointer cend() const volatile { return s.coeff()+ s.size(); }
844 
846 
851 
853  KOKKOS_INLINE_FUNCTION
854  Vector& operator += (const value_type& x) {
855 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
856 #pragma ivdep
857 #endif
858 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
859 #pragma vector aligned
860 #endif
861 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
862 #pragma unroll
863 #endif
864  for (ordinal_type i=0; i<s.size(); i++)
865  s[i] += x;
866  return *this;
867  }
868 
870  KOKKOS_INLINE_FUNCTION
871  Vector& operator += (const volatile value_type& x) {
872 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
873 #pragma ivdep
874 #endif
875 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
876 #pragma vector aligned
877 #endif
878 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
879 #pragma unroll
880 #endif
881  for (ordinal_type i=0; i<s.size(); i++)
882  s[i] += x;
883  return *this;
884  }
885 
887  KOKKOS_INLINE_FUNCTION
888  /*volatile*/ Vector& operator += (const value_type& x) volatile {
889 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
890 #pragma ivdep
891 #endif
892 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
893 #pragma vector aligned
894 #endif
895 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
896 #pragma unroll
897 #endif
898  for (ordinal_type i=0; i<s.size(); i++)
899  s[i] += x;
900  return const_cast<Vector&>(*this);
901  }
902 
904  KOKKOS_INLINE_FUNCTION
905  /*volatile*/ Vector& operator += (const volatile value_type& x) volatile {
906 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
907 #pragma ivdep
908 #endif
909 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
910 #pragma vector aligned
911 #endif
912 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
913 #pragma unroll
914 #endif
915  for (ordinal_type i=0; i<s.size(); i++)
916  s[i] += x;
917  return const_cast<Vector&>(*this);
918  }
919 
921  KOKKOS_INLINE_FUNCTION
922  Vector& operator -= (const value_type& x) {
923 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
924 #pragma ivdep
925 #endif
926 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
927 #pragma vector aligned
928 #endif
929 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
930 #pragma unroll
931 #endif
932  for (ordinal_type i=0; i<s.size(); i++)
933  s[i] -= x;
934  return *this;
935  }
936 
938  KOKKOS_INLINE_FUNCTION
939  Vector& operator -= (const volatile value_type& x) {
940 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
941 #pragma ivdep
942 #endif
943 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
944 #pragma vector aligned
945 #endif
946 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
947 #pragma unroll
948 #endif
949  for (ordinal_type i=0; i<s.size(); i++)
950  s[i] -= x;
951  return *this;
952  }
953 
955  KOKKOS_INLINE_FUNCTION
956  /*volatile*/ Vector& operator -= (const value_type& x) volatile {
957 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
958 #pragma ivdep
959 #endif
960 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
961 #pragma vector aligned
962 #endif
963 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
964 #pragma unroll
965 #endif
966  for (ordinal_type i=0; i<s.size(); i++)
967  s[i] -= x;
968  return const_cast<Vector&>(*this);
969  }
970 
972  KOKKOS_INLINE_FUNCTION
973  /*volatile*/ Vector& operator -= (const volatile value_type& x) volatile {
974 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
975 #pragma ivdep
976 #endif
977 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
978 #pragma vector aligned
979 #endif
980 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
981 #pragma unroll
982 #endif
983  for (ordinal_type i=0; i<s.size(); i++)
984  s[i] -= x;
985  return const_cast<Vector&>(*this);
986  }
987 
989  KOKKOS_INLINE_FUNCTION
990  Vector& operator *= (const value_type& x) {
991 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
992 #pragma ivdep
993 #endif
994 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
995 #pragma vector aligned
996 #endif
997 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
998 #pragma unroll
999 #endif
1000  for (ordinal_type i=0; i<s.size(); i++)
1001  s[i] *= x;
1002  return *this;
1003  }
1004 
1006  KOKKOS_INLINE_FUNCTION
1007  Vector& operator *= (const volatile value_type& x) {
1008 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1009 #pragma ivdep
1010 #endif
1011 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1012 #pragma vector aligned
1013 #endif
1014 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1015 #pragma unroll
1016 #endif
1017  for (ordinal_type i=0; i<s.size(); i++)
1018  s[i] *= x;
1019  return *this;
1020  }
1021 
1023  KOKKOS_INLINE_FUNCTION
1024  /*volatile*/ Vector& operator *= (const value_type& x) volatile {
1025 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1026 #pragma ivdep
1027 #endif
1028 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1029 #pragma vector aligned
1030 #endif
1031 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1032 #pragma unroll
1033 #endif
1034  for (ordinal_type i=0; i<s.size(); i++)
1035  s[i] *= x;
1036  return const_cast<Vector&>(*this);
1037  }
1038 
1040  KOKKOS_INLINE_FUNCTION
1041  /*volatile*/ Vector& operator *= (const volatile value_type& x) volatile {
1042 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1043 #pragma ivdep
1044 #endif
1045 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1046 #pragma vector aligned
1047 #endif
1048 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1049 #pragma unroll
1050 #endif
1051  for (ordinal_type i=0; i<s.size(); i++)
1052  s[i] *= x;
1053  return const_cast<Vector&>(*this);
1054  }
1055 
1057  KOKKOS_INLINE_FUNCTION
1058  Vector& operator /= (const value_type& x) {
1059 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1060 #pragma ivdep
1061 #endif
1062 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1063 #pragma vector aligned
1064 #endif
1065 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1066 #pragma unroll
1067 #endif
1068  for (ordinal_type i=0; i<s.size(); i++)
1069  s[i] /= x;
1070  return *this;
1071  }
1072 
1074  KOKKOS_INLINE_FUNCTION
1075  Vector& operator /= (const volatile value_type& x) {
1076 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1077 #pragma ivdep
1078 #endif
1079 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1080 #pragma vector aligned
1081 #endif
1082 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1083 #pragma unroll
1084 #endif
1085  for (ordinal_type i=0; i<s.size(); i++)
1086  s[i] /= x;
1087  return *this;
1088  }
1089 
1091  KOKKOS_INLINE_FUNCTION
1092  /*volatile*/ Vector& operator /= (const value_type& x) volatile {
1093 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1094 #pragma ivdep
1095 #endif
1096 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1097 #pragma vector aligned
1098 #endif
1099 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1100 #pragma unroll
1101 #endif
1102  for (ordinal_type i=0; i<s.size(); i++)
1103  s[i] /= x;
1104  return const_cast<Vector&>(*this);
1105  }
1106 
1108  KOKKOS_INLINE_FUNCTION
1109  /*volatile*/ Vector& operator /= (const volatile value_type& x) volatile {
1110 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1111 #pragma ivdep
1112 #endif
1113 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1114 #pragma vector aligned
1115 #endif
1116 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1117 #pragma unroll
1118 #endif
1119  for (ordinal_type i=0; i<s.size(); i++)
1120  s[i] /= x;
1121  return const_cast<Vector&>(*this);
1122  }
1123 
1125  template <typename S>
1126  KOKKOS_INLINE_FUNCTION
1127  Vector& operator += (const Expr<S>& xx) {
1128  //*this = *this + x;
1129  typedef typename Expr<S>::derived_type expr_type;
1130  const expr_type& x = xx.derived();
1131 
1132  if (x.size() > s.size())
1133  this->reset(x.size());
1134 
1135 #ifdef STOKHOS_DEBUG
1136  if (s.size() < x.size())
1137  Kokkos::Impl::raise_error("Vector::operator+=(): Mismatched sizes");
1138 #endif
1139 
1140  if (x.hasFastAccess(s.size())) {
1141 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1142 #pragma ivdep
1143 #endif
1144 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1145 #pragma vector aligned
1146 #endif
1147 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1148 #pragma unroll
1149 #endif
1150  for (ordinal_type i=0; i<s.size(); i++)
1151  s[i] += x.fastAccessCoeff(i);
1152  }
1153  else {
1154  for (ordinal_type i=0; i<s.size(); i++)
1155  s[i] += x.coeff(i);
1156  }
1157  return *this;
1158  }
1159 
1161  template <typename S>
1162  KOKKOS_INLINE_FUNCTION
1163  Vector& operator += (const volatile Expr<S>& xx) {
1164  //*this = *this + x;
1165  typedef typename Expr<S>::derived_type expr_type;
1166  const volatile expr_type& x = xx.derived();
1167 
1168  if (x.size() > s.size())
1169  this->reset(x.size());
1170 
1171 #ifdef STOKHOS_DEBUG
1172  if (s.size() < x.size())
1173  Kokkos::Impl::raise_error("Vector::operator+=(): Mismatched sizes");
1174 #endif
1175 
1176  if (x.hasFastAccess(s.size())) {
1177 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1178 #pragma ivdep
1179 #endif
1180 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1181 #pragma vector aligned
1182 #endif
1183 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1184 #pragma unroll
1185 #endif
1186  for (ordinal_type i=0; i<s.size(); i++)
1187  s[i] += x.fastAccessCoeff(i);
1188  }
1189  else {
1190  for (ordinal_type i=0; i<s.size(); i++)
1191  s[i] += x.coeff(i);
1192  }
1193  return *this;
1194  }
1195 
1197  template <typename S>
1198  KOKKOS_INLINE_FUNCTION
1199  /*volatile*/ Vector& operator += (const Expr<S>& xx) volatile {
1200  //*this = *this + x;
1201  typedef typename Expr<S>::derived_type expr_type;
1202  const expr_type& x = xx.derived();
1203 
1204  if (x.size() > s.size())
1205  this->reset(x.size());
1206 
1207 #ifdef STOKHOS_DEBUG
1208  if (s.size() < x.size())
1209  Kokkos::Impl::raise_error("Vector::operator+=(): Mismatched sizes");
1210 #endif
1211 
1212  if (x.hasFastAccess(s.size())) {
1213 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1214 #pragma ivdep
1215 #endif
1216 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1217 #pragma vector aligned
1218 #endif
1219 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1220 #pragma unroll
1221 #endif
1222  for (ordinal_type i=0; i<s.size(); i++)
1223  s[i] += x.fastAccessCoeff(i);
1224  }
1225  else {
1226  for (ordinal_type i=0; i<s.size(); i++)
1227  s[i] += x.coeff(i);
1228  }
1229  return const_cast<Vector&>(*this);
1230  }
1231 
1233  template <typename S>
1234  KOKKOS_INLINE_FUNCTION
1235  /*volatile*/ Vector& operator += (const volatile Expr<S>& xx) volatile {
1236  //*this = *this + x;
1237  typedef typename Expr<S>::derived_type expr_type;
1238  const volatile expr_type& x = xx.derived();
1239 
1240  if (x.size() > s.size())
1241  this->reset(x.size());
1242 
1243 #ifdef STOKHOS_DEBUG
1244  if (s.size() < x.size())
1245  Kokkos::Impl::raise_error("Vector::operator+=(): Mismatched sizes");
1246 #endif
1247 
1248  if (x.hasFastAccess(s.size())) {
1249 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1250 #pragma ivdep
1251 #endif
1252 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1253 #pragma vector aligned
1254 #endif
1255 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1256 #pragma unroll
1257 #endif
1258  for (ordinal_type i=0; i<s.size(); i++)
1259  s[i] += x.fastAccessCoeff(i);
1260  }
1261  else {
1262  for (ordinal_type i=0; i<s.size(); i++)
1263  s[i] += x.coeff(i);
1264  }
1265  return const_cast<Vector&>(*this);
1266  }
1267 
1269  template <typename S>
1270  KOKKOS_INLINE_FUNCTION
1271  Vector& operator -= (const Expr<S>& xx) {
1272  //*this = *this - x;
1273  typedef typename Expr<S>::derived_type expr_type;
1274  const expr_type& x = xx.derived();
1275 
1276  if (x.size() > s.size())
1277  this->reset(x.size());
1278 
1279 #ifdef STOKHOS_DEBUG
1280  if (s.size() < x.size())
1281  Kokkos::Impl::raise_error("Vector::operator-=(): Mismatched sizes");
1282 #endif
1283 
1284  if (x.hasFastAccess(s.size())) {
1285 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1286 #pragma ivdep
1287 #endif
1288 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1289 #pragma vector aligned
1290 #endif
1291 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1292 #pragma unroll
1293 #endif
1294  for (ordinal_type i=0; i<s.size(); i++)
1295  s[i] -= x.fastAccessCoeff(i);
1296  }
1297  else {
1298  for (ordinal_type i=0; i<s.size(); i++)
1299  s[i] -= x.coeff(i);
1300  }
1301  return *this;
1302  }
1303 
1305  template <typename S>
1306  KOKKOS_INLINE_FUNCTION
1307  Vector& operator -= (const volatile Expr<S>& xx) {
1308  //*this = *this - x;
1309  typedef typename Expr<S>::derived_type expr_type;
1310  const volatile expr_type& x = xx.derived();
1311 
1312  if (x.size() > s.size())
1313  this->reset(x.size());
1314 
1315 #ifdef STOKHOS_DEBUG
1316  if (s.size() < x.size())
1317  Kokkos::Impl::raise_error("Vector::operator-=(): Mismatched sizes");
1318 #endif
1319 
1320  if (x.hasFastAccess(s.size())) {
1321 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1322 #pragma ivdep
1323 #endif
1324 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1325 #pragma vector aligned
1326 #endif
1327 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1328 #pragma unroll
1329 #endif
1330  for (ordinal_type i=0; i<s.size(); i++)
1331  s[i] -= x.fastAccessCoeff(i);
1332  }
1333  else {
1334  for (ordinal_type i=0; i<s.size(); i++)
1335  s[i] -= x.coeff(i);
1336  }
1337  return *this;
1338  }
1339 
1341  template <typename S>
1342  KOKKOS_INLINE_FUNCTION
1343  /*volatile*/ Vector& operator -= (const Expr<S>& xx) volatile {
1344  //*this = *this - x;
1345  typedef typename Expr<S>::derived_type expr_type;
1346  const expr_type& x = xx.derived();
1347 
1348  if (x.size() > s.size())
1349  this->reset(x.size());
1350 
1351 #ifdef STOKHOS_DEBUG
1352  if (s.size() < x.size())
1353  Kokkos::Impl::raise_error("Vector::operator-=(): Mismatched sizes");
1354 #endif
1355 
1356  if (x.hasFastAccess(s.size())) {
1357 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1358 #pragma ivdep
1359 #endif
1360 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1361 #pragma vector aligned
1362 #endif
1363 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1364 #pragma unroll
1365 #endif
1366  for (ordinal_type i=0; i<s.size(); i++)
1367  s[i] -= x.fastAccessCoeff(i);
1368  }
1369  else {
1370  for (ordinal_type i=0; i<s.size(); i++)
1371  s[i] -= x.coeff(i);
1372  }
1373  return const_cast<Vector&>(*this);
1374  }
1375 
1377  template <typename S>
1378  KOKKOS_INLINE_FUNCTION
1379  /*volatile*/ Vector& operator -= (const volatile Expr<S>& xx) volatile {
1380  //*this = *this - x;
1381  typedef typename Expr<S>::derived_type expr_type;
1382  const volatile expr_type& x = xx.derived();
1383 
1384  if (x.size() > s.size())
1385  this->reset(x.size());
1386 
1387 #ifdef STOKHOS_DEBUG
1388  if (s.size() < x.size())
1389  Kokkos::Impl::raise_error("Vector::operator-=(): Mismatched sizes");
1390 #endif
1391 
1392  if (x.hasFastAccess(s.size())) {
1393 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1394 #pragma ivdep
1395 #endif
1396 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1397 #pragma vector aligned
1398 #endif
1399 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1400 #pragma unroll
1401 #endif
1402  for (ordinal_type i=0; i<s.size(); i++)
1403  s[i] -= x.fastAccessCoeff(i);
1404  }
1405  else {
1406  for (ordinal_type i=0; i<s.size(); i++)
1407  s[i] -= x.coeff(i);
1408  }
1409  return const_cast<Vector&>(*this);
1410  }
1411 
1413  template <typename S>
1414  KOKKOS_INLINE_FUNCTION
1415  Vector& operator *= (const Expr<S>& xx) {
1416  //*this = *this * x;
1417  typedef typename Expr<S>::derived_type expr_type;
1418  const expr_type& x = xx.derived();
1419 
1420  if (x.size() > s.size())
1421  this->reset(x.size());
1422 
1423 #ifdef STOKHOS_DEBUG
1424  if (s.size() < x.size())
1425  Kokkos::Impl::raise_error("Vector::operator*=(): Mismatched sizes");
1426 #endif
1427 
1428  if (x.hasFastAccess(s.size())) {
1429 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1430 #pragma ivdep
1431 #endif
1432 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1433 #pragma vector aligned
1434 #endif
1435 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1436 #pragma unroll
1437 #endif
1438  for (ordinal_type i=0; i<s.size(); i++)
1439  s[i] *= x.fastAccessCoeff(i);
1440  }
1441  else {
1442  for (ordinal_type i=0; i<s.size(); i++)
1443  s[i] *= x.coeff(i);
1444  }
1445  return *this;
1446  }
1447 
1449  template <typename S>
1450  KOKKOS_INLINE_FUNCTION
1451  Vector& operator *= (const volatile Expr<S>& xx) {
1452  //*this = *this * x;
1453  typedef typename Expr<S>::derived_type expr_type;
1454  const volatile expr_type& x = xx.derived();
1455 
1456  if (x.size() > s.size())
1457  this->reset(x.size());
1458 
1459 #ifdef STOKHOS_DEBUG
1460  if (s.size() < x.size())
1461  Kokkos::Impl::raise_error("Vector::operator*=(): Mismatched sizes");
1462 #endif
1463 
1464  if (x.hasFastAccess(s.size())) {
1465 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1466 #pragma ivdep
1467 #endif
1468 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1469 #pragma vector aligned
1470 #endif
1471 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1472 #pragma unroll
1473 #endif
1474  for (ordinal_type i=0; i<s.size(); i++)
1475  s[i] *= x.fastAccessCoeff(i);
1476  }
1477  else {
1478  for (ordinal_type i=0; i<s.size(); i++)
1479  s[i] *= x.coeff(i);
1480  }
1481  return *this;
1482  }
1483 
1485  template <typename S>
1486  KOKKOS_INLINE_FUNCTION
1487  /*volatile*/ Vector& operator *= (const Expr<S>& xx) volatile {
1488  //*this = *this * x;
1489  typedef typename Expr<S>::derived_type expr_type;
1490  const expr_type& x = xx.derived();
1491 
1492  if (x.size() > s.size())
1493  this->reset(x.size());
1494 
1495 #ifdef STOKHOS_DEBUG
1496  if (s.size() < x.size())
1497  Kokkos::Impl::raise_error("Vector::operator*=(): Mismatched sizes");
1498 #endif
1499 
1500  if (x.hasFastAccess(s.size())) {
1501 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1502 #pragma ivdep
1503 #endif
1504 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1505 #pragma vector aligned
1506 #endif
1507 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1508 #pragma unroll
1509 #endif
1510  for (ordinal_type i=0; i<s.size(); i++)
1511  s[i] *= x.fastAccessCoeff(i);
1512  }
1513  else {
1514  for (ordinal_type i=0; i<s.size(); i++)
1515  s[i] *= x.coeff(i);
1516  }
1517  return const_cast<Vector&>(*this);
1518  }
1519 
1521  template <typename S>
1522  KOKKOS_INLINE_FUNCTION
1523  /*volatile*/ Vector& operator *= (const volatile Expr<S>& xx) volatile {
1524  //*this = *this * x;
1525  typedef typename Expr<S>::derived_type expr_type;
1526  const volatile expr_type& x = xx.derived();
1527 
1528  if (x.size() > s.size())
1529  this->reset(x.size());
1530 
1531 #ifdef STOKHOS_DEBUG
1532  if (s.size() < x.size())
1533  Kokkos::Impl::raise_error("Vector::operator*=(): Mismatched sizes");
1534 #endif
1535 
1536  if (x.hasFastAccess(s.size())) {
1537 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1538 #pragma ivdep
1539 #endif
1540 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1541 #pragma vector aligned
1542 #endif
1543 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1544 #pragma unroll
1545 #endif
1546  for (ordinal_type i=0; i<s.size(); i++)
1547  s[i] *= x.fastAccessCoeff(i);
1548  }
1549  else {
1550  for (ordinal_type i=0; i<s.size(); i++)
1551  s[i] *= x.coeff(i);
1552  }
1553  return const_cast<Vector&>(*this);
1554  }
1555 
1557  template <typename S>
1558  KOKKOS_INLINE_FUNCTION
1559  Vector& operator /= (const Expr<S>& xx) {
1560  //*this = *this / x;
1561  typedef typename Expr<S>::derived_type expr_type;
1562  const expr_type& x = xx.derived();
1563 
1564  if (x.size() > s.size())
1565  this->reset(x.size());
1566 
1567 #ifdef STOKHOS_DEBUG
1568  if (s.size() < x.size())
1569  Kokkos::Impl::raise_error("Vector::operator/=(): Mismatched sizes");
1570 #endif
1571 
1572  if (x.hasFastAccess(s.size())) {
1573 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1574 #pragma ivdep
1575 #endif
1576 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1577 #pragma vector aligned
1578 #endif
1579 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1580 #pragma unroll
1581 #endif
1582  for (ordinal_type i=0; i<s.size(); i++)
1583  s[i] /= x.fastAccessCoeff(i);
1584  }
1585  else {
1586  for (ordinal_type i=0; i<s.size(); i++)
1587  s[i] /= x.coeff(i);
1588  }
1589  return *this;
1590  }
1591 
1593  template <typename S>
1594  KOKKOS_INLINE_FUNCTION
1595  Vector& operator /= (const volatile Expr<S>& xx) {
1596  //*this = *this / x;
1597  typedef typename Expr<S>::derived_type expr_type;
1598  const volatile expr_type& x = xx.derived();
1599 
1600  if (x.size() > s.size())
1601  this->reset(x.size());
1602 
1603 #ifdef STOKHOS_DEBUG
1604  if (s.size() < x.size())
1605  Kokkos::Impl::raise_error("Vector::operator/=(): Mismatched sizes");
1606 #endif
1607 
1608  if (x.hasFastAccess(s.size())) {
1609 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1610 #pragma ivdep
1611 #endif
1612 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1613 #pragma vector aligned
1614 #endif
1615 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1616 #pragma unroll
1617 #endif
1618  for (ordinal_type i=0; i<s.size(); i++)
1619  s[i] /= x.fastAccessCoeff(i);
1620  }
1621  else {
1622  for (ordinal_type i=0; i<s.size(); i++)
1623  s[i] /= x.coeff(i);
1624  }
1625  return *this;
1626  }
1627 
1629  template <typename S>
1630  KOKKOS_INLINE_FUNCTION
1631  /*volatile*/ Vector& operator /= (const Expr<S>& xx) volatile {
1632  //*this = *this / x;
1633  typedef typename Expr<S>::derived_type expr_type;
1634  const expr_type& x = xx.derived();
1635 
1636  if (x.size() > s.size())
1637  this->reset(x.size());
1638 
1639 #ifdef STOKHOS_DEBUG
1640  if (s.size() < x.size())
1641  Kokkos::Impl::raise_error("Vector::operator/=(): Mismatched sizes");
1642 #endif
1643 
1644  if (x.hasFastAccess(s.size())) {
1645 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1646 #pragma ivdep
1647 #endif
1648 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1649 #pragma vector aligned
1650 #endif
1651 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1652 #pragma unroll
1653 #endif
1654  for (ordinal_type i=0; i<s.size(); i++)
1655  s[i] /= x.fastAccessCoeff(i);
1656  }
1657  else {
1658  for (ordinal_type i=0; i<s.size(); i++)
1659  s[i] /= x.coeff(i);
1660  }
1661  return const_cast<Vector&>(*this);
1662  }
1663 
1665  template <typename S>
1666  KOKKOS_INLINE_FUNCTION
1667  /*volatile*/ Vector& operator /= (const volatile Expr<S>& xx) volatile {
1668  //*this = *this / x;
1669  typedef typename Expr<S>::derived_type expr_type;
1670  const volatile expr_type& x = xx.derived();
1671 
1672  if (x.size() > s.size())
1673  this->reset(x.size());
1674 
1675 #ifdef STOKHOS_DEBUG
1676  if (s.size() < x.size())
1677  Kokkos::Impl::raise_error("Vector::operator/=(): Mismatched sizes");
1678 #endif
1679 
1680  if (x.hasFastAccess(s.size())) {
1681 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1682 #pragma ivdep
1683 #endif
1684 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1685 #pragma vector aligned
1686 #endif
1687 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1688 #pragma unroll
1689 #endif
1690  for (ordinal_type i=0; i<s.size(); i++)
1691  s[i] /= x.fastAccessCoeff(i);
1692  }
1693  else {
1694  for (ordinal_type i=0; i<s.size(); i++)
1695  s[i] /= x.coeff(i);
1696  }
1697  return const_cast<Vector&>(*this);
1698  }
1699 
1701  KOKKOS_INLINE_FUNCTION
1702  Vector& operator++() {
1703  for (ordinal_type i=0; i<s.size(); i++)
1704  ++(s[i]);
1705  return *this;
1706  }
1707 
1709  KOKKOS_INLINE_FUNCTION
1710  volatile Vector& operator++() volatile {
1711  for (ordinal_type i=0; i<s.size(); i++)
1712  ++(s[i]);
1713  return *this;
1714  }
1715 
1717  KOKKOS_INLINE_FUNCTION
1718  Vector operator++(int) {
1719  Vector tmp(*this);
1720  ++(*this);
1721  return tmp;
1722  }
1723 
1725  KOKKOS_INLINE_FUNCTION
1726  Vector operator++(int) volatile {
1727  Vector tmp(*this);
1728  ++(*this);
1729  return tmp;
1730  }
1731 
1733  KOKKOS_INLINE_FUNCTION
1734  Vector& operator--() {
1735  for (ordinal_type i=0; i<s.size(); i++)
1736  --(s[i]);
1737  return *this;
1738  }
1739 
1741  KOKKOS_INLINE_FUNCTION
1742  volatile Vector& operator--() volatile {
1743  for (ordinal_type i=0; i<s.size(); i++)
1744  --(s[i]);
1745  return *this;
1746  }
1747 
1749  KOKKOS_INLINE_FUNCTION
1750  Vector operator--(int) {
1751  Vector tmp(*this);
1752  --(*this);
1753  return tmp;
1754  }
1755 
1757  KOKKOS_INLINE_FUNCTION
1758  Vector operator--(int) volatile {
1759  Vector tmp(*this);
1760  --(*this);
1761  return tmp;
1762  }
1763 
1765 
1766  KOKKOS_INLINE_FUNCTION
1767  std::string name() const volatile { return "x"; }
1768 
1769  protected:
1770 
1771  Storage s;
1772 
1773  template <typename expr_type>
1774  struct StaticOp {
1775  storage_type& s;
1776  const expr_type& x;
1777 
1778  KOKKOS_INLINE_FUNCTION
1779  StaticOp(storage_type& s_, const expr_type& x_) : s(s_), x(x_) {}
1780 
1781  template <typename ArgT>
1782  KOKKOS_INLINE_FUNCTION
1783  void operator() (ArgT arg) const {
1784  const int Arg = ArgT::value;
1785  s.template getCoeff<Arg>() = x.template getCoeff<Arg>();
1786  }
1787 
1788  };
1789 
1790  }; // class Vector
1791  }
1792 }
1793 
1794 #if STOKHOS_USE_MP_VECTOR_SFS_SPEC
1795 #include "Sacado_MP_Vector_SFS.hpp"
1796 #endif
1797 
1798 namespace Sacado{
1799  namespace MP {
1800 
1802 
1806  template <typename T> struct const_expr_ref {
1807  typedef const T type;
1808  };
1809 
1811 
1815  template <typename S> struct const_expr_ref< Vector<S> > {
1816  typedef const Vector<S>& type;
1817  };
1818 
1820 
1824  template <typename S> struct const_expr_ref< volatile Vector<S> > {
1825  typedef const volatile Vector<S>& type;
1826  };
1827 
1829  template <typename T> struct remove_volatile {
1830  typedef T type;
1831  };
1832  template <typename T> struct remove_volatile<volatile T> {
1833  typedef T type;
1834  };
1835 
1837  template <typename T> struct add_volatile {
1838  typedef volatile T type;
1839  };
1840  template <typename T> struct add_volatile<volatile T> {
1841  typedef volatile T type;
1842  };
1843 
1844  template <typename Storage>
1845  std::ostream&
1846  operator << (std::ostream& os, const Vector<Storage>& a)
1847  {
1849 
1850  os << "[ ";
1851 
1852  for (ordinal_type i=0; i<a.size(); i++) {
1853  os << a.coeff(i) << " ";
1854  }
1855 
1856  os << "]";
1857  return os;
1858  }
1859 
1860  template <typename Storage>
1861  std::ostream&
1862  operator << (std::ostream& os, const volatile Vector<Storage>& a)
1863  {
1865 
1866  os << "[ ";
1867 
1868  for (ordinal_type i=0; i<a.size(); i++) {
1869  os << a.coeff(i) << " ";
1870  }
1871 
1872  os << "]";
1873  return os;
1874  }
1875 
1876  template <typename Storage>
1877  std::istream&
1878  operator >> (std::istream& is, Vector<Storage>& a)
1879  {
1881  typedef typename Vector<Storage>::value_type value_type;
1882 
1883  //
1884  // Need to check all of this for errors, end-of-line, etc...
1885  //
1886 
1887  char b = 0;
1888  if (Storage::is_static) {
1889  is >> b; // "["
1890  for (ordinal_type i=0; i<a.size(); i++) {
1891  is >> a.fastAccessCoeff(i);
1892  }
1893  is >> b; // "]";
1894  }
1895  else {
1896  std::vector<value_type> c;
1897  value_type v;
1898  is >> b; // "["
1899  while (is >> b && b != ']') {
1900  is.putback(b);
1901  is >> v;
1902  c.push_back(v);
1903  }
1904  ordinal_type n = c.size();
1905  a.reset(n);
1906  for (ordinal_type i=0; i<n; ++i)
1907  a.fastAccessCoeff(i) = c[i];
1908  }
1909 
1910  return is;
1911  }
1912 
1913  //------------------------------------------------------------------------
1914  //------------------------------------------------------------------------
1915 
1917  template <unsigned Size = 0>
1918  struct VectorPartition {
1919  static const unsigned PartitionSize = Size;
1920  unsigned begin ;
1921  unsigned end ;
1922 
1923  template< typename iType0 , typename iType1 >
1924  KOKKOS_INLINE_FUNCTION
1925  VectorPartition( const iType0 & i0 , const iType1 & i1 ) :
1926  begin(i0), end(i1) {
1927  }
1928  };
1929 
1930  template <typename T>
1931  struct is_vector_partition {
1932  static const bool value = false;
1933  };
1934 
1935  template <unsigned Size>
1936  struct is_vector_partition< VectorPartition<Size> > {
1937  static const bool value = true;
1938  };
1939 
1940  } // namespace MP
1941 
1942  template <typename T>
1943  struct IsExpr< MP::Expr<T> > {
1944  static const bool value = true;
1945  };
1946 
1947  template <typename T>
1948  struct BaseExprType< MP::Expr<T> > {
1949  typedef typename MP::Expr<T>::derived_type derived_type;
1950  typedef typename derived_type::base_expr_type type;
1951  };
1952 
1953  template <typename S>
1954  struct IsExpr< MP::Vector<S> > {
1955  static const bool value = true;
1956  };
1957 
1958  template <typename S>
1959  struct BaseExprType< MP::Vector<S> > {
1960  typedef MP::Vector<S> type;
1961  };
1962 
1964  template <typename T> struct is_mp_vector {
1965  static const bool value = false;
1966  };
1967  template <typename S> struct is_mp_vector< MP::Vector<S> > {
1968  static const bool value = true;
1969  };
1970  template <typename T> struct is_mp_vector< const T > {
1971  static const bool value = is_mp_vector<T>::value;
1972  };
1973  template <typename T> struct is_mp_vector< T* > {
1974  static const bool value = is_mp_vector<T>::value;
1975  };
1976  template <typename T> struct is_mp_vector< T[] > {
1977  static const bool value = is_mp_vector<T>::value;
1978  };
1979  template <typename T, unsigned N> struct is_mp_vector< T[N] > {
1980  static const bool value = is_mp_vector<T>::value;
1981  };
1982 
1983  // Utility function to see if a MP::Vector is really a constant
1984  template <typename Storage>
1986  {
1987  typedef typename Storage::ordinal_type ordinal_type;
1988  typedef typename Storage::value_type value_type;
1989 
1990  // All size-1 vectors are constants
1991  const ordinal_type sz = x.size();
1992  if (sz == 1) return true;
1993 
1994  // Maybe use a tolerance????
1995  const value_type val = x.fastAccessCoeff(0);
1996  for (ordinal_type i=1; i<sz; ++i)
1997  if (x.fastAccessCoeff(i) != val) return false;
1998 
1999  return true;
2000  }
2001 
2002 } // namespace Sacado
2003 
2004 #include "Sacado_MP_Vector_ops.hpp"
2006 
2007 #if STOKHOS_ALIGN_MEMORY
2008 
2009 #include <memory>
2010 
2011 namespace std {
2012 
2013 template <typename Storage>
2014 class allocator< Sacado::MP::Vector< Storage > >
2015  : public Stokhos::aligned_allocator< Sacado::MP::Vector< Storage > > {
2016 public:
2017  typedef Sacado::MP::Vector<Storage> T;
2018  typedef Stokhos::aligned_allocator<T> Base;
2019  typedef typename Base::value_type value_type;
2020  typedef typename Base::pointer pointer;
2021  typedef typename Base::const_pointer const_pointer;
2022  typedef typename Base::reference reference;
2023  typedef typename Base::const_reference const_reference;
2024  typedef typename Base::size_type size_type;
2025  typedef typename Base::difference_type difference_type;
2026 
2027  template <class U> struct rebind { typedef allocator<U> other; };
2028  allocator() {}
2029  template <class U> allocator(const allocator<U>&) {}
2030 };
2031 
2032 template <typename Storage>
2033 class allocator< const Sacado::MP::Vector< Storage > >
2034  : public Stokhos::aligned_allocator< const Sacado::MP::Vector< Storage > > {
2035 public:
2036  typedef Sacado::MP::Vector<Storage> T;
2038  typedef typename Base::value_type value_type;
2039  typedef typename Base::pointer pointer;
2040  typedef typename Base::const_pointer const_pointer;
2041  typedef typename Base::reference reference;
2042  typedef typename Base::const_reference const_reference;
2043  typedef typename Base::size_type size_type;
2044  typedef typename Base::difference_type difference_type;
2045 
2046  template <class U> struct rebind { typedef allocator<U> other; };
2047  allocator() {}
2048  template <class U> allocator(const allocator<U>&) {}
2049 };
2050 
2051 }
2052 
2053 #endif
2054 
2055 #include "Kokkos_NumericTraits.hpp"
2056 
2057 namespace Kokkos {
2058 
2059 template <typename Storage>
2060 struct reduction_identity< Sacado::MP::Vector<Storage> > {
2061  typedef Sacado::MP::Vector<Storage> Vector;
2062  typedef typename Storage::value_type scalar;
2063  typedef reduction_identity<scalar> RIS;
2064  KOKKOS_FORCEINLINE_FUNCTION constexpr static Vector sum() {
2065  return Vector(RIS::sum());
2066  }
2067  KOKKOS_FORCEINLINE_FUNCTION constexpr static Vector prod() {
2068  return Vector(RIS::prod());
2069  }
2070  KOKKOS_FORCEINLINE_FUNCTION constexpr static Vector max() {
2071  return Vector(RIS::max());
2072  }
2073  KOKKOS_FORCEINLINE_FUNCTION constexpr static Vector min() {
2074  return Vector(RIS::min());
2075  }
2076 };
2077 
2078 namespace Impl {
2079  template <typename Storage>
2080  struct promote<Sacado::MP::Vector<Storage>,false> {
2081  using type = typename Sacado::MP::Vector<Storage>;
2082  };
2083 }
2084 
2085 }
2086 
2087 #endif // HAVE_STOKHOS_SACADO
2088 
2089 #endif // SACADO_MP_VECTOR_HPP
An aligned STL allocator.
Stokhos::StandardStorage< int, double > storage_type
Kokkos::DefaultExecutionSpace execution_space
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)
std::istream & operator>>(std::istream &is, PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION PCE< Storage > max(const typename PCE< Storage >::value_type &a, const PCE< Storage > &b)
Traits class encapsulting memory alignment.
KOKKOS_INLINE_FUNCTION bool is_constant(const T &x)
expr1 expr1 expr1 expr2 expr1 expr1 c expr2 expr1 c fastAccessCoeff(j)-expr2.val(j)
expr val()
int n
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)