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 //
4 // Stokhos Package
5 // Copyright (2009) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Eric T. Phipps (etphipp@sandia.gov).
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 #ifndef SACADO_MP_VECTOR_HPP
43 #define SACADO_MP_VECTOR_HPP
44 
45 #include "Stokhos_ConfigDefs.h"
46 
47 #ifdef HAVE_STOKHOS_SACADO
48 
49 #include <ostream> // for std::ostream
50 #include <initializer_list>
51 
52 #include "Kokkos_Macros.hpp"
53 
56 #include "Sacado_Traits.hpp"
57 #include "Sacado_mpl_apply.hpp"
58 #include "Sacado_mpl_range_c.hpp"
59 #include "Stokhos_mpl_for_each.hpp"
60 #include "Stokhos_MemoryTraits.hpp"
61 #include "Stokhos_Is_Constant.hpp"
62 
63 #include "Kokkos_View_Utils.hpp"
64 
65 namespace Sacado {
66 
68  namespace MP {
69 
71 
84  template <typename T>
85  class Expr {
86  public:
87 
89 
93  typedef T derived_type;
94 
96 
100  KOKKOS_INLINE_FUNCTION
101  const derived_type& derived() const {
102  return static_cast<const derived_type&>(*this);
103  }
104 
106 
110  KOKKOS_INLINE_FUNCTION
111  const volatile derived_type& derived() const volatile {
112  return static_cast<const volatile derived_type&>(*this);
113  }
114 
115  };
116 
118  template <typename Storage>
119  class Vector : public Expr< Vector<Storage> > {
120  public:
121 
123  typedef Storage storage_type;
124 
125  typedef typename storage_type::value_type value_type;
126  typedef typename storage_type::ordinal_type ordinal_type;
128  typedef typename storage_type::pointer pointer;
129  typedef typename storage_type::volatile_pointer volatile_pointer;
130  typedef typename storage_type::const_pointer const_pointer;
131  typedef typename storage_type::const_volatile_pointer const_volatile_pointer;
132  typedef typename storage_type::reference reference;
133  typedef typename storage_type::volatile_reference volatile_reference;
134  typedef typename storage_type::const_reference const_reference;
135  typedef typename storage_type::const_volatile_reference const_volatile_reference;
136 
137  typedef typename execution_space::memory_space memory_space;
138  typedef typename Stokhos::MemoryTraits<memory_space> MemTraits;
139 
141  typedef typename ScalarType<value_type>::type scalar_type;
142 
143  typedef Vector base_expr_type;
144 
146  template < class NewStorageType >
147  struct apply {
148  typedef Vector< NewStorageType > type;
149  };
150 
152  static const int num_args = 1;
153 
154 #if STOKHOS_ALIGN_MEMORY
155  KOKKOS_INLINE_FUNCTION
156  static void* operator new(std::size_t sz) {
157  return MemTraits::alloc(sz);
158  }
159  KOKKOS_INLINE_FUNCTION
160  static void* operator new[](std::size_t sz) {
161  return MemTraits::alloc(sz);
162  }
163  KOKKOS_INLINE_FUNCTION
164  static void* operator new(std::size_t sz, void* ptr) {
165  return ptr;
166  }
167  KOKKOS_INLINE_FUNCTION
168  static void* operator new[](std::size_t sz, void* ptr) {
169  return ptr;
170  }
171  KOKKOS_INLINE_FUNCTION
172  static void operator delete(void* ptr) {
173  MemTraits::free(ptr);
174  }
175  KOKKOS_INLINE_FUNCTION
176  static void operator delete[](void* ptr) {
177  MemTraits::free(ptr);
178  }
179  KOKKOS_INLINE_FUNCTION
180  static void operator delete(void* ptr, void*) {
181  MemTraits::free(ptr);
182  }
183  KOKKOS_INLINE_FUNCTION
184  static void operator delete[](void* ptr, void*) {
185  MemTraits::free(ptr);
186  }
187 #endif
188 
190 
193  KOKKOS_INLINE_FUNCTION
194  Vector() = default;
195 
197 
200  KOKKOS_INLINE_FUNCTION
201  Vector(const value_type& x) : s(1,x) {}
202 
204 
208  KOKKOS_INLINE_FUNCTION
209  Vector(ordinal_type sz, pointer v, bool owned) : s(sz,v,owned) {}
210 
212 
215  KOKKOS_INLINE_FUNCTION
216  Vector(ordinal_type sz, const value_type& x) : s(sz,x) {}
217 
219  KOKKOS_INLINE_FUNCTION
220  Vector(const storage_type& ss) : s(ss) {}
221 
223  KOKKOS_INLINE_FUNCTION
224  Vector(const Vector& x) = default;
225 
227  KOKKOS_INLINE_FUNCTION
228  Vector(const volatile Vector& x) : s(x.s) {}
229 
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();
237 
238 #ifdef STOKHOS_DEBUG
239  if (s.size() != x.size())
240  Kokkos::Impl::raise_error("Vector(): Mismatched sizes");
241 #endif
242 
243  if (x.hasFastAccess(s.size())) {
244 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
245 #pragma ivdep
246 #endif
247 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
248 #pragma vector aligned
249 #endif
250 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
251 #pragma unroll
252 #endif
253  for (ordinal_type i=0; i<s.size(); i++)
254  s[i] = x.fastAccessCoeff(i);
255  }
256  else {
257  for (ordinal_type i=0; i<s.size(); i++)
258  s[i] = x.coeff(i);
259  }
260  }
261 
263 
266  Vector(std::initializer_list<value_type> l) : s(l.size(), l.begin()) {}
267 
269  KOKKOS_INLINE_FUNCTION
270  ~Vector() = default;
271 
273  KOKKOS_INLINE_FUNCTION
274  void init(const value_type& v) { s.init(v); }
275 
277  KOKKOS_INLINE_FUNCTION
278  void init(const value_type& v) volatile { s.init(v); }
279 
281  KOKKOS_INLINE_FUNCTION
282  void init(const value_type* v) { s.init(v); }
283 
285  KOKKOS_INLINE_FUNCTION
286  void init(const value_type* v) volatile { s.init(v); }
287 
289  template <typename S>
290  KOKKOS_INLINE_FUNCTION
291  void init(const Vector<S>& v) {
292  s.init(v.s.coeff(), v.s.size());
293  }
294 
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());
300  }
301 
303  KOKKOS_INLINE_FUNCTION
304  void load(value_type* v) { s.load(v); }
305 
307  KOKKOS_INLINE_FUNCTION
308  void load(value_type* v) volatile { s.load(v); }
309 
311  template <typename S>
312  KOKKOS_INLINE_FUNCTION
313  void load(Vector<S>& v) { s.load(v.s.coeff()); }
314 
316  template <typename S>
317  KOKKOS_INLINE_FUNCTION
318  void load(Vector<S>& v) volatile { s.load(v.s.coeff()); }
319 
321 
324  KOKKOS_INLINE_FUNCTION
325  void reset(ordinal_type sz_new) {
326  ordinal_type sz = this->size();
327  s.resize(sz_new);
328  if (sz == 1 && sz_new > sz)
329  for (ordinal_type i=1; i<sz_new; i++)
330  s[i] = s[0];
331  }
332 
334 
337  KOKKOS_INLINE_FUNCTION
338  void reset(ordinal_type sz_new) volatile {
339  ordinal_type sz = this->size();
340  s.resize(sz_new);
341  if (sz == 1 && sz_new > sz)
342  for (ordinal_type i=1; i<sz_new; i++)
343  s[i] = s[0];
344  }
345 
347 
356  KOKKOS_INLINE_FUNCTION
357  void copyForWrite() volatile { }
358 
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;
366  bool eq = true;
367  for (ordinal_type i=0; i<this->size(); i++)
368  eq = eq && IE::eval(x.coeff(i), this->coeff(i));
369  return eq;
370  }
371 
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;
379  bool eq = true;
380  for (ordinal_type i=0; i<this->size(); i++)
381  eq = eq && IE::eval(x.coeff(i), this->coeff(i));
382  return eq;
383  }
384 
389 
391 
394  Vector& operator=(std::initializer_list<value_type> l) {
395  const ordinal_type lsz = l.size();
396  if (lsz != s.size())
397  s.resize(lsz);
398  s.init(l.begin(), lsz);
399  return *this;
400  }
401 
403 
406  /*volatile*/ Vector&
407  operator=(std::initializer_list<value_type> l) volatile {
408  const ordinal_type lsz = l.size();
409  if (lsz != s.size())
410  s.resize(lsz);
411  s.init(l.begin(), lsz);
412  return const_cast<Vector&>(*this);
413  }
414 
416  KOKKOS_INLINE_FUNCTION
417  Vector& operator=(const value_type& x) {
418  s.init(x);
419  return *this;
420  }
421 
423  KOKKOS_INLINE_FUNCTION
424  /*volatile*/ Vector& operator=(const value_type& x) volatile {
425  s.init(x);
426  return const_cast<Vector&>(*this);
427  }
428 
430  KOKKOS_INLINE_FUNCTION
431  Vector& operator=(const Vector& x) {
432  if (this != &x) {
433  s = x.s;
434 
435  // For DyamicStorage as a view (is_owned=false), we need to set
436  // the trailing entries when assigning a constant vector (because
437  // the copy constructor in this case doesn't reset the size of this)
438  //
439  // Note: supporting this technically makes the Vector non-POD, even
440  // with a static storage type where this branch will get optimized
441  // out. We would have to remove DynamicStorage-as-a view as an option
442  // or partial specialize on StaticFixedStorage to fix this. However
443  // the volatile operator=() and copy constructor overloads make
444  // Vector non-POD anyway.
445  if (s.size() > x.s.size())
446  for (ordinal_type i=x.s.size(); i<s.size(); i++)
447  s[i] = s[0];
448  }
449 
450  return *this;
451  }
452 
454  KOKKOS_INLINE_FUNCTION
455  Vector& operator=(const volatile Vector& x) {
456  if (this != &x) {
457  s = x.s;
458 
459  // For DyamicStorage as a view (is_owned=false), we need to set
460  // the trailing entries when assigning a constant vector (because
461  // the copy constructor in this case doesn't reset the size of this)
462  //
463  // Note: supporting this technically makes the Vector non-POD, even
464  // with a static storage type where this branch will get optimized
465  // out. We would have to remove DynamicStorage-as-a view as an option
466  // or partial specialize on StaticFixedStorage to fix this. However
467  // the volatile operator=() and copy constructor overloads make
468  // Vector non-POD anyway.
469  if (s.size() > x.s.size())
470  for (ordinal_type i=x.s.size(); i<s.size(); i++)
471  s[i] = s[0];
472  }
473 
474  return *this;
475  }
476 
478  KOKKOS_INLINE_FUNCTION
479  /*volatile*/ Vector& operator=(const Vector& x) volatile {
480  if (this != &x) {
481  s = x.s;
482 
483  // For DyamicStorage as a view (is_owned=false), we need to set
484  // the trailing entries when assigning a constant vector (because
485  // the copy constructor in this case doesn't reset the size of this)
486  //
487  // Note: supporting this technically makes the Vector non-POD, even
488  // with a static storage type where this branch will get optimized
489  // out. We would have to remove DynamicStorage-as-a view as an option
490  // or partial specialize on StaticFixedStorage to fix this. However
491  // the volatile operator=() and copy constructor overloads make
492  // Vector non-POD anyway.
493  if (s.size() > x.s.size())
494  for (ordinal_type i=x.s.size(); i<s.size(); i++)
495  s[i] = s[0];
496  }
497 
498  return const_cast<Vector&>(*this);
499  }
500 
502  KOKKOS_INLINE_FUNCTION
503  /*volatile*/ Vector& operator=(const volatile Vector& x) volatile {
504  if (this != &x) {
505  s = x.s;
506 
507  // For DyamicStorage as a view (is_owned=false), we need to set
508  // the trailing entries when assigning a constant vector (because
509  // the copy constructor in this case doesn't reset the size of this)
510  //
511  // Note: supporting this technically makes the Vector non-POD, even
512  // with a static storage type where this branch will get optimized
513  // out. We would have to remove DynamicStorage-as-a view as an option
514  // or partial specialize on StaticFixedStorage to fix this. However
515  // the volatile operator=() and copy constructor overloads make
516  // Vector non-POD anyway.
517  if (s.size() > x.s.size())
518  for (ordinal_type i=x.s.size(); i<s.size(); i++)
519  s[i] = s[0];
520  }
521 
522  return const_cast<Vector&>(*this);
523  }
524 
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();
531 
532  this->reset(x.size());
533 
534 #ifdef STOKHOS_DEBUG
535  if (s.size() != x.size())
536  Kokkos::Impl::raise_error("Vector::operator=(): Mismatched sizes");
537 #endif
538 
539  if (x.hasFastAccess(s.size())) {
540 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
541 #pragma ivdep
542 #endif
543 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
544 #pragma vector aligned
545 #endif
546 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
547 #pragma unroll
548 #endif
549  for (ordinal_type i=0; i<s.size(); i++)
550  s[i] = x.fastAccessCoeff(i);
551  }
552  else {
553  for (ordinal_type i=0; i<s.size(); i++)
554  s[i] = x.coeff(i);
555  }
556  return *this;
557  }
558 
560  template <typename S>
561  KOKKOS_INLINE_FUNCTION
562  /*volatile*/ Vector& operator=(const Expr<S>& xx) volatile {
563  typedef typename Expr<S>::derived_type expr_type;
564  const expr_type& x = xx.derived();
565 
566  this->reset(x.size());
567 
568 #ifdef STOKHOS_DEBUG
569  if (s.size() != x.size())
570  Kokkos::Impl::raise_error("Vector::operator=(): Mismatched sizes");
571 #endif
572 
573  if (x.hasFastAccess(s.size())) {
574 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
575 #pragma ivdep
576 #endif
577 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
578 #pragma vector aligned
579 #endif
580 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
581 #pragma unroll
582 #endif
583  for (ordinal_type i=0; i<s.size(); i++)
584  s[i] = x.fastAccessCoeff(i);
585  }
586  else {
587  for (ordinal_type i=0; i<s.size(); i++)
588  s[i] = x.coeff(i);
589  }
590  return const_cast<Vector&>(*this);
591  }
592 
594  template< typename S >
595  KOKKOS_INLINE_FUNCTION
596  typename Kokkos::Impl::enable_if<( ! Kokkos::Impl::is_same<S,void>::value &&
598  ), Vector >
599  ::type const & operator = ( const Expr<S> & xx ) const
600  {
601  const typename Expr<S>::derived_type & x = xx.derived();
602 
603 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
604 #pragma ivdep
605 #endif
606 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
607 #pragma vector aligned
608 #endif
609 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
610 #pragma unroll
611 #endif
612  for ( ordinal_type i = 0 ; i < s.size() ; ++i ) { s[i] = x.coeff(i); }
613 
614  return *this ;
615  }
616 
618  template< typename S >
619  KOKKOS_INLINE_FUNCTION
620  volatile
621  typename Kokkos::Impl::enable_if<( ! Kokkos::Impl::is_same<S,void>::value &&
623  ), Vector >
624  ::type const & operator = ( const Expr<S> & xx ) const volatile
625  {
626  const typename Expr<S>::derived_type & x = xx.derived();
627 
628 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
629 #pragma ivdep
630 #endif
631 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
632 #pragma vector aligned
633 #endif
634 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
635 #pragma unroll
636 #endif
637  for ( ordinal_type i = 0 ; i < s.size() ; ++i ) { s[i] = x.coeff(i); }
638 
639  return *this ;
640  }
641 
643 
648  KOKKOS_INLINE_FUNCTION
650  const volatile storage_type& storage() const volatile { return s; }
651 
653  KOKKOS_INLINE_FUNCTION
654  const storage_type& storage() const { return s; }
655 
657  KOKKOS_INLINE_FUNCTION
658  volatile storage_type& storage() volatile { return s; }
659 
661  KOKKOS_INLINE_FUNCTION
662  storage_type& storage() { return s; }
663 
668 
670  KOKKOS_INLINE_FUNCTION
671  const_volatile_reference val() const volatile { return s[0]; }
672 
674  KOKKOS_INLINE_FUNCTION
675  const_reference val() const { return s[0]; }
676 
678  KOKKOS_INLINE_FUNCTION
679  volatile_reference val() volatile { return s[0]; }
680 
682  KOKKOS_INLINE_FUNCTION
683  reference val() { return s[0]; }
684 
686 
691 
693  KOKKOS_INLINE_FUNCTION
694  ordinal_type size() const { return s.size();}
695 
697  KOKKOS_INLINE_FUNCTION
698  ordinal_type size() const volatile { return s.size();}
699 
701  KOKKOS_INLINE_FUNCTION
702  bool hasFastAccess(ordinal_type sz) const { return s.size()>=sz;}
703 
705  KOKKOS_INLINE_FUNCTION
706  bool hasFastAccess(ordinal_type sz) const volatile { return s.size()>=sz;}
707 
709  KOKKOS_INLINE_FUNCTION
710  const_pointer coeff() const { return s.coeff();}
711 
713  KOKKOS_INLINE_FUNCTION
714  const_volatile_pointer coeff() const volatile { return s.coeff();}
715 
717  KOKKOS_INLINE_FUNCTION
718  volatile_pointer coeff() volatile { return s.coeff();}
719 
721  KOKKOS_INLINE_FUNCTION
722  pointer coeff() { return s.coeff();}
723 
725  KOKKOS_INLINE_FUNCTION
726  value_type coeff(ordinal_type i) const volatile {
727  return i<s.size() ? s[i] : s[0]; }
728 
730  KOKKOS_INLINE_FUNCTION
731  value_type coeff(ordinal_type i) const {
732  return i<s.size() ? s[i] : s[0]; }
733 
735  KOKKOS_INLINE_FUNCTION
736  value_type coeff(ordinal_type i) volatile {
737  return i<s.size() ? s[i] : s[0]; }
738 
740  KOKKOS_INLINE_FUNCTION
741  value_type coeff(ordinal_type i) {
742  return i<s.size() ? s[i] : s[0]; }
743 
745  KOKKOS_INLINE_FUNCTION
746  const_volatile_reference fastAccessCoeff(ordinal_type i) const volatile {
747  return s[i];}
748 
750  KOKKOS_INLINE_FUNCTION
751  const_reference fastAccessCoeff(ordinal_type i) const {
752  return s[i];}
753 
755  KOKKOS_INLINE_FUNCTION
756  volatile_reference fastAccessCoeff(ordinal_type i) volatile {
757  return s[i];}
758 
760  KOKKOS_INLINE_FUNCTION
761  reference fastAccessCoeff(ordinal_type i) {
762  return s[i];}
763 
765  KOKKOS_INLINE_FUNCTION
766  const_volatile_reference operator[](ordinal_type i) const volatile {
767  return s[i];}
768 
770  KOKKOS_INLINE_FUNCTION
771  const_reference operator[](ordinal_type i) const {
772  return s[i];}
773 
775  KOKKOS_INLINE_FUNCTION
776  volatile_reference operator[](ordinal_type i) volatile {
777  return s[i];}
778 
780  KOKKOS_INLINE_FUNCTION
781  reference operator[](ordinal_type i) {
782  return s[i];}
783 
784  template <int i>
785  KOKKOS_INLINE_FUNCTION
786  value_type getCoeff() const volatile {
787  return s.template getCoeff<i>(); }
788 
789  template <int i>
790  KOKKOS_INLINE_FUNCTION
791  value_type getCoeff() const {
792  return s.template getCoeff<i>(); }
793 
794  template <int i>
795  KOKKOS_INLINE_FUNCTION
796  volatile_reference getCoeff() volatile {
797  return s.template getCoeff<i>(); }
798 
799  template <int i>
800  KOKKOS_INLINE_FUNCTION
801  reference getCoeff() {
802  return s.template getCoeff<i>(); }
803 
805  KOKKOS_INLINE_FUNCTION
806  pointer begin() { return s.coeff(); }
807 
809  KOKKOS_INLINE_FUNCTION
810  const_pointer begin() const { return s.coeff(); }
811 
813  KOKKOS_INLINE_FUNCTION
814  volatile_pointer begin() volatile { return s.coeff(); }
815 
817  KOKKOS_INLINE_FUNCTION
818  const_volatile_pointer begin() const volatile { return s.coeff(); }
819 
821  KOKKOS_INLINE_FUNCTION
822  const_pointer cbegin() const { return s.coeff(); }
823 
825  KOKKOS_INLINE_FUNCTION
826  const_volatile_pointer cbegin() const volatile { return s.coeff(); }
827 
829  KOKKOS_INLINE_FUNCTION
830  pointer end() { return s.coeff() + s.size(); }
831 
833  KOKKOS_INLINE_FUNCTION
834  const_pointer end() const { return s.coeff() + s.size(); }
835 
837  KOKKOS_INLINE_FUNCTION
838  volatile_pointer end() volatile { return s.coeff() + s.size(); }
839 
841  KOKKOS_INLINE_FUNCTION
842  const_volatile_pointer end() const volatile { return s.coeff() + s.size(); }
843 
845  KOKKOS_INLINE_FUNCTION
846  const_pointer cend() const { return s.coeff()+ s.size(); }
847 
849  KOKKOS_INLINE_FUNCTION
850  const_volatile_pointer cend() const volatile { return s.coeff()+ s.size(); }
851 
853 
858 
860  KOKKOS_INLINE_FUNCTION
861  Vector& operator += (const value_type& x) {
862 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
863 #pragma ivdep
864 #endif
865 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
866 #pragma vector aligned
867 #endif
868 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
869 #pragma unroll
870 #endif
871  for (ordinal_type i=0; i<s.size(); i++)
872  s[i] += x;
873  return *this;
874  }
875 
877  KOKKOS_INLINE_FUNCTION
878  Vector& operator += (const volatile value_type& x) {
879 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
880 #pragma ivdep
881 #endif
882 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
883 #pragma vector aligned
884 #endif
885 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
886 #pragma unroll
887 #endif
888  for (ordinal_type i=0; i<s.size(); i++)
889  s[i] += x;
890  return *this;
891  }
892 
894  KOKKOS_INLINE_FUNCTION
895  /*volatile*/ Vector& operator += (const value_type& x) volatile {
896 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
897 #pragma ivdep
898 #endif
899 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
900 #pragma vector aligned
901 #endif
902 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
903 #pragma unroll
904 #endif
905  for (ordinal_type i=0; i<s.size(); i++)
906  s[i] += x;
907  return const_cast<Vector&>(*this);
908  }
909 
911  KOKKOS_INLINE_FUNCTION
912  /*volatile*/ Vector& operator += (const volatile value_type& x) volatile {
913 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
914 #pragma ivdep
915 #endif
916 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
917 #pragma vector aligned
918 #endif
919 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
920 #pragma unroll
921 #endif
922  for (ordinal_type i=0; i<s.size(); i++)
923  s[i] += x;
924  return const_cast<Vector&>(*this);
925  }
926 
928  KOKKOS_INLINE_FUNCTION
929  Vector& operator -= (const value_type& x) {
930 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
931 #pragma ivdep
932 #endif
933 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
934 #pragma vector aligned
935 #endif
936 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
937 #pragma unroll
938 #endif
939  for (ordinal_type i=0; i<s.size(); i++)
940  s[i] -= x;
941  return *this;
942  }
943 
945  KOKKOS_INLINE_FUNCTION
946  Vector& operator -= (const volatile value_type& x) {
947 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
948 #pragma ivdep
949 #endif
950 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
951 #pragma vector aligned
952 #endif
953 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
954 #pragma unroll
955 #endif
956  for (ordinal_type i=0; i<s.size(); i++)
957  s[i] -= x;
958  return *this;
959  }
960 
962  KOKKOS_INLINE_FUNCTION
963  /*volatile*/ Vector& operator -= (const value_type& x) volatile {
964 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
965 #pragma ivdep
966 #endif
967 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
968 #pragma vector aligned
969 #endif
970 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
971 #pragma unroll
972 #endif
973  for (ordinal_type i=0; i<s.size(); i++)
974  s[i] -= x;
975  return const_cast<Vector&>(*this);
976  }
977 
979  KOKKOS_INLINE_FUNCTION
980  /*volatile*/ Vector& operator -= (const volatile value_type& x) volatile {
981 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
982 #pragma ivdep
983 #endif
984 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
985 #pragma vector aligned
986 #endif
987 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
988 #pragma unroll
989 #endif
990  for (ordinal_type i=0; i<s.size(); i++)
991  s[i] -= x;
992  return const_cast<Vector&>(*this);
993  }
994 
996  KOKKOS_INLINE_FUNCTION
997  Vector& operator *= (const value_type& x) {
998 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
999 #pragma ivdep
1000 #endif
1001 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1002 #pragma vector aligned
1003 #endif
1004 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1005 #pragma unroll
1006 #endif
1007  for (ordinal_type i=0; i<s.size(); i++)
1008  s[i] *= x;
1009  return *this;
1010  }
1011 
1013  KOKKOS_INLINE_FUNCTION
1014  Vector& operator *= (const volatile value_type& x) {
1015 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1016 #pragma ivdep
1017 #endif
1018 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1019 #pragma vector aligned
1020 #endif
1021 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1022 #pragma unroll
1023 #endif
1024  for (ordinal_type i=0; i<s.size(); i++)
1025  s[i] *= x;
1026  return *this;
1027  }
1028 
1030  KOKKOS_INLINE_FUNCTION
1031  /*volatile*/ Vector& operator *= (const value_type& x) volatile {
1032 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1033 #pragma ivdep
1034 #endif
1035 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1036 #pragma vector aligned
1037 #endif
1038 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1039 #pragma unroll
1040 #endif
1041  for (ordinal_type i=0; i<s.size(); i++)
1042  s[i] *= x;
1043  return const_cast<Vector&>(*this);
1044  }
1045 
1047  KOKKOS_INLINE_FUNCTION
1048  /*volatile*/ Vector& operator *= (const volatile value_type& x) volatile {
1049 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1050 #pragma ivdep
1051 #endif
1052 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1053 #pragma vector aligned
1054 #endif
1055 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1056 #pragma unroll
1057 #endif
1058  for (ordinal_type i=0; i<s.size(); i++)
1059  s[i] *= x;
1060  return const_cast<Vector&>(*this);
1061  }
1062 
1064  KOKKOS_INLINE_FUNCTION
1065  Vector& operator /= (const value_type& x) {
1066 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1067 #pragma ivdep
1068 #endif
1069 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1070 #pragma vector aligned
1071 #endif
1072 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1073 #pragma unroll
1074 #endif
1075  for (ordinal_type i=0; i<s.size(); i++)
1076  s[i] /= x;
1077  return *this;
1078  }
1079 
1081  KOKKOS_INLINE_FUNCTION
1082  Vector& operator /= (const volatile value_type& x) {
1083 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1084 #pragma ivdep
1085 #endif
1086 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1087 #pragma vector aligned
1088 #endif
1089 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1090 #pragma unroll
1091 #endif
1092  for (ordinal_type i=0; i<s.size(); i++)
1093  s[i] /= x;
1094  return *this;
1095  }
1096 
1098  KOKKOS_INLINE_FUNCTION
1099  /*volatile*/ Vector& operator /= (const value_type& x) volatile {
1100 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1101 #pragma ivdep
1102 #endif
1103 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1104 #pragma vector aligned
1105 #endif
1106 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1107 #pragma unroll
1108 #endif
1109  for (ordinal_type i=0; i<s.size(); i++)
1110  s[i] /= x;
1111  return const_cast<Vector&>(*this);
1112  }
1113 
1115  KOKKOS_INLINE_FUNCTION
1116  /*volatile*/ Vector& operator /= (const volatile value_type& x) volatile {
1117 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1118 #pragma ivdep
1119 #endif
1120 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1121 #pragma vector aligned
1122 #endif
1123 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1124 #pragma unroll
1125 #endif
1126  for (ordinal_type i=0; i<s.size(); i++)
1127  s[i] /= x;
1128  return const_cast<Vector&>(*this);
1129  }
1130 
1132  template <typename S>
1133  KOKKOS_INLINE_FUNCTION
1134  Vector& operator += (const Expr<S>& xx) {
1135  //*this = *this + x;
1136  typedef typename Expr<S>::derived_type expr_type;
1137  const expr_type& x = xx.derived();
1138 
1139  if (x.size() > s.size())
1140  this->reset(x.size());
1141 
1142 #ifdef STOKHOS_DEBUG
1143  if (s.size() < x.size())
1144  Kokkos::Impl::raise_error("Vector::operator+=(): Mismatched sizes");
1145 #endif
1146 
1147  if (x.hasFastAccess(s.size())) {
1148 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1149 #pragma ivdep
1150 #endif
1151 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1152 #pragma vector aligned
1153 #endif
1154 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1155 #pragma unroll
1156 #endif
1157  for (ordinal_type i=0; i<s.size(); i++)
1158  s[i] += x.fastAccessCoeff(i);
1159  }
1160  else {
1161  for (ordinal_type i=0; i<s.size(); i++)
1162  s[i] += x.coeff(i);
1163  }
1164  return *this;
1165  }
1166 
1168  template <typename S>
1169  KOKKOS_INLINE_FUNCTION
1170  Vector& operator += (const volatile Expr<S>& xx) {
1171  //*this = *this + x;
1172  typedef typename Expr<S>::derived_type expr_type;
1173  const volatile expr_type& x = xx.derived();
1174 
1175  if (x.size() > s.size())
1176  this->reset(x.size());
1177 
1178 #ifdef STOKHOS_DEBUG
1179  if (s.size() < x.size())
1180  Kokkos::Impl::raise_error("Vector::operator+=(): Mismatched sizes");
1181 #endif
1182 
1183  if (x.hasFastAccess(s.size())) {
1184 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1185 #pragma ivdep
1186 #endif
1187 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1188 #pragma vector aligned
1189 #endif
1190 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1191 #pragma unroll
1192 #endif
1193  for (ordinal_type i=0; i<s.size(); i++)
1194  s[i] += x.fastAccessCoeff(i);
1195  }
1196  else {
1197  for (ordinal_type i=0; i<s.size(); i++)
1198  s[i] += x.coeff(i);
1199  }
1200  return *this;
1201  }
1202 
1204  template <typename S>
1205  KOKKOS_INLINE_FUNCTION
1206  /*volatile*/ Vector& operator += (const Expr<S>& xx) volatile {
1207  //*this = *this + x;
1208  typedef typename Expr<S>::derived_type expr_type;
1209  const expr_type& x = xx.derived();
1210 
1211  if (x.size() > s.size())
1212  this->reset(x.size());
1213 
1214 #ifdef STOKHOS_DEBUG
1215  if (s.size() < x.size())
1216  Kokkos::Impl::raise_error("Vector::operator+=(): Mismatched sizes");
1217 #endif
1218 
1219  if (x.hasFastAccess(s.size())) {
1220 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1221 #pragma ivdep
1222 #endif
1223 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1224 #pragma vector aligned
1225 #endif
1226 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1227 #pragma unroll
1228 #endif
1229  for (ordinal_type i=0; i<s.size(); i++)
1230  s[i] += x.fastAccessCoeff(i);
1231  }
1232  else {
1233  for (ordinal_type i=0; i<s.size(); i++)
1234  s[i] += x.coeff(i);
1235  }
1236  return const_cast<Vector&>(*this);
1237  }
1238 
1240  template <typename S>
1241  KOKKOS_INLINE_FUNCTION
1242  /*volatile*/ Vector& operator += (const volatile Expr<S>& xx) volatile {
1243  //*this = *this + x;
1244  typedef typename Expr<S>::derived_type expr_type;
1245  const volatile expr_type& x = xx.derived();
1246 
1247  if (x.size() > s.size())
1248  this->reset(x.size());
1249 
1250 #ifdef STOKHOS_DEBUG
1251  if (s.size() < x.size())
1252  Kokkos::Impl::raise_error("Vector::operator+=(): Mismatched sizes");
1253 #endif
1254 
1255  if (x.hasFastAccess(s.size())) {
1256 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1257 #pragma ivdep
1258 #endif
1259 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1260 #pragma vector aligned
1261 #endif
1262 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1263 #pragma unroll
1264 #endif
1265  for (ordinal_type i=0; i<s.size(); i++)
1266  s[i] += x.fastAccessCoeff(i);
1267  }
1268  else {
1269  for (ordinal_type i=0; i<s.size(); i++)
1270  s[i] += x.coeff(i);
1271  }
1272  return const_cast<Vector&>(*this);
1273  }
1274 
1276  template <typename S>
1277  KOKKOS_INLINE_FUNCTION
1278  Vector& operator -= (const Expr<S>& xx) {
1279  //*this = *this - x;
1280  typedef typename Expr<S>::derived_type expr_type;
1281  const expr_type& x = xx.derived();
1282 
1283  if (x.size() > s.size())
1284  this->reset(x.size());
1285 
1286 #ifdef STOKHOS_DEBUG
1287  if (s.size() < x.size())
1288  Kokkos::Impl::raise_error("Vector::operator-=(): Mismatched sizes");
1289 #endif
1290 
1291  if (x.hasFastAccess(s.size())) {
1292 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1293 #pragma ivdep
1294 #endif
1295 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1296 #pragma vector aligned
1297 #endif
1298 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1299 #pragma unroll
1300 #endif
1301  for (ordinal_type i=0; i<s.size(); i++)
1302  s[i] -= x.fastAccessCoeff(i);
1303  }
1304  else {
1305  for (ordinal_type i=0; i<s.size(); i++)
1306  s[i] -= x.coeff(i);
1307  }
1308  return *this;
1309  }
1310 
1312  template <typename S>
1313  KOKKOS_INLINE_FUNCTION
1314  Vector& operator -= (const volatile Expr<S>& xx) {
1315  //*this = *this - x;
1316  typedef typename Expr<S>::derived_type expr_type;
1317  const volatile expr_type& x = xx.derived();
1318 
1319  if (x.size() > s.size())
1320  this->reset(x.size());
1321 
1322 #ifdef STOKHOS_DEBUG
1323  if (s.size() < x.size())
1324  Kokkos::Impl::raise_error("Vector::operator-=(): Mismatched sizes");
1325 #endif
1326 
1327  if (x.hasFastAccess(s.size())) {
1328 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1329 #pragma ivdep
1330 #endif
1331 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1332 #pragma vector aligned
1333 #endif
1334 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1335 #pragma unroll
1336 #endif
1337  for (ordinal_type i=0; i<s.size(); i++)
1338  s[i] -= x.fastAccessCoeff(i);
1339  }
1340  else {
1341  for (ordinal_type i=0; i<s.size(); i++)
1342  s[i] -= x.coeff(i);
1343  }
1344  return *this;
1345  }
1346 
1348  template <typename S>
1349  KOKKOS_INLINE_FUNCTION
1350  /*volatile*/ Vector& operator -= (const Expr<S>& xx) volatile {
1351  //*this = *this - x;
1352  typedef typename Expr<S>::derived_type expr_type;
1353  const expr_type& x = xx.derived();
1354 
1355  if (x.size() > s.size())
1356  this->reset(x.size());
1357 
1358 #ifdef STOKHOS_DEBUG
1359  if (s.size() < x.size())
1360  Kokkos::Impl::raise_error("Vector::operator-=(): Mismatched sizes");
1361 #endif
1362 
1363  if (x.hasFastAccess(s.size())) {
1364 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1365 #pragma ivdep
1366 #endif
1367 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1368 #pragma vector aligned
1369 #endif
1370 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1371 #pragma unroll
1372 #endif
1373  for (ordinal_type i=0; i<s.size(); i++)
1374  s[i] -= x.fastAccessCoeff(i);
1375  }
1376  else {
1377  for (ordinal_type i=0; i<s.size(); i++)
1378  s[i] -= x.coeff(i);
1379  }
1380  return const_cast<Vector&>(*this);
1381  }
1382 
1384  template <typename S>
1385  KOKKOS_INLINE_FUNCTION
1386  /*volatile*/ Vector& operator -= (const volatile Expr<S>& xx) volatile {
1387  //*this = *this - x;
1388  typedef typename Expr<S>::derived_type expr_type;
1389  const volatile expr_type& x = xx.derived();
1390 
1391  if (x.size() > s.size())
1392  this->reset(x.size());
1393 
1394 #ifdef STOKHOS_DEBUG
1395  if (s.size() < x.size())
1396  Kokkos::Impl::raise_error("Vector::operator-=(): Mismatched sizes");
1397 #endif
1398 
1399  if (x.hasFastAccess(s.size())) {
1400 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1401 #pragma ivdep
1402 #endif
1403 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1404 #pragma vector aligned
1405 #endif
1406 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1407 #pragma unroll
1408 #endif
1409  for (ordinal_type i=0; i<s.size(); i++)
1410  s[i] -= x.fastAccessCoeff(i);
1411  }
1412  else {
1413  for (ordinal_type i=0; i<s.size(); i++)
1414  s[i] -= x.coeff(i);
1415  }
1416  return const_cast<Vector&>(*this);
1417  }
1418 
1420  template <typename S>
1421  KOKKOS_INLINE_FUNCTION
1422  Vector& operator *= (const Expr<S>& xx) {
1423  //*this = *this * x;
1424  typedef typename Expr<S>::derived_type expr_type;
1425  const expr_type& x = xx.derived();
1426 
1427  if (x.size() > s.size())
1428  this->reset(x.size());
1429 
1430 #ifdef STOKHOS_DEBUG
1431  if (s.size() < x.size())
1432  Kokkos::Impl::raise_error("Vector::operator*=(): Mismatched sizes");
1433 #endif
1434 
1435  if (x.hasFastAccess(s.size())) {
1436 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1437 #pragma ivdep
1438 #endif
1439 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1440 #pragma vector aligned
1441 #endif
1442 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1443 #pragma unroll
1444 #endif
1445  for (ordinal_type i=0; i<s.size(); i++)
1446  s[i] *= x.fastAccessCoeff(i);
1447  }
1448  else {
1449  for (ordinal_type i=0; i<s.size(); i++)
1450  s[i] *= x.coeff(i);
1451  }
1452  return *this;
1453  }
1454 
1456  template <typename S>
1457  KOKKOS_INLINE_FUNCTION
1458  Vector& operator *= (const volatile Expr<S>& xx) {
1459  //*this = *this * x;
1460  typedef typename Expr<S>::derived_type expr_type;
1461  const volatile expr_type& x = xx.derived();
1462 
1463  if (x.size() > s.size())
1464  this->reset(x.size());
1465 
1466 #ifdef STOKHOS_DEBUG
1467  if (s.size() < x.size())
1468  Kokkos::Impl::raise_error("Vector::operator*=(): Mismatched sizes");
1469 #endif
1470 
1471  if (x.hasFastAccess(s.size())) {
1472 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1473 #pragma ivdep
1474 #endif
1475 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1476 #pragma vector aligned
1477 #endif
1478 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1479 #pragma unroll
1480 #endif
1481  for (ordinal_type i=0; i<s.size(); i++)
1482  s[i] *= x.fastAccessCoeff(i);
1483  }
1484  else {
1485  for (ordinal_type i=0; i<s.size(); i++)
1486  s[i] *= x.coeff(i);
1487  }
1488  return *this;
1489  }
1490 
1492  template <typename S>
1493  KOKKOS_INLINE_FUNCTION
1494  /*volatile*/ Vector& operator *= (const Expr<S>& xx) volatile {
1495  //*this = *this * x;
1496  typedef typename Expr<S>::derived_type expr_type;
1497  const expr_type& x = xx.derived();
1498 
1499  if (x.size() > s.size())
1500  this->reset(x.size());
1501 
1502 #ifdef STOKHOS_DEBUG
1503  if (s.size() < x.size())
1504  Kokkos::Impl::raise_error("Vector::operator*=(): Mismatched sizes");
1505 #endif
1506 
1507  if (x.hasFastAccess(s.size())) {
1508 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1509 #pragma ivdep
1510 #endif
1511 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1512 #pragma vector aligned
1513 #endif
1514 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1515 #pragma unroll
1516 #endif
1517  for (ordinal_type i=0; i<s.size(); i++)
1518  s[i] *= x.fastAccessCoeff(i);
1519  }
1520  else {
1521  for (ordinal_type i=0; i<s.size(); i++)
1522  s[i] *= x.coeff(i);
1523  }
1524  return const_cast<Vector&>(*this);
1525  }
1526 
1528  template <typename S>
1529  KOKKOS_INLINE_FUNCTION
1530  /*volatile*/ Vector& operator *= (const volatile Expr<S>& xx) volatile {
1531  //*this = *this * x;
1532  typedef typename Expr<S>::derived_type expr_type;
1533  const volatile expr_type& x = xx.derived();
1534 
1535  if (x.size() > s.size())
1536  this->reset(x.size());
1537 
1538 #ifdef STOKHOS_DEBUG
1539  if (s.size() < x.size())
1540  Kokkos::Impl::raise_error("Vector::operator*=(): Mismatched sizes");
1541 #endif
1542 
1543  if (x.hasFastAccess(s.size())) {
1544 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1545 #pragma ivdep
1546 #endif
1547 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1548 #pragma vector aligned
1549 #endif
1550 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1551 #pragma unroll
1552 #endif
1553  for (ordinal_type i=0; i<s.size(); i++)
1554  s[i] *= x.fastAccessCoeff(i);
1555  }
1556  else {
1557  for (ordinal_type i=0; i<s.size(); i++)
1558  s[i] *= x.coeff(i);
1559  }
1560  return const_cast<Vector&>(*this);
1561  }
1562 
1564  template <typename S>
1565  KOKKOS_INLINE_FUNCTION
1566  Vector& operator /= (const Expr<S>& xx) {
1567  //*this = *this / x;
1568  typedef typename Expr<S>::derived_type expr_type;
1569  const expr_type& x = xx.derived();
1570 
1571  if (x.size() > s.size())
1572  this->reset(x.size());
1573 
1574 #ifdef STOKHOS_DEBUG
1575  if (s.size() < x.size())
1576  Kokkos::Impl::raise_error("Vector::operator/=(): Mismatched sizes");
1577 #endif
1578 
1579  if (x.hasFastAccess(s.size())) {
1580 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1581 #pragma ivdep
1582 #endif
1583 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1584 #pragma vector aligned
1585 #endif
1586 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1587 #pragma unroll
1588 #endif
1589  for (ordinal_type i=0; i<s.size(); i++)
1590  s[i] /= x.fastAccessCoeff(i);
1591  }
1592  else {
1593  for (ordinal_type i=0; i<s.size(); i++)
1594  s[i] /= x.coeff(i);
1595  }
1596  return *this;
1597  }
1598 
1600  template <typename S>
1601  KOKKOS_INLINE_FUNCTION
1602  Vector& operator /= (const volatile Expr<S>& xx) {
1603  //*this = *this / x;
1604  typedef typename Expr<S>::derived_type expr_type;
1605  const volatile expr_type& x = xx.derived();
1606 
1607  if (x.size() > s.size())
1608  this->reset(x.size());
1609 
1610 #ifdef STOKHOS_DEBUG
1611  if (s.size() < x.size())
1612  Kokkos::Impl::raise_error("Vector::operator/=(): Mismatched sizes");
1613 #endif
1614 
1615  if (x.hasFastAccess(s.size())) {
1616 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1617 #pragma ivdep
1618 #endif
1619 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1620 #pragma vector aligned
1621 #endif
1622 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1623 #pragma unroll
1624 #endif
1625  for (ordinal_type i=0; i<s.size(); i++)
1626  s[i] /= x.fastAccessCoeff(i);
1627  }
1628  else {
1629  for (ordinal_type i=0; i<s.size(); i++)
1630  s[i] /= x.coeff(i);
1631  }
1632  return *this;
1633  }
1634 
1636  template <typename S>
1637  KOKKOS_INLINE_FUNCTION
1638  /*volatile*/ Vector& operator /= (const Expr<S>& xx) volatile {
1639  //*this = *this / x;
1640  typedef typename Expr<S>::derived_type expr_type;
1641  const expr_type& x = xx.derived();
1642 
1643  if (x.size() > s.size())
1644  this->reset(x.size());
1645 
1646 #ifdef STOKHOS_DEBUG
1647  if (s.size() < x.size())
1648  Kokkos::Impl::raise_error("Vector::operator/=(): Mismatched sizes");
1649 #endif
1650 
1651  if (x.hasFastAccess(s.size())) {
1652 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1653 #pragma ivdep
1654 #endif
1655 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1656 #pragma vector aligned
1657 #endif
1658 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1659 #pragma unroll
1660 #endif
1661  for (ordinal_type i=0; i<s.size(); i++)
1662  s[i] /= x.fastAccessCoeff(i);
1663  }
1664  else {
1665  for (ordinal_type i=0; i<s.size(); i++)
1666  s[i] /= x.coeff(i);
1667  }
1668  return const_cast<Vector&>(*this);
1669  }
1670 
1672  template <typename S>
1673  KOKKOS_INLINE_FUNCTION
1674  /*volatile*/ Vector& operator /= (const volatile Expr<S>& xx) volatile {
1675  //*this = *this / x;
1676  typedef typename Expr<S>::derived_type expr_type;
1677  const volatile expr_type& x = xx.derived();
1678 
1679  if (x.size() > s.size())
1680  this->reset(x.size());
1681 
1682 #ifdef STOKHOS_DEBUG
1683  if (s.size() < x.size())
1684  Kokkos::Impl::raise_error("Vector::operator/=(): Mismatched sizes");
1685 #endif
1686 
1687  if (x.hasFastAccess(s.size())) {
1688 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1689 #pragma ivdep
1690 #endif
1691 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1692 #pragma vector aligned
1693 #endif
1694 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1695 #pragma unroll
1696 #endif
1697  for (ordinal_type i=0; i<s.size(); i++)
1698  s[i] /= x.fastAccessCoeff(i);
1699  }
1700  else {
1701  for (ordinal_type i=0; i<s.size(); i++)
1702  s[i] /= x.coeff(i);
1703  }
1704  return const_cast<Vector&>(*this);
1705  }
1706 
1708  KOKKOS_INLINE_FUNCTION
1709  Vector& operator++() {
1710  for (ordinal_type i=0; i<s.size(); i++)
1711  ++(s[i]);
1712  return *this;
1713  }
1714 
1716  KOKKOS_INLINE_FUNCTION
1717  volatile Vector& operator++() volatile {
1718  for (ordinal_type i=0; i<s.size(); i++)
1719  ++(s[i]);
1720  return *this;
1721  }
1722 
1724  KOKKOS_INLINE_FUNCTION
1725  Vector operator++(int) {
1726  Vector tmp(*this);
1727  ++(*this);
1728  return tmp;
1729  }
1730 
1732  KOKKOS_INLINE_FUNCTION
1733  Vector operator++(int) volatile {
1734  Vector tmp(*this);
1735  ++(*this);
1736  return tmp;
1737  }
1738 
1740  KOKKOS_INLINE_FUNCTION
1741  Vector& operator--() {
1742  for (ordinal_type i=0; i<s.size(); i++)
1743  --(s[i]);
1744  return *this;
1745  }
1746 
1748  KOKKOS_INLINE_FUNCTION
1749  volatile Vector& operator--() volatile {
1750  for (ordinal_type i=0; i<s.size(); i++)
1751  --(s[i]);
1752  return *this;
1753  }
1754 
1756  KOKKOS_INLINE_FUNCTION
1757  Vector operator--(int) {
1758  Vector tmp(*this);
1759  --(*this);
1760  return tmp;
1761  }
1762 
1764  KOKKOS_INLINE_FUNCTION
1765  Vector operator--(int) volatile {
1766  Vector tmp(*this);
1767  --(*this);
1768  return tmp;
1769  }
1770 
1772 
1773  KOKKOS_INLINE_FUNCTION
1774  std::string name() const volatile { return "x"; }
1775 
1776  protected:
1777 
1778  Storage s;
1779 
1780  template <typename expr_type>
1781  struct StaticOp {
1782  storage_type& s;
1783  const expr_type& x;
1784 
1785  KOKKOS_INLINE_FUNCTION
1786  StaticOp(storage_type& s_, const expr_type& x_) : s(s_), x(x_) {}
1787 
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>();
1793  }
1794 
1795  };
1796 
1797  }; // class Vector
1798  }
1799 }
1800 
1801 #if STOKHOS_USE_MP_VECTOR_SFS_SPEC
1802 #include "Sacado_MP_Vector_SFS.hpp"
1803 #endif
1804 
1805 namespace Sacado{
1806  namespace MP {
1807 
1809 
1813  template <typename T> struct const_expr_ref {
1814  typedef const T type;
1815  };
1816 
1818 
1822  template <typename S> struct const_expr_ref< Vector<S> > {
1823  typedef const Vector<S>& type;
1824  };
1825 
1827 
1831  template <typename S> struct const_expr_ref< volatile Vector<S> > {
1832  typedef const volatile Vector<S>& type;
1833  };
1834 
1836  template <typename T> struct remove_volatile {
1837  typedef T type;
1838  };
1839  template <typename T> struct remove_volatile<volatile T> {
1840  typedef T type;
1841  };
1842 
1844  template <typename T> struct add_volatile {
1845  typedef volatile T type;
1846  };
1847  template <typename T> struct add_volatile<volatile T> {
1848  typedef volatile T type;
1849  };
1850 
1851  template <typename Storage>
1852  std::ostream&
1853  operator << (std::ostream& os, const Vector<Storage>& a)
1854  {
1856 
1857  os << "[ ";
1858 
1859  for (ordinal_type i=0; i<a.size(); i++) {
1860  os << a.coeff(i) << " ";
1861  }
1862 
1863  os << "]";
1864  return os;
1865  }
1866 
1867  template <typename Storage>
1868  std::ostream&
1869  operator << (std::ostream& os, const volatile Vector<Storage>& a)
1870  {
1872 
1873  os << "[ ";
1874 
1875  for (ordinal_type i=0; i<a.size(); i++) {
1876  os << a.coeff(i) << " ";
1877  }
1878 
1879  os << "]";
1880  return os;
1881  }
1882 
1883  template <typename Storage>
1884  std::istream&
1885  operator >> (std::istream& is, Vector<Storage>& a)
1886  {
1888  typedef typename Vector<Storage>::value_type value_type;
1889 
1890  //
1891  // Need to check all of this for errors, end-of-line, etc...
1892  //
1893 
1894  char b = 0;
1895  if (Storage::is_static) {
1896  is >> b; // "["
1897  for (ordinal_type i=0; i<a.size(); i++) {
1898  is >> a.fastAccessCoeff(i);
1899  }
1900  is >> b; // "]";
1901  }
1902  else {
1903  std::vector<value_type> c;
1904  value_type v;
1905  is >> b; // "["
1906  while (is >> b && b != ']') {
1907  is.putback(b);
1908  is >> v;
1909  c.push_back(v);
1910  }
1911  ordinal_type n = c.size();
1912  a.reset(n);
1913  for (ordinal_type i=0; i<n; ++i)
1914  a.fastAccessCoeff(i) = c[i];
1915  }
1916 
1917  return is;
1918  }
1919 
1920  //------------------------------------------------------------------------
1921  //------------------------------------------------------------------------
1922 
1924  template <unsigned Size = 0>
1925  struct VectorPartition {
1926  static const unsigned PartitionSize = Size;
1927  unsigned begin ;
1928  unsigned end ;
1929 
1930  template< typename iType0 , typename iType1 >
1931  KOKKOS_INLINE_FUNCTION
1932  VectorPartition( const iType0 & i0 , const iType1 & i1 ) :
1933  begin(i0), end(i1) {
1934  }
1935  };
1936 
1937  template <typename T>
1938  struct is_vector_partition {
1939  static const bool value = false;
1940  };
1941 
1942  template <unsigned Size>
1943  struct is_vector_partition< VectorPartition<Size> > {
1944  static const bool value = true;
1945  };
1946 
1947  } // namespace MP
1948 
1949  template <typename T>
1950  struct IsExpr< MP::Expr<T> > {
1951  static const bool value = true;
1952  };
1953 
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;
1958  };
1959 
1960  template <typename S>
1961  struct IsExpr< MP::Vector<S> > {
1962  static const bool value = true;
1963  };
1964 
1965  template <typename S>
1966  struct BaseExprType< MP::Vector<S> > {
1967  typedef MP::Vector<S> type;
1968  };
1969 
1971  template <typename T> struct is_mp_vector {
1972  static const bool value = false;
1973  };
1974  template <typename S> struct is_mp_vector< MP::Vector<S> > {
1975  static const bool value = true;
1976  };
1977  template <typename T> struct is_mp_vector< const T > {
1978  static const bool value = is_mp_vector<T>::value;
1979  };
1980  template <typename T> struct is_mp_vector< T* > {
1981  static const bool value = is_mp_vector<T>::value;
1982  };
1983  template <typename T> struct is_mp_vector< T[] > {
1984  static const bool value = is_mp_vector<T>::value;
1985  };
1986  template <typename T, unsigned N> struct is_mp_vector< T[N] > {
1987  static const bool value = is_mp_vector<T>::value;
1988  };
1989 
1990  // Utility function to see if a MP::Vector is really a constant
1991  template <typename Storage>
1993  {
1994  typedef typename Storage::ordinal_type ordinal_type;
1995  typedef typename Storage::value_type value_type;
1996 
1997  // All size-1 vectors are constants
1998  const ordinal_type sz = x.size();
1999  if (sz == 1) return true;
2000 
2001  // Maybe use a tolerance????
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;
2005 
2006  return true;
2007  }
2008 
2009 } // namespace Sacado
2010 
2011 #include "Sacado_MP_Vector_ops.hpp"
2012 
2013 #if STOKHOS_ALIGN_MEMORY
2014 
2015 #include <memory>
2016 
2017 namespace std {
2018 
2019 template <typename Storage>
2020 class allocator< Sacado::MP::Vector< Storage > >
2021  : public Stokhos::aligned_allocator< Sacado::MP::Vector< Storage > > {
2022 public:
2023  typedef Sacado::MP::Vector<Storage> T;
2024  typedef Stokhos::aligned_allocator<T> Base;
2025  typedef typename Base::value_type value_type;
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;
2032 
2033  template <class U> struct rebind { typedef allocator<U> other; };
2034  allocator() {}
2035  template <class U> allocator(const allocator<U>&) {}
2036 };
2037 
2038 template <typename Storage>
2039 class allocator< const Sacado::MP::Vector< Storage > >
2040  : public Stokhos::aligned_allocator< const Sacado::MP::Vector< Storage > > {
2041 public:
2042  typedef Sacado::MP::Vector<Storage> T;
2044  typedef typename Base::value_type value_type;
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;
2051 
2052  template <class U> struct rebind { typedef allocator<U> other; };
2053  allocator() {}
2054  template <class U> allocator(const allocator<U>&) {}
2055 };
2056 
2057 }
2058 
2059 #endif
2060 
2061 #endif // HAVE_STOKHOS_SACADO
2062 
2063 #include "Kokkos_NumericTraits.hpp"
2064 
2065 namespace Kokkos {
2066 
2067 template <typename Storage>
2068 struct reduction_identity< Sacado::MP::Vector<Storage> > {
2070  typedef typename Storage::value_type scalar;
2071  typedef reduction_identity<scalar> RIS;
2072  KOKKOS_FORCEINLINE_FUNCTION constexpr static Vector sum() {
2073  return Vector(RIS::sum());
2074  }
2075  KOKKOS_FORCEINLINE_FUNCTION constexpr static Vector prod() {
2076  return Vector(RIS::prod());
2077  }
2078  KOKKOS_FORCEINLINE_FUNCTION constexpr static Vector max() {
2079  return Vector(RIS::max());
2080  }
2081  KOKKOS_FORCEINLINE_FUNCTION constexpr static Vector min() {
2082  return Vector(RIS::min());
2083  }
2084 };
2085 
2086 }
2087 
2088 #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)
KOKKOS_FORCEINLINE_FUNCTION static constexpr Vector sum()
std::istream & operator>>(std::istream &is, PCE< Storage > &a)
KOKKOS_FORCEINLINE_FUNCTION static constexpr Vector min()
KOKKOS_INLINE_FUNCTION PCE< Storage > max(const typename PCE< Storage >::value_type &a, const PCE< Storage > &b)
Traits class encapsulting memory alignment.
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)
expr val()
KOKKOS_FORCEINLINE_FUNCTION static constexpr Vector max()
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)