Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
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 // ivdep is necessary to get the intel compiler to vectorize through
66 // expresion template assignent operators
67 #if defined(__INTEL_COMPILER) && ! defined(__CUDA_ARCH__)
68 #define STOKHOS_HAVE_PRAGMA_IVDEP
69 #endif
70 
71 // unrolling appears to slow everything down
72 #if 0 && ( defined(__INTEL_COMPILER) || defined(__CUDA_ARCH__) )
73 #define STOKHOS_HAVE_PRAGMA_UNROLL
74 #endif
75 
76 namespace Sacado {
77 
79  namespace MP {
80 
82 
95  template <typename T>
96  class Expr {
97  public:
98 
100 
104  typedef T derived_type;
105 
107 
111  KOKKOS_INLINE_FUNCTION
112  const derived_type& derived() const {
113  return static_cast<const derived_type&>(*this);
114  }
115 
117 
121  KOKKOS_INLINE_FUNCTION
122  const volatile derived_type& derived() const volatile {
123  return static_cast<const volatile derived_type&>(*this);
124  }
125 
126  };
127 
129  template <typename Storage>
130  class Vector : public Expr< Vector<Storage> > {
131  public:
132 
134  typedef Storage storage_type;
135 
136  typedef typename storage_type::value_type value_type;
137  typedef typename storage_type::ordinal_type ordinal_type;
139  typedef typename storage_type::pointer pointer;
140  typedef typename storage_type::volatile_pointer volatile_pointer;
141  typedef typename storage_type::const_pointer const_pointer;
142  typedef typename storage_type::const_volatile_pointer const_volatile_pointer;
143  typedef typename storage_type::reference reference;
144  typedef typename storage_type::volatile_reference volatile_reference;
145  typedef typename storage_type::const_reference const_reference;
146  typedef typename storage_type::const_volatile_reference const_volatile_reference;
147 
148  typedef typename execution_space::memory_space memory_space;
149  typedef typename Stokhos::MemoryTraits<memory_space> MemTraits;
150 
152  typedef typename ScalarType<value_type>::type scalar_type;
153 
154  typedef Vector base_expr_type;
155 
157  template < class NewStorageType >
158  struct apply {
159  typedef Vector< NewStorageType > type;
160  };
161 
163  static const int num_args = 1;
164 
165 #if STOKHOS_ALIGN_MEMORY
166  KOKKOS_INLINE_FUNCTION
167  static void* operator new(std::size_t sz) {
168  return MemTraits::alloc(sz);
169  }
170  KOKKOS_INLINE_FUNCTION
171  static void* operator new[](std::size_t sz) {
172  return MemTraits::alloc(sz);
173  }
174  KOKKOS_INLINE_FUNCTION
175  static void* operator new(std::size_t sz, void* ptr) {
176  return ptr;
177  }
178  KOKKOS_INLINE_FUNCTION
179  static void* operator new[](std::size_t sz, void* ptr) {
180  return ptr;
181  }
182  KOKKOS_INLINE_FUNCTION
183  static void operator delete(void* ptr) {
184  MemTraits::free(ptr);
185  }
186  KOKKOS_INLINE_FUNCTION
187  static void operator delete[](void* ptr) {
188  MemTraits::free(ptr);
189  }
190  KOKKOS_INLINE_FUNCTION
191  static void operator delete(void* ptr, void*) {
192  MemTraits::free(ptr);
193  }
194  KOKKOS_INLINE_FUNCTION
195  static void operator delete[](void* ptr, void*) {
196  MemTraits::free(ptr);
197  }
198 #endif
199 
201 
204  KOKKOS_INLINE_FUNCTION
205  Vector() = default;
206 
208 
211  KOKKOS_INLINE_FUNCTION
212  Vector(const value_type& x) : s(1) { s.init(x); }
213 
215 
219  KOKKOS_INLINE_FUNCTION
220  Vector(ordinal_type sz, pointer v, bool owned) : s(sz,v,owned) {}
221 
223 
226  KOKKOS_INLINE_FUNCTION
227  Vector(ordinal_type sz, const value_type& x) : s(sz,x) {}
228 
230  KOKKOS_INLINE_FUNCTION
231  Vector(const storage_type& ss) : s(ss) {}
232 
234  KOKKOS_INLINE_FUNCTION
235  Vector(const Vector& x) = default;
236 
238  KOKKOS_INLINE_FUNCTION
239  Vector(const volatile Vector& x) : s(x.s) {}
240 
242  template <typename S>
243  KOKKOS_INLINE_FUNCTION
244  Vector(const Expr<S>& xx) :
245  s(xx.derived().size()) {
246  typedef typename Expr<S>::derived_type expr_type;
247  const expr_type& x = xx.derived();
248 
249 #ifdef STOKHOS_DEBUG
250  if (s.size() != x.size())
251  Kokkos::Impl::raise_error("Vector(): Mismatched sizes");
252 #endif
253 
254  if (x.hasFastAccess(s.size())) {
255 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
256 #pragma ivdep
257 #endif
258 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
259 #pragma unroll
260 #endif
261  for (ordinal_type i=0; i<s.size(); i++)
262  s[i] = x.fastAccessCoeff(i);
263  }
264  else {
265  for (ordinal_type i=0; i<s.size(); i++)
266  s[i] = x.coeff(i);
267  }
268  }
269 
271 
274  Vector(std::initializer_list<value_type> l) : s(l.size(), l.begin()) {}
275 
277  KOKKOS_INLINE_FUNCTION
278  ~Vector() = default;
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  KOKKOS_INLINE_FUNCTION
290  void init(const value_type* v) { s.init(v); }
291 
293  KOKKOS_INLINE_FUNCTION
294  void init(const value_type* v) volatile { s.init(v); }
295 
297  template <typename S>
298  KOKKOS_INLINE_FUNCTION
299  void init(const Vector<S>& v) {
300  s.init(v.s.coeff(), v.s.size());
301  }
302 
304  template <typename S>
305  KOKKOS_INLINE_FUNCTION
306  void init(const Vector<S>& v) volatile {
307  s.init(v.s.coeff(), v.s.size());
308  }
309 
311  KOKKOS_INLINE_FUNCTION
312  void load(value_type* v) { s.load(v); }
313 
315  KOKKOS_INLINE_FUNCTION
316  void load(value_type* v) volatile { s.load(v); }
317 
319  template <typename S>
320  KOKKOS_INLINE_FUNCTION
321  void load(Vector<S>& v) { s.load(v.s.coeff()); }
322 
324  template <typename S>
325  KOKKOS_INLINE_FUNCTION
326  void load(Vector<S>& v) volatile { s.load(v.s.coeff()); }
327 
329 
332  KOKKOS_INLINE_FUNCTION
333  void reset(ordinal_type sz_new) {
334  ordinal_type sz = this->size();
335  s.resize(sz_new);
336  if (sz == 1 && sz_new > sz)
337  for (ordinal_type i=1; i<sz_new; i++)
338  s[i] = s[0];
339  }
340 
342 
345  KOKKOS_INLINE_FUNCTION
346  void reset(ordinal_type sz_new) volatile {
347  ordinal_type sz = this->size();
348  s.resize(sz_new);
349  if (sz == 1 && sz_new > sz)
350  for (ordinal_type i=1; i<sz_new; i++)
351  s[i] = s[0];
352  }
353 
355 
364  KOKKOS_INLINE_FUNCTION
365  void copyForWrite() volatile { }
366 
368  template <typename S>
369  KOKKOS_INLINE_FUNCTION
370  bool isEqualTo(const Expr<S>& xx) const {
371  const typename Expr<S>::derived_type& x = xx.derived();
372  typedef IsEqual<value_type> IE;
373  if (x.size() != this->size()) return false;
374  bool eq = true;
375  for (ordinal_type i=0; i<this->size(); i++)
376  eq = eq && IE::eval(x.coeff(i), this->coeff(i));
377  return eq;
378  }
379 
381  template <typename S>
382  KOKKOS_INLINE_FUNCTION
383  bool isEqualTo(const Expr<S>& xx) const volatile {
384  const typename Expr<S>::derived_type& x = xx.derived();
385  typedef IsEqual<value_type> IE;
386  if (x.size() != this->size()) return false;
387  bool eq = true;
388  for (ordinal_type i=0; i<this->size(); i++)
389  eq = eq && IE::eval(x.coeff(i), this->coeff(i));
390  return eq;
391  }
392 
397 
399 
402  Vector& operator=(std::initializer_list<value_type> l) {
403  const ordinal_type lsz = l.size();
404  if (lsz != s.size())
405  s.resize(lsz);
406  s.init(l.begin(), lsz);
407  return *this;
408  }
409 
411 
414  /*volatile*/ Vector&
415  operator=(std::initializer_list<value_type> l) volatile {
416  const ordinal_type lsz = l.size();
417  if (lsz != s.size())
418  s.resize(lsz);
419  s.init(l.begin(), lsz);
420  return const_cast<Vector&>(*this);
421  }
422 
424  KOKKOS_INLINE_FUNCTION
425  Vector& operator=(const value_type& x) {
426  s.init(x);
427  return *this;
428  }
429 
431  KOKKOS_INLINE_FUNCTION
432  /*volatile*/ Vector& operator=(const value_type& x) volatile {
433  s.init(x);
434  return const_cast<Vector&>(*this);
435  }
436 
438  KOKKOS_INLINE_FUNCTION
439  Vector& operator=(const Vector& x) {
440  if (this != &x) {
441  s = x.s;
442 
443  // For DyamicStorage as a view (is_owned=false), we need to set
444  // the trailing entries when assigning a constant vector (because
445  // the copy constructor in this case doesn't reset the size of this)
446  //
447  // Note: supporting this technically makes the Vector non-POD, even
448  // with a static storage type where this branch will get optimized
449  // out. We would have to remove DynamicStorage-as-a view as an option
450  // or partial specialize on StaticFixedStorage to fix this. However
451  // the volatile operator=() and copy constructor overloads make
452  // Vector non-POD anyway.
453  if (s.size() > x.s.size())
454  for (ordinal_type i=x.s.size(); i<s.size(); i++)
455  s[i] = s[0];
456  }
457 
458  return *this;
459  }
460 
462  KOKKOS_INLINE_FUNCTION
463  Vector& operator=(const volatile Vector& x) {
464  if (this != &x) {
465  s = x.s;
466 
467  // For DyamicStorage as a view (is_owned=false), we need to set
468  // the trailing entries when assigning a constant vector (because
469  // the copy constructor in this case doesn't reset the size of this)
470  //
471  // Note: supporting this technically makes the Vector non-POD, even
472  // with a static storage type where this branch will get optimized
473  // out. We would have to remove DynamicStorage-as-a view as an option
474  // or partial specialize on StaticFixedStorage to fix this. However
475  // the volatile operator=() and copy constructor overloads make
476  // Vector non-POD anyway.
477  if (s.size() > x.s.size())
478  for (ordinal_type i=x.s.size(); i<s.size(); i++)
479  s[i] = s[0];
480  }
481 
482  return *this;
483  }
484 
486  KOKKOS_INLINE_FUNCTION
487  /*volatile*/ Vector& operator=(const Vector& x) volatile {
488  if (this != &x) {
489  s = x.s;
490 
491  // For DyamicStorage as a view (is_owned=false), we need to set
492  // the trailing entries when assigning a constant vector (because
493  // the copy constructor in this case doesn't reset the size of this)
494  //
495  // Note: supporting this technically makes the Vector non-POD, even
496  // with a static storage type where this branch will get optimized
497  // out. We would have to remove DynamicStorage-as-a view as an option
498  // or partial specialize on StaticFixedStorage to fix this. However
499  // the volatile operator=() and copy constructor overloads make
500  // Vector non-POD anyway.
501  if (s.size() > x.s.size())
502  for (ordinal_type i=x.s.size(); i<s.size(); i++)
503  s[i] = s[0];
504  }
505 
506  return const_cast<Vector&>(*this);
507  }
508 
510  KOKKOS_INLINE_FUNCTION
511  /*volatile*/ Vector& operator=(const volatile Vector& x) volatile {
512  if (this != &x) {
513  s = x.s;
514 
515  // For DyamicStorage as a view (is_owned=false), we need to set
516  // the trailing entries when assigning a constant vector (because
517  // the copy constructor in this case doesn't reset the size of this)
518  //
519  // Note: supporting this technically makes the Vector non-POD, even
520  // with a static storage type where this branch will get optimized
521  // out. We would have to remove DynamicStorage-as-a view as an option
522  // or partial specialize on StaticFixedStorage to fix this. However
523  // the volatile operator=() and copy constructor overloads make
524  // Vector non-POD anyway.
525  if (s.size() > x.s.size())
526  for (ordinal_type i=x.s.size(); i<s.size(); i++)
527  s[i] = s[0];
528  }
529 
530  return const_cast<Vector&>(*this);
531  }
532 
534  template <typename S>
535  KOKKOS_INLINE_FUNCTION
536  Vector& operator=(const Expr<S>& xx) {
537  typedef typename Expr<S>::derived_type expr_type;
538  const expr_type& x = xx.derived();
539 
540  this->reset(x.size());
541 
542 #ifdef STOKHOS_DEBUG
543  if (s.size() != x.size())
544  Kokkos::Impl::raise_error("Vector::operator=(): Mismatched sizes");
545 #endif
546 
547  if (x.hasFastAccess(s.size())) {
548 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
549 #pragma ivdep
550 #endif
551 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
552 #pragma unroll
553 #endif
554  for (ordinal_type i=0; i<s.size(); i++)
555  s[i] = x.fastAccessCoeff(i);
556  }
557  else {
558  for (ordinal_type i=0; i<s.size(); i++)
559  s[i] = x.coeff(i);
560  }
561  return *this;
562  }
563 
565  template <typename S>
566  KOKKOS_INLINE_FUNCTION
567  /*volatile*/ Vector& operator=(const Expr<S>& xx) volatile {
568  typedef typename Expr<S>::derived_type expr_type;
569  const expr_type& x = xx.derived();
570 
571  this->reset(x.size());
572 
573 #ifdef STOKHOS_DEBUG
574  if (s.size() != x.size())
575  Kokkos::Impl::raise_error("Vector::operator=(): Mismatched sizes");
576 #endif
577 
578  if (x.hasFastAccess(s.size())) {
579 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
580 #pragma ivdep
581 #endif
582 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
583 #pragma unroll
584 #endif
585  for (ordinal_type i=0; i<s.size(); i++)
586  s[i] = x.fastAccessCoeff(i);
587  }
588  else {
589  for (ordinal_type i=0; i<s.size(); i++)
590  s[i] = x.coeff(i);
591  }
592  return const_cast<Vector&>(*this);
593  }
594 
596  template< typename S >
597  KOKKOS_INLINE_FUNCTION
598  typename Kokkos::Impl::enable_if<( ! Kokkos::Impl::is_same<S,void>::value &&
600  ), Vector >
601  ::type const & operator = ( const Expr<S> & xx ) const
602  {
603  const typename Expr<S>::derived_type & x = xx.derived();
604 
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 Kokkos::Impl::enable_if<( ! Kokkos::Impl::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  for ( ordinal_type i = 0 ; i < s.size() ; ++i ) { s[i] = x.coeff(i); }
622 
623  return *this ;
624  }
625 
627 
632  KOKKOS_INLINE_FUNCTION
634  const volatile storage_type& storage() const volatile { return s; }
635 
637  KOKKOS_INLINE_FUNCTION
638  const storage_type& storage() const { return s; }
639 
641  KOKKOS_INLINE_FUNCTION
642  volatile storage_type& storage() volatile { return s; }
643 
645  KOKKOS_INLINE_FUNCTION
646  storage_type& storage() { return s; }
647 
652 
654  KOKKOS_INLINE_FUNCTION
655  const_volatile_reference val() const volatile { return s[0]; }
656 
658  KOKKOS_INLINE_FUNCTION
659  const_reference val() const { return s[0]; }
660 
662  KOKKOS_INLINE_FUNCTION
663  volatile_reference val() volatile { return s[0]; }
664 
666  KOKKOS_INLINE_FUNCTION
667  reference val() { return s[0]; }
668 
670 
675 
677  KOKKOS_INLINE_FUNCTION
678  ordinal_type size() const { return s.size();}
679 
681  KOKKOS_INLINE_FUNCTION
682  ordinal_type size() const volatile { return s.size();}
683 
685  KOKKOS_INLINE_FUNCTION
686  bool hasFastAccess(ordinal_type sz) const { return s.size()>=sz;}
687 
689  KOKKOS_INLINE_FUNCTION
690  bool hasFastAccess(ordinal_type sz) const volatile { return s.size()>=sz;}
691 
693  KOKKOS_INLINE_FUNCTION
694  const_pointer coeff() const { return s.coeff();}
695 
697  KOKKOS_INLINE_FUNCTION
698  const_volatile_pointer coeff() const volatile { return s.coeff();}
699 
701  KOKKOS_INLINE_FUNCTION
702  volatile_pointer coeff() volatile { return s.coeff();}
703 
705  KOKKOS_INLINE_FUNCTION
706  pointer coeff() { return s.coeff();}
707 
709  KOKKOS_INLINE_FUNCTION
710  value_type coeff(ordinal_type i) const volatile {
711  return i<s.size() ? s[i] : s[0]; }
712 
714  KOKKOS_INLINE_FUNCTION
715  value_type coeff(ordinal_type i) const {
716  return i<s.size() ? s[i] : s[0]; }
717 
719  KOKKOS_INLINE_FUNCTION
720  value_type coeff(ordinal_type i) volatile {
721  return i<s.size() ? s[i] : s[0]; }
722 
724  KOKKOS_INLINE_FUNCTION
725  value_type coeff(ordinal_type i) {
726  return i<s.size() ? s[i] : s[0]; }
727 
729  KOKKOS_INLINE_FUNCTION
730  const_volatile_reference fastAccessCoeff(ordinal_type i) const volatile {
731  return s[i];}
732 
734  KOKKOS_INLINE_FUNCTION
735  const_reference fastAccessCoeff(ordinal_type i) const {
736  return s[i];}
737 
739  KOKKOS_INLINE_FUNCTION
740  volatile_reference fastAccessCoeff(ordinal_type i) volatile {
741  return s[i];}
742 
744  KOKKOS_INLINE_FUNCTION
745  reference fastAccessCoeff(ordinal_type i) {
746  return s[i];}
747 
748  template <int i>
749  KOKKOS_INLINE_FUNCTION
750  value_type getCoeff() const volatile {
751  return s.template getCoeff<i>(); }
752 
753  template <int i>
754  KOKKOS_INLINE_FUNCTION
755  value_type getCoeff() const {
756  return s.template getCoeff<i>(); }
757 
758  template <int i>
759  KOKKOS_INLINE_FUNCTION
760  volatile_reference getCoeff() volatile {
761  return s.template getCoeff<i>(); }
762 
763  template <int i>
764  KOKKOS_INLINE_FUNCTION
765  reference getCoeff() {
766  return s.template getCoeff<i>(); }
767 
769  KOKKOS_INLINE_FUNCTION
770  pointer begin() { return s.coeff(); }
771 
773  KOKKOS_INLINE_FUNCTION
774  const_pointer begin() const { return s.coeff(); }
775 
777  KOKKOS_INLINE_FUNCTION
778  volatile_pointer begin() volatile { return s.coeff(); }
779 
781  KOKKOS_INLINE_FUNCTION
782  const_volatile_pointer begin() const volatile { return s.coeff(); }
783 
785  KOKKOS_INLINE_FUNCTION
786  const_pointer cbegin() const { return s.coeff(); }
787 
789  KOKKOS_INLINE_FUNCTION
790  const_volatile_pointer cbegin() const volatile { return s.coeff(); }
791 
793  KOKKOS_INLINE_FUNCTION
794  pointer end() { return s.coeff() + s.size(); }
795 
797  KOKKOS_INLINE_FUNCTION
798  const_pointer end() const { return s.coeff() + s.size(); }
799 
801  KOKKOS_INLINE_FUNCTION
802  volatile_pointer end() volatile { return s.coeff() + s.size(); }
803 
805  KOKKOS_INLINE_FUNCTION
806  const_volatile_pointer end() const volatile { return s.coeff() + s.size(); }
807 
809  KOKKOS_INLINE_FUNCTION
810  const_pointer cend() const { return s.coeff()+ s.size(); }
811 
813  KOKKOS_INLINE_FUNCTION
814  const_volatile_pointer cend() const volatile { return s.coeff()+ s.size(); }
815 
817 
822 
824  KOKKOS_INLINE_FUNCTION
825  Vector& operator += (const value_type& x) {
826  for (ordinal_type i=0; i<s.size(); i++)
827  s[i] += x;
828  return *this;
829  }
830 
832  KOKKOS_INLINE_FUNCTION
833  Vector& operator += (const volatile value_type& x) {
834  for (ordinal_type i=0; i<s.size(); i++)
835  s[i] += x;
836  return *this;
837  }
838 
840  KOKKOS_INLINE_FUNCTION
841  /*volatile*/ Vector& operator += (const value_type& x) volatile {
842  for (ordinal_type i=0; i<s.size(); i++)
843  s[i] += x;
844  return const_cast<Vector&>(*this);
845  }
846 
848  KOKKOS_INLINE_FUNCTION
849  /*volatile*/ Vector& operator += (const volatile value_type& x) volatile {
850  for (ordinal_type i=0; i<s.size(); i++)
851  s[i] += x;
852  return const_cast<Vector&>(*this);
853  }
854 
856  KOKKOS_INLINE_FUNCTION
857  Vector& operator -= (const value_type& x) {
858  for (ordinal_type i=0; i<s.size(); i++)
859  s[i] -= x;
860  return *this;
861  }
862 
864  KOKKOS_INLINE_FUNCTION
865  Vector& operator -= (const volatile value_type& x) {
866  for (ordinal_type i=0; i<s.size(); i++)
867  s[i] -= x;
868  return *this;
869  }
870 
872  KOKKOS_INLINE_FUNCTION
873  /*volatile*/ Vector& operator -= (const value_type& x) volatile {
874  for (ordinal_type i=0; i<s.size(); i++)
875  s[i] -= x;
876  return const_cast<Vector&>(*this);
877  }
878 
880  KOKKOS_INLINE_FUNCTION
881  /*volatile*/ Vector& operator -= (const volatile value_type& x) volatile {
882  for (ordinal_type i=0; i<s.size(); i++)
883  s[i] -= x;
884  return const_cast<Vector&>(*this);
885  }
886 
888  KOKKOS_INLINE_FUNCTION
889  Vector& operator *= (const value_type& x) {
890  for (ordinal_type i=0; i<s.size(); i++)
891  s[i] *= x;
892  return *this;
893  }
894 
896  KOKKOS_INLINE_FUNCTION
897  Vector& operator *= (const volatile value_type& x) {
898  for (ordinal_type i=0; i<s.size(); i++)
899  s[i] *= x;
900  return *this;
901  }
902 
904  KOKKOS_INLINE_FUNCTION
905  /*volatile*/ Vector& operator *= (const value_type& x) volatile {
906  for (ordinal_type i=0; i<s.size(); i++)
907  s[i] *= x;
908  return const_cast<Vector&>(*this);
909  }
910 
912  KOKKOS_INLINE_FUNCTION
913  /*volatile*/ Vector& operator *= (const volatile value_type& x) volatile {
914  for (ordinal_type i=0; i<s.size(); i++)
915  s[i] *= x;
916  return const_cast<Vector&>(*this);
917  }
918 
920  KOKKOS_INLINE_FUNCTION
921  Vector& operator /= (const value_type& x) {
922  for (ordinal_type i=0; i<s.size(); i++)
923  s[i] /= x;
924  return *this;
925  }
926 
928  KOKKOS_INLINE_FUNCTION
929  Vector& operator /= (const volatile value_type& x) {
930  for (ordinal_type i=0; i<s.size(); i++)
931  s[i] /= x;
932  return *this;
933  }
934 
936  KOKKOS_INLINE_FUNCTION
937  /*volatile*/ Vector& operator /= (const value_type& x) volatile {
938  for (ordinal_type i=0; i<s.size(); i++)
939  s[i] /= x;
940  return const_cast<Vector&>(*this);
941  }
942 
944  KOKKOS_INLINE_FUNCTION
945  /*volatile*/ Vector& operator /= (const volatile value_type& x) volatile {
946  for (ordinal_type i=0; i<s.size(); i++)
947  s[i] /= x;
948  return const_cast<Vector&>(*this);
949  }
950 
952  template <typename S>
953  KOKKOS_INLINE_FUNCTION
954  Vector& operator += (const Expr<S>& xx) {
955  //*this = *this + x;
956  typedef typename Expr<S>::derived_type expr_type;
957  const expr_type& x = xx.derived();
958 
959  if (x.size() > s.size())
960  this->reset(x.size());
961 
962 #ifdef STOKHOS_DEBUG
963  if (s.size() < x.size())
964  Kokkos::Impl::raise_error("Vector::operator+=(): Mismatched sizes");
965 #endif
966 
967  if (x.hasFastAccess(s.size())) {
968 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
969 #pragma ivdep
970 #endif
971 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
972 #pragma unroll
973 #endif
974  for (ordinal_type i=0; i<s.size(); i++)
975  s[i] += x.fastAccessCoeff(i);
976  }
977  else {
978  for (ordinal_type i=0; i<s.size(); i++)
979  s[i] += x.coeff(i);
980  }
981  return *this;
982  }
983 
985  template <typename S>
986  KOKKOS_INLINE_FUNCTION
987  Vector& operator += (const volatile Expr<S>& xx) {
988  //*this = *this + x;
989  typedef typename Expr<S>::derived_type expr_type;
990  const volatile expr_type& x = xx.derived();
991 
992  if (x.size() > s.size())
993  this->reset(x.size());
994 
995 #ifdef STOKHOS_DEBUG
996  if (s.size() < x.size())
997  Kokkos::Impl::raise_error("Vector::operator+=(): Mismatched sizes");
998 #endif
999 
1000  if (x.hasFastAccess(s.size())) {
1001 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1002 #pragma ivdep
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.fastAccessCoeff(i);
1009  }
1010  else {
1011  for (ordinal_type i=0; i<s.size(); i++)
1012  s[i] += x.coeff(i);
1013  }
1014  return *this;
1015  }
1016 
1018  template <typename S>
1019  KOKKOS_INLINE_FUNCTION
1020  /*volatile*/ Vector& operator += (const Expr<S>& xx) volatile {
1021  //*this = *this + x;
1022  typedef typename Expr<S>::derived_type expr_type;
1023  const expr_type& x = xx.derived();
1024 
1025  if (x.size() > s.size())
1026  this->reset(x.size());
1027 
1028 #ifdef STOKHOS_DEBUG
1029  if (s.size() < x.size())
1030  Kokkos::Impl::raise_error("Vector::operator+=(): Mismatched sizes");
1031 #endif
1032 
1033  if (x.hasFastAccess(s.size())) {
1034 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1035 #pragma ivdep
1036 #endif
1037 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1038 #pragma unroll
1039 #endif
1040  for (ordinal_type i=0; i<s.size(); i++)
1041  s[i] += x.fastAccessCoeff(i);
1042  }
1043  else {
1044  for (ordinal_type i=0; i<s.size(); i++)
1045  s[i] += x.coeff(i);
1046  }
1047  return const_cast<Vector&>(*this);
1048  }
1049 
1051  template <typename S>
1052  KOKKOS_INLINE_FUNCTION
1053  /*volatile*/ Vector& operator += (const volatile Expr<S>& xx) volatile {
1054  //*this = *this + x;
1055  typedef typename Expr<S>::derived_type expr_type;
1056  const volatile expr_type& x = xx.derived();
1057 
1058  if (x.size() > s.size())
1059  this->reset(x.size());
1060 
1061 #ifdef STOKHOS_DEBUG
1062  if (s.size() < x.size())
1063  Kokkos::Impl::raise_error("Vector::operator+=(): Mismatched sizes");
1064 #endif
1065 
1066  if (x.hasFastAccess(s.size())) {
1067 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1068 #pragma ivdep
1069 #endif
1070 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1071 #pragma unroll
1072 #endif
1073  for (ordinal_type i=0; i<s.size(); i++)
1074  s[i] += x.fastAccessCoeff(i);
1075  }
1076  else {
1077  for (ordinal_type i=0; i<s.size(); i++)
1078  s[i] += x.coeff(i);
1079  }
1080  return const_cast<Vector&>(*this);
1081  }
1082 
1084  template <typename S>
1085  KOKKOS_INLINE_FUNCTION
1086  Vector& operator -= (const Expr<S>& xx) {
1087  //*this = *this - x;
1088  typedef typename Expr<S>::derived_type expr_type;
1089  const expr_type& x = xx.derived();
1090 
1091  if (x.size() > s.size())
1092  this->reset(x.size());
1093 
1094 #ifdef STOKHOS_DEBUG
1095  if (s.size() < x.size())
1096  Kokkos::Impl::raise_error("Vector::operator-=(): Mismatched sizes");
1097 #endif
1098 
1099  if (x.hasFastAccess(s.size())) {
1100 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1101 #pragma ivdep
1102 #endif
1103 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1104 #pragma unroll
1105 #endif
1106  for (ordinal_type i=0; i<s.size(); i++)
1107  s[i] -= x.fastAccessCoeff(i);
1108  }
1109  else {
1110  for (ordinal_type i=0; i<s.size(); i++)
1111  s[i] -= x.coeff(i);
1112  }
1113  return *this;
1114  }
1115 
1117  template <typename S>
1118  KOKKOS_INLINE_FUNCTION
1119  Vector& operator -= (const volatile Expr<S>& xx) {
1120  //*this = *this - x;
1121  typedef typename Expr<S>::derived_type expr_type;
1122  const volatile expr_type& x = xx.derived();
1123 
1124  if (x.size() > s.size())
1125  this->reset(x.size());
1126 
1127 #ifdef STOKHOS_DEBUG
1128  if (s.size() < x.size())
1129  Kokkos::Impl::raise_error("Vector::operator-=(): Mismatched sizes");
1130 #endif
1131 
1132  if (x.hasFastAccess(s.size())) {
1133 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1134 #pragma ivdep
1135 #endif
1136 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1137 #pragma unroll
1138 #endif
1139  for (ordinal_type i=0; i<s.size(); i++)
1140  s[i] -= x.fastAccessCoeff(i);
1141  }
1142  else {
1143  for (ordinal_type i=0; i<s.size(); i++)
1144  s[i] -= x.coeff(i);
1145  }
1146  return *this;
1147  }
1148 
1150  template <typename S>
1151  KOKKOS_INLINE_FUNCTION
1152  /*volatile*/ Vector& operator -= (const Expr<S>& xx) volatile {
1153  //*this = *this - x;
1154  typedef typename Expr<S>::derived_type expr_type;
1155  const expr_type& x = xx.derived();
1156 
1157  if (x.size() > s.size())
1158  this->reset(x.size());
1159 
1160 #ifdef STOKHOS_DEBUG
1161  if (s.size() < x.size())
1162  Kokkos::Impl::raise_error("Vector::operator-=(): Mismatched sizes");
1163 #endif
1164 
1165  if (x.hasFastAccess(s.size())) {
1166 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1167 #pragma ivdep
1168 #endif
1169 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1170 #pragma unroll
1171 #endif
1172  for (ordinal_type i=0; i<s.size(); i++)
1173  s[i] -= x.fastAccessCoeff(i);
1174  }
1175  else {
1176  for (ordinal_type i=0; i<s.size(); i++)
1177  s[i] -= x.coeff(i);
1178  }
1179  return const_cast<Vector&>(*this);
1180  }
1181 
1183  template <typename S>
1184  KOKKOS_INLINE_FUNCTION
1185  /*volatile*/ Vector& operator -= (const volatile Expr<S>& xx) volatile {
1186  //*this = *this - x;
1187  typedef typename Expr<S>::derived_type expr_type;
1188  const volatile expr_type& x = xx.derived();
1189 
1190  if (x.size() > s.size())
1191  this->reset(x.size());
1192 
1193 #ifdef STOKHOS_DEBUG
1194  if (s.size() < x.size())
1195  Kokkos::Impl::raise_error("Vector::operator-=(): Mismatched sizes");
1196 #endif
1197 
1198  if (x.hasFastAccess(s.size())) {
1199 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1200 #pragma ivdep
1201 #endif
1202 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1203 #pragma unroll
1204 #endif
1205  for (ordinal_type i=0; i<s.size(); i++)
1206  s[i] -= x.fastAccessCoeff(i);
1207  }
1208  else {
1209  for (ordinal_type i=0; i<s.size(); i++)
1210  s[i] -= x.coeff(i);
1211  }
1212  return const_cast<Vector&>(*this);
1213  }
1214 
1216  template <typename S>
1217  KOKKOS_INLINE_FUNCTION
1218  Vector& operator *= (const Expr<S>& xx) {
1219  //*this = *this * x;
1220  typedef typename Expr<S>::derived_type expr_type;
1221  const expr_type& x = xx.derived();
1222 
1223  if (x.size() > s.size())
1224  this->reset(x.size());
1225 
1226 #ifdef STOKHOS_DEBUG
1227  if (s.size() < x.size())
1228  Kokkos::Impl::raise_error("Vector::operator*=(): Mismatched sizes");
1229 #endif
1230 
1231  if (x.hasFastAccess(s.size())) {
1232 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1233 #pragma ivdep
1234 #endif
1235 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1236 #pragma unroll
1237 #endif
1238  for (ordinal_type i=0; i<s.size(); i++)
1239  s[i] *= x.fastAccessCoeff(i);
1240  }
1241  else {
1242  for (ordinal_type i=0; i<s.size(); i++)
1243  s[i] *= x.coeff(i);
1244  }
1245  return *this;
1246  }
1247 
1249  template <typename S>
1250  KOKKOS_INLINE_FUNCTION
1251  Vector& operator *= (const volatile Expr<S>& xx) {
1252  //*this = *this * x;
1253  typedef typename Expr<S>::derived_type expr_type;
1254  const volatile expr_type& x = xx.derived();
1255 
1256  if (x.size() > s.size())
1257  this->reset(x.size());
1258 
1259 #ifdef STOKHOS_DEBUG
1260  if (s.size() < x.size())
1261  Kokkos::Impl::raise_error("Vector::operator*=(): Mismatched sizes");
1262 #endif
1263 
1264  if (x.hasFastAccess(s.size())) {
1265 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1266 #pragma ivdep
1267 #endif
1268 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1269 #pragma unroll
1270 #endif
1271  for (ordinal_type i=0; i<s.size(); i++)
1272  s[i] *= x.fastAccessCoeff(i);
1273  }
1274  else {
1275  for (ordinal_type i=0; i<s.size(); i++)
1276  s[i] *= x.coeff(i);
1277  }
1278  return *this;
1279  }
1280 
1282  template <typename S>
1283  KOKKOS_INLINE_FUNCTION
1284  /*volatile*/ Vector& operator *= (const Expr<S>& xx) volatile {
1285  //*this = *this * x;
1286  typedef typename Expr<S>::derived_type expr_type;
1287  const expr_type& x = xx.derived();
1288 
1289  if (x.size() > s.size())
1290  this->reset(x.size());
1291 
1292 #ifdef STOKHOS_DEBUG
1293  if (s.size() < x.size())
1294  Kokkos::Impl::raise_error("Vector::operator*=(): Mismatched sizes");
1295 #endif
1296 
1297  if (x.hasFastAccess(s.size())) {
1298 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1299 #pragma ivdep
1300 #endif
1301 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1302 #pragma unroll
1303 #endif
1304  for (ordinal_type i=0; i<s.size(); i++)
1305  s[i] *= x.fastAccessCoeff(i);
1306  }
1307  else {
1308  for (ordinal_type i=0; i<s.size(); i++)
1309  s[i] *= x.coeff(i);
1310  }
1311  return const_cast<Vector&>(*this);
1312  }
1313 
1315  template <typename S>
1316  KOKKOS_INLINE_FUNCTION
1317  /*volatile*/ Vector& operator *= (const volatile Expr<S>& xx) volatile {
1318  //*this = *this * x;
1319  typedef typename Expr<S>::derived_type expr_type;
1320  const volatile expr_type& x = xx.derived();
1321 
1322  if (x.size() > s.size())
1323  this->reset(x.size());
1324 
1325 #ifdef STOKHOS_DEBUG
1326  if (s.size() < x.size())
1327  Kokkos::Impl::raise_error("Vector::operator*=(): Mismatched sizes");
1328 #endif
1329 
1330  if (x.hasFastAccess(s.size())) {
1331 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1332 #pragma ivdep
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 const_cast<Vector&>(*this);
1345  }
1346 
1348  template <typename S>
1349  KOKKOS_INLINE_FUNCTION
1350  Vector& operator /= (const Expr<S>& xx) {
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_UNROLL
1368 #pragma unroll
1369 #endif
1370  for (ordinal_type i=0; i<s.size(); i++)
1371  s[i] /= x.fastAccessCoeff(i);
1372  }
1373  else {
1374  for (ordinal_type i=0; i<s.size(); i++)
1375  s[i] /= x.coeff(i);
1376  }
1377  return *this;
1378  }
1379 
1381  template <typename S>
1382  KOKKOS_INLINE_FUNCTION
1383  Vector& operator /= (const volatile Expr<S>& xx) {
1384  //*this = *this / x;
1385  typedef typename Expr<S>::derived_type expr_type;
1386  const volatile expr_type& x = xx.derived();
1387 
1388  if (x.size() > s.size())
1389  this->reset(x.size());
1390 
1391 #ifdef STOKHOS_DEBUG
1392  if (s.size() < x.size())
1393  Kokkos::Impl::raise_error("Vector::operator/=(): Mismatched sizes");
1394 #endif
1395 
1396  if (x.hasFastAccess(s.size())) {
1397 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1398 #pragma ivdep
1399 #endif
1400 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1401 #pragma unroll
1402 #endif
1403  for (ordinal_type i=0; i<s.size(); i++)
1404  s[i] /= x.fastAccessCoeff(i);
1405  }
1406  else {
1407  for (ordinal_type i=0; i<s.size(); i++)
1408  s[i] /= x.coeff(i);
1409  }
1410  return *this;
1411  }
1412 
1414  template <typename S>
1415  KOKKOS_INLINE_FUNCTION
1416  /*volatile*/ Vector& operator /= (const Expr<S>& xx) volatile {
1417  //*this = *this / x;
1418  typedef typename Expr<S>::derived_type expr_type;
1419  const expr_type& x = xx.derived();
1420 
1421  if (x.size() > s.size())
1422  this->reset(x.size());
1423 
1424 #ifdef STOKHOS_DEBUG
1425  if (s.size() < x.size())
1426  Kokkos::Impl::raise_error("Vector::operator/=(): Mismatched sizes");
1427 #endif
1428 
1429  if (x.hasFastAccess(s.size())) {
1430 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1431 #pragma ivdep
1432 #endif
1433 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1434 #pragma unroll
1435 #endif
1436  for (ordinal_type i=0; i<s.size(); i++)
1437  s[i] /= x.fastAccessCoeff(i);
1438  }
1439  else {
1440  for (ordinal_type i=0; i<s.size(); i++)
1441  s[i] /= x.coeff(i);
1442  }
1443  return const_cast<Vector&>(*this);
1444  }
1445 
1447  template <typename S>
1448  KOKKOS_INLINE_FUNCTION
1449  /*volatile*/ Vector& operator /= (const volatile Expr<S>& xx) volatile {
1450  //*this = *this / x;
1451  typedef typename Expr<S>::derived_type expr_type;
1452  const volatile expr_type& x = xx.derived();
1453 
1454  if (x.size() > s.size())
1455  this->reset(x.size());
1456 
1457 #ifdef STOKHOS_DEBUG
1458  if (s.size() < x.size())
1459  Kokkos::Impl::raise_error("Vector::operator/=(): Mismatched sizes");
1460 #endif
1461 
1462  if (x.hasFastAccess(s.size())) {
1463 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1464 #pragma ivdep
1465 #endif
1466 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1467 #pragma unroll
1468 #endif
1469  for (ordinal_type i=0; i<s.size(); i++)
1470  s[i] /= x.fastAccessCoeff(i);
1471  }
1472  else {
1473  for (ordinal_type i=0; i<s.size(); i++)
1474  s[i] /= x.coeff(i);
1475  }
1476  return const_cast<Vector&>(*this);
1477  }
1478 
1480  KOKKOS_INLINE_FUNCTION
1481  Vector& operator++() {
1482  for (ordinal_type i=0; i<s.size(); i++)
1483  ++(s[i]);
1484  return *this;
1485  }
1486 
1488  KOKKOS_INLINE_FUNCTION
1489  volatile Vector& operator++() volatile {
1490  for (ordinal_type i=0; i<s.size(); i++)
1491  ++(s[i]);
1492  return *this;
1493  }
1494 
1496  KOKKOS_INLINE_FUNCTION
1497  Vector operator++(int) {
1498  Vector tmp(*this);
1499  ++(*this);
1500  return tmp;
1501  }
1502 
1504  KOKKOS_INLINE_FUNCTION
1505  Vector operator++(int) volatile {
1506  Vector tmp(*this);
1507  ++(*this);
1508  return tmp;
1509  }
1510 
1512  KOKKOS_INLINE_FUNCTION
1513  Vector& operator--() {
1514  for (ordinal_type i=0; i<s.size(); i++)
1515  --(s[i]);
1516  return *this;
1517  }
1518 
1520  KOKKOS_INLINE_FUNCTION
1521  volatile Vector& operator--() volatile {
1522  for (ordinal_type i=0; i<s.size(); i++)
1523  --(s[i]);
1524  return *this;
1525  }
1526 
1528  KOKKOS_INLINE_FUNCTION
1529  Vector operator--(int) {
1530  Vector tmp(*this);
1531  --(*this);
1532  return tmp;
1533  }
1534 
1536  KOKKOS_INLINE_FUNCTION
1537  Vector operator--(int) volatile {
1538  Vector tmp(*this);
1539  --(*this);
1540  return tmp;
1541  }
1542 
1544 
1545  KOKKOS_INLINE_FUNCTION
1546  std::string name() const volatile { return "x"; }
1547 
1548  protected:
1549 
1550  Storage s;
1551 
1552  template <typename expr_type>
1553  struct StaticOp {
1554  storage_type& s;
1555  const expr_type& x;
1556 
1557  KOKKOS_INLINE_FUNCTION
1558  StaticOp(storage_type& s_, const expr_type& x_) : s(s_), x(x_) {}
1559 
1560  template <typename ArgT>
1561  KOKKOS_INLINE_FUNCTION
1562  void operator() (ArgT arg) const {
1563  const int Arg = ArgT::value;
1564  s.template getCoeff<Arg>() = x.template getCoeff<Arg>();
1565  }
1566 
1567  };
1568 
1569  }; // class Vector
1570 
1572 
1576  template <typename T> struct const_expr_ref {
1577  typedef const T type;
1578  };
1579 
1581 
1585  template <typename S> struct const_expr_ref< Vector<S> > {
1586  typedef const Vector<S>& type;
1587  };
1588 
1590 
1594  template <typename S> struct const_expr_ref< volatile Vector<S> > {
1595  typedef const volatile Vector<S>& type;
1596  };
1597 
1599  template <typename T> struct remove_volatile {
1600  typedef T type;
1601  };
1602  template <typename T> struct remove_volatile<volatile T> {
1603  typedef T type;
1604  };
1605 
1607  template <typename T> struct add_volatile {
1608  typedef volatile T type;
1609  };
1610  template <typename T> struct add_volatile<volatile T> {
1611  typedef volatile T type;
1612  };
1613 
1614  template <typename Storage>
1615  std::ostream&
1616  operator << (std::ostream& os, const volatile Vector<Storage>& a)
1617  {
1619 
1620  os << "[ ";
1621 
1622  for (ordinal_type i=0; i<a.size(); i++) {
1623  os << a.coeff(i) << " ";
1624  }
1625 
1626  os << "]";
1627  return os;
1628  }
1629 
1630  template <typename Storage>
1631  std::istream&
1632  operator >> (std::istream& is, Vector<Storage>& a)
1633  {
1635  typedef typename Vector<Storage>::value_type value_type;
1636 
1637  //
1638  // Need to check all of this for errors, end-of-line, etc...
1639  //
1640 
1641  char b = 0;
1642  if (Storage::is_static) {
1643  is >> b; // "["
1644  for (ordinal_type i=0; i<a.size(); i++) {
1645  is >> a.fastAccessCoeff(i);
1646  }
1647  is >> b; // "]";
1648  }
1649  else {
1650  std::vector<value_type> c;
1651  value_type v;
1652  is >> b; // "["
1653  while (is >> b && b != ']') {
1654  is.putback(b);
1655  is >> v;
1656  c.push_back(v);
1657  }
1658  ordinal_type n = c.size();
1659  a.reset(n);
1660  for (ordinal_type i=0; i<n; ++i)
1661  a.fastAccessCoeff(i) = c[i];
1662  }
1663 
1664  return is;
1665  }
1666 
1667  //------------------------------------------------------------------------
1668  //------------------------------------------------------------------------
1669 
1671  template <unsigned Size = 0>
1672  struct VectorPartition {
1673  static const unsigned PartitionSize = Size;
1674  unsigned begin ;
1675  unsigned end ;
1676 
1677  template< typename iType0 , typename iType1 >
1678  KOKKOS_INLINE_FUNCTION
1679  VectorPartition( const iType0 & i0 , const iType1 & i1 ) :
1680  begin(i0), end(i1) {
1681  }
1682  };
1683 
1684  template <typename T>
1685  struct is_vector_partition {
1686  static const bool value = false;
1687  };
1688 
1689  template <unsigned Size>
1690  struct is_vector_partition< VectorPartition<Size> > {
1691  static const bool value = true;
1692  };
1693 
1694  } // namespace MP
1695 
1696  template <typename T>
1697  struct IsExpr< MP::Expr<T> > {
1698  static const bool value = true;
1699  };
1700 
1701  template <typename T>
1702  struct BaseExprType< MP::Expr<T> > {
1703  typedef typename MP::Expr<T>::derived_type derived_type;
1704  typedef typename derived_type::base_expr_type type;
1705  };
1706 
1707  template <typename S>
1708  struct IsExpr< MP::Vector<S> > {
1709  static const bool value = true;
1710  };
1711 
1712  template <typename S>
1713  struct BaseExprType< MP::Vector<S> > {
1714  typedef MP::Vector<S> type;
1715  };
1716 
1718  template <typename T> struct is_mp_vector {
1719  static const bool value = false;
1720  };
1721  template <typename S> struct is_mp_vector< MP::Vector<S> > {
1722  static const bool value = true;
1723  };
1724  template <typename T> struct is_mp_vector< const T > {
1725  static const bool value = is_mp_vector<T>::value;
1726  };
1727  template <typename T> struct is_mp_vector< T* > {
1728  static const bool value = is_mp_vector<T>::value;
1729  };
1730  template <typename T> struct is_mp_vector< T[] > {
1731  static const bool value = is_mp_vector<T>::value;
1732  };
1733  template <typename T, unsigned N> struct is_mp_vector< T[N] > {
1734  static const bool value = is_mp_vector<T>::value;
1735  };
1736 
1737  // Utility function to see if a MP::Vector is really a constant
1738  template <typename Storage>
1740  {
1741  typedef typename Storage::ordinal_type ordinal_type;
1742  typedef typename Storage::value_type value_type;
1743 
1744  // All size-1 vectors are constants
1745  const ordinal_type sz = x.size();
1746  if (sz == 1) return true;
1747 
1748  // Maybe use a tolerance????
1749  const value_type val = x.fastAccessCoeff(0);
1750  for (ordinal_type i=1; i<sz; ++i)
1751  if (x.fastAccessCoeff(i) != val) return false;
1752 
1753  return true;
1754  }
1755 
1756 } // namespace Sacado
1757 
1758 #include "Sacado_MP_Vector_ops.hpp"
1759 
1760 #if STOKHOS_ALIGN_MEMORY
1761 
1762 #include <memory>
1763 
1764 namespace std {
1765 
1766 template <typename Storage>
1767 class allocator< Sacado::MP::Vector< Storage > >
1768  : public Stokhos::aligned_allocator< Sacado::MP::Vector< Storage > > {
1769 public:
1770  typedef Sacado::MP::Vector<Storage> T;
1771  typedef Stokhos::aligned_allocator<T> Base;
1772  typedef typename Base::value_type value_type;
1773  typedef typename Base::pointer pointer;
1774  typedef typename Base::const_pointer const_pointer;
1775  typedef typename Base::reference reference;
1776  typedef typename Base::const_reference const_reference;
1777  typedef typename Base::size_type size_type;
1778  typedef typename Base::difference_type difference_type;
1779 
1780  template <class U> struct rebind { typedef allocator<U> other; };
1781  allocator() {}
1782  template <class U> allocator(const allocator<U>&) {}
1783 };
1784 
1785 template <typename Storage>
1786 class allocator< const Sacado::MP::Vector< Storage > >
1787  : public Stokhos::aligned_allocator< const Sacado::MP::Vector< Storage > > {
1788 public:
1789  typedef Sacado::MP::Vector<Storage> T;
1791  typedef typename Base::value_type value_type;
1792  typedef typename Base::pointer pointer;
1793  typedef typename Base::const_pointer const_pointer;
1794  typedef typename Base::reference reference;
1795  typedef typename Base::const_reference const_reference;
1796  typedef typename Base::size_type size_type;
1797  typedef typename Base::difference_type difference_type;
1798 
1799  template <class U> struct rebind { typedef allocator<U> other; };
1800  allocator() {}
1801  template <class U> allocator(const allocator<U>&) {}
1802 };
1803 
1804 }
1805 
1806 #endif
1807 
1808 #endif // HAVE_STOKHOS_SACADO
1809 
1810 //#include "Sacado_MP_Vector_SFS.hpp"
1811 
1812 #endif // SACADO_MP_VECTOR_HPP
An aligned STL allocator.
Stokhos::StandardStorage< int, double > storage_type
expr val()
Kokkos::DefaultExecutionSpace execution_space
KOKKOS_INLINE_FUNCTION void raise_error(const char *msg)
std::istream & operator>>(std::istream &is, PCE< Storage > &a)
const IndexType const IndexType const IndexType const IndexType const ValueType const ValueType * x
Definition: csr_vector.h:260
Traits class encapsulting memory alignment.
KOKKOS_INLINE_FUNCTION bool is_constant(const T &x)