Stokhos Package Browser (Single Doxygen Collection) Version of the Day
Loading...
Searching...
No Matches
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"
63
64#include "Kokkos_View_Utils.hpp"
65
66namespace Sacado {
67
69 namespace MP {
70
72
85 template <typename T>
86 class Expr {
87 public:
88
90
94 typedef T derived_type;
95
97
101 KOKKOS_INLINE_FUNCTION
102 const derived_type& derived() const {
103 return static_cast<const derived_type&>(*this);
104 }
105
107
111 KOKKOS_INLINE_FUNCTION
112 const volatile derived_type& derived() const volatile {
113 return static_cast<const volatile derived_type&>(*this);
114 }
115
116 // Allow explicit casting to integral types, since we don't have an
117 // integral ensemble type.
118 template <typename U, typename Enabled = typename std::enable_if<std::is_integral<U>::value>::type>
119 KOKKOS_INLINE_FUNCTION
120 explicit operator U() const { return static_cast<U>(derived().val()); }
121
122 };
123
125 template <typename Storage>
126 class Vector : public Expr< Vector<Storage> > {
127 public:
128
130 typedef Storage storage_type;
131
132 typedef typename storage_type::value_type value_type;
133 typedef typename storage_type::ordinal_type ordinal_type;
134 typedef typename storage_type::execution_space execution_space;
135 typedef typename storage_type::pointer pointer;
136 typedef typename storage_type::volatile_pointer volatile_pointer;
137 typedef typename storage_type::const_pointer const_pointer;
138 typedef typename storage_type::const_volatile_pointer const_volatile_pointer;
139 typedef typename storage_type::reference reference;
140 typedef typename storage_type::volatile_reference volatile_reference;
141 typedef typename storage_type::const_reference const_reference;
142 typedef typename storage_type::const_volatile_reference const_volatile_reference;
143
144 typedef typename execution_space::memory_space memory_space;
145 typedef typename Stokhos::MemoryTraits<memory_space> MemTraits;
146
148 typedef typename ScalarType<value_type>::type scalar_type;
149
150 typedef Vector base_expr_type;
151
153 template < class NewStorageType >
154 struct apply {
155 typedef Vector< NewStorageType > type;
156 };
157
159 static const int num_args = 1;
160
161#if STOKHOS_ALIGN_MEMORY
162 KOKKOS_INLINE_FUNCTION
163 static void* operator new(std::size_t sz) {
164 return MemTraits::alloc(sz);
165 }
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, void* ptr) {
172 return ptr;
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 delete(void* ptr) {
180 MemTraits::free(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, void*) {
188 MemTraits::free(ptr);
189 }
190 KOKKOS_INLINE_FUNCTION
191 static void operator delete[](void* ptr, void*) {
192 MemTraits::free(ptr);
193 }
194#endif
195
197
200 KOKKOS_DEFAULTED_FUNCTION
201 Vector() = default;
202
204
207 KOKKOS_INLINE_FUNCTION
208 Vector(const value_type& x) : s(1,x) {}
209
211
215 KOKKOS_INLINE_FUNCTION
216 Vector(ordinal_type sz, pointer v, bool owned) : s(sz,v,owned) {}
217
219
222 KOKKOS_INLINE_FUNCTION
223 Vector(ordinal_type sz, const value_type& x) : s(sz,x) {}
224
226 KOKKOS_INLINE_FUNCTION
227 Vector(const storage_type& ss) : s(ss) {}
228
230 KOKKOS_DEFAULTED_FUNCTION
231 Vector(const Vector& x) = default;
232
234 KOKKOS_INLINE_FUNCTION
235 Vector(const volatile Vector& x) : s(x.s) {}
236
238 template <typename S>
239 KOKKOS_INLINE_FUNCTION
240 Vector(const Expr<S>& xx) :
241 s(xx.derived().size()) {
242 typedef typename Expr<S>::derived_type expr_type;
243 const expr_type& x = xx.derived();
244
245#ifdef STOKHOS_DEBUG
246 if (s.size() != x.size())
247 Kokkos::Impl::raise_error("Vector(): Mismatched sizes");
248#endif
249
250 if (x.hasFastAccess(s.size())) {
251#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
252#pragma ivdep
253#endif
254#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
255#pragma vector aligned
256#endif
257#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
258#pragma unroll
259#endif
260 for (ordinal_type i=0; i<s.size(); i++)
261 s[i] = x.fastAccessCoeff(i);
262 }
263 else {
264 for (ordinal_type i=0; i<s.size(); i++)
265 s[i] = x.coeff(i);
266 }
267 }
268
270
276 KOKKOS_INLINE_FUNCTION
277 Vector(std::initializer_list<value_type> l) : s(l.size(), l.begin()) {
278 if constexpr (Storage::is_static) {
279 const auto lsz = static_cast<ordinal_type>(l.size());
280 const ordinal_type sz = this->size();
281 if (lsz < sz) {
282 if (lsz > 1) {
283 Kokkos::abort("Size mismatch in list initialization of MP Vector with static fixed storage.");
284 }
285 else {
286 const value_type v = lsz > 0 ? *l.begin() : value_type(0);
287 s.init(v);
288 }
289 }
290 }
291 }
292
294 KOKKOS_DEFAULTED_FUNCTION
295 ~Vector() = default;
296
298 KOKKOS_INLINE_FUNCTION
299 void init(const value_type& v) { s.init(v); }
300
302 KOKKOS_INLINE_FUNCTION
303 void init(const value_type& v) volatile { s.init(v); }
304
306 KOKKOS_INLINE_FUNCTION
307 void init(const value_type* v) { s.init(v); }
308
310 KOKKOS_INLINE_FUNCTION
311 void init(const value_type* v) volatile { s.init(v); }
312
314 template <typename S>
315 KOKKOS_INLINE_FUNCTION
316 void init(const Vector<S>& v) {
317 s.init(v.s.coeff(), v.s.size());
318 }
319
321 template <typename S>
322 KOKKOS_INLINE_FUNCTION
323 void init(const Vector<S>& v) volatile {
324 s.init(v.s.coeff(), v.s.size());
325 }
326
328 KOKKOS_INLINE_FUNCTION
329 void load(value_type* v) { s.load(v); }
330
332 KOKKOS_INLINE_FUNCTION
333 void load(value_type* v) volatile { s.load(v); }
334
336 template <typename S>
337 KOKKOS_INLINE_FUNCTION
338 void load(Vector<S>& v) { s.load(v.s.coeff()); }
339
341 template <typename S>
342 KOKKOS_INLINE_FUNCTION
343 void load(Vector<S>& v) volatile { s.load(v.s.coeff()); }
344
346
349 KOKKOS_INLINE_FUNCTION
350 void reset(ordinal_type sz_new) {
351 ordinal_type sz = this->size();
352 s.resize(sz_new);
353 if (sz == 1 && sz_new > sz)
354 for (ordinal_type i=1; i<sz_new; i++)
355 s[i] = s[0];
356 }
357
359
362 KOKKOS_INLINE_FUNCTION
363 void reset(ordinal_type sz_new) volatile {
364 ordinal_type sz = this->size();
365 s.resize(sz_new);
366 if (sz == 1 && sz_new > sz)
367 for (ordinal_type i=1; i<sz_new; i++)
368 s[i] = s[0];
369 }
370
372
381 KOKKOS_INLINE_FUNCTION
382 void copyForWrite() volatile { }
383
385 template <typename S>
386 KOKKOS_INLINE_FUNCTION
387 bool isEqualTo(const Expr<S>& xx) const {
388 const typename Expr<S>::derived_type& x = xx.derived();
389 typedef IsEqual<value_type> IE;
390 if (x.size() != this->size()) return false;
391 bool eq = true;
392 for (ordinal_type i=0; i<this->size(); i++)
393 eq = eq && IE::eval(x.coeff(i), this->coeff(i));
394 return eq;
395 }
396
398 template <typename S>
399 KOKKOS_INLINE_FUNCTION
400 bool isEqualTo(const Expr<S>& xx) const volatile {
401 const typename Expr<S>::derived_type& x = xx.derived();
402 typedef IsEqual<value_type> IE;
403 if (x.size() != this->size()) return false;
404 bool eq = true;
405 for (ordinal_type i=0; i<this->size(); i++)
406 eq = eq && IE::eval(x.coeff(i), this->coeff(i));
407 return eq;
408 }
409
414
416
419 Vector& operator=(std::initializer_list<value_type> l) {
420 const ordinal_type lsz = l.size();
421 if (lsz != s.size())
422 s.resize(lsz);
423 s.init(l.begin(), lsz);
424 return *this;
425 }
426
428
431 /*volatile*/ Vector&
432 operator=(std::initializer_list<value_type> l) volatile {
433 const ordinal_type lsz = l.size();
434 if (lsz != s.size())
435 s.resize(lsz);
436 s.init(l.begin(), lsz);
437 return const_cast<Vector&>(*this);
438 }
439
441 KOKKOS_INLINE_FUNCTION
442 Vector& operator=(const value_type& x) {
443 s.init(x);
444 return *this;
445 }
446
448 KOKKOS_INLINE_FUNCTION
449 /*volatile*/ Vector& operator=(const value_type& x) volatile {
450 s.init(x);
451 return const_cast<Vector&>(*this);
452 }
453
455 KOKKOS_INLINE_FUNCTION
456 Vector& operator=(const Vector& x) {
457 if (this != &x) {
458 s = x.s;
459
460 // For DyamicStorage as a view (is_owned=false), we need to set
461 // the trailing entries when assigning a constant vector (because
462 // the copy constructor in this case doesn't reset the size of this)
463 //
464 // Note: supporting this technically makes the Vector non-POD, even
465 // with a static storage type where this branch will get optimized
466 // out. We would have to remove DynamicStorage-as-a view as an option
467 // or partial specialize on StaticFixedStorage to fix this. However
468 // the volatile operator=() and copy constructor overloads make
469 // Vector non-POD anyway.
470 if (s.size() > x.s.size())
471 for (ordinal_type i=x.s.size(); i<s.size(); i++)
472 s[i] = s[0];
473 }
474
475 return *this;
476 }
477
479 KOKKOS_INLINE_FUNCTION
480 Vector& operator=(const volatile Vector& x) {
481 if (this != &x) {
482 s = x.s;
483
484 // For DyamicStorage as a view (is_owned=false), we need to set
485 // the trailing entries when assigning a constant vector (because
486 // the copy constructor in this case doesn't reset the size of this)
487 //
488 // Note: supporting this technically makes the Vector non-POD, even
489 // with a static storage type where this branch will get optimized
490 // out. We would have to remove DynamicStorage-as-a view as an option
491 // or partial specialize on StaticFixedStorage to fix this. However
492 // the volatile operator=() and copy constructor overloads make
493 // Vector non-POD anyway.
494 if (s.size() > x.s.size())
495 for (ordinal_type i=x.s.size(); i<s.size(); i++)
496 s[i] = s[0];
497 }
498
499 return *this;
500 }
501
503 KOKKOS_INLINE_FUNCTION
504 /*volatile*/ Vector& operator=(const Vector& x) volatile {
505 if (this != &x) {
506 s = x.s;
507
508 // For DyamicStorage as a view (is_owned=false), we need to set
509 // the trailing entries when assigning a constant vector (because
510 // the copy constructor in this case doesn't reset the size of this)
511 //
512 // Note: supporting this technically makes the Vector non-POD, even
513 // with a static storage type where this branch will get optimized
514 // out. We would have to remove DynamicStorage-as-a view as an option
515 // or partial specialize on StaticFixedStorage to fix this. However
516 // the volatile operator=() and copy constructor overloads make
517 // Vector non-POD anyway.
518 if (s.size() > x.s.size())
519 for (ordinal_type i=x.s.size(); i<s.size(); i++)
520 s[i] = s[0];
521 }
522
523 return const_cast<Vector&>(*this);
524 }
525
527 KOKKOS_INLINE_FUNCTION
528 /*volatile*/ Vector& operator=(const volatile Vector& x) volatile {
529 if (this != &x) {
530 s = x.s;
531
532 // For DyamicStorage as a view (is_owned=false), we need to set
533 // the trailing entries when assigning a constant vector (because
534 // the copy constructor in this case doesn't reset the size of this)
535 //
536 // Note: supporting this technically makes the Vector non-POD, even
537 // with a static storage type where this branch will get optimized
538 // out. We would have to remove DynamicStorage-as-a view as an option
539 // or partial specialize on StaticFixedStorage to fix this. However
540 // the volatile operator=() and copy constructor overloads make
541 // Vector non-POD anyway.
542 if (s.size() > x.s.size())
543 for (ordinal_type i=x.s.size(); i<s.size(); i++)
544 s[i] = s[0];
545 }
546
547 return const_cast<Vector&>(*this);
548 }
549
551 template <typename S>
552 KOKKOS_INLINE_FUNCTION
553 Vector& operator=(const Expr<S>& xx) {
554 typedef typename Expr<S>::derived_type expr_type;
555 const expr_type& x = xx.derived();
556
557 this->reset(x.size());
558
559#ifdef STOKHOS_DEBUG
560 if (s.size() != x.size())
561 Kokkos::Impl::raise_error("Vector::operator=(): Mismatched sizes");
562#endif
563
564 if (x.hasFastAccess(s.size())) {
565#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
566#pragma ivdep
567#endif
568#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
569#pragma vector aligned
570#endif
571#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
572#pragma unroll
573#endif
574 for (ordinal_type i=0; i<s.size(); i++)
575 s[i] = x.fastAccessCoeff(i);
576 }
577 else {
578 for (ordinal_type i=0; i<s.size(); i++)
579 s[i] = x.coeff(i);
580 }
581 return *this;
582 }
583
585 template <typename S>
586 KOKKOS_INLINE_FUNCTION
587 /*volatile*/ Vector& operator=(const Expr<S>& xx) volatile {
588 typedef typename Expr<S>::derived_type expr_type;
589 const expr_type& x = xx.derived();
590
591 this->reset(x.size());
592
593#ifdef STOKHOS_DEBUG
594 if (s.size() != x.size())
595 Kokkos::Impl::raise_error("Vector::operator=(): Mismatched sizes");
596#endif
597
598 if (x.hasFastAccess(s.size())) {
599#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
600#pragma ivdep
601#endif
602#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
603#pragma vector aligned
604#endif
605#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
606#pragma unroll
607#endif
608 for (ordinal_type i=0; i<s.size(); i++)
609 s[i] = x.fastAccessCoeff(i);
610 }
611 else {
612 for (ordinal_type i=0; i<s.size(); i++)
613 s[i] = x.coeff(i);
614 }
615 return const_cast<Vector&>(*this);
616 }
617
619 template< typename S >
620 KOKKOS_INLINE_FUNCTION
621 typename std::enable_if<( ! std::is_same<S,void>::value &&
623 ), Vector >
624 ::type const & operator = ( const Expr<S> & xx ) const
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 template< typename S >
644 KOKKOS_INLINE_FUNCTION
645 volatile
646 typename std::enable_if<( ! std::is_same<S,void>::value &&
648 ), Vector >
649 ::type const & operator = ( const Expr<S> & xx ) const volatile
650 {
651 const typename Expr<S>::derived_type & x = xx.derived();
652
653#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
654#pragma ivdep
655#endif
656#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
657#pragma vector aligned
658#endif
659#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
660#pragma unroll
661#endif
662 for ( ordinal_type i = 0 ; i < s.size() ; ++i ) { s[i] = x.coeff(i); }
663
664 return *this ;
665 }
666
668
672
674 KOKKOS_INLINE_FUNCTION
675 const volatile storage_type& storage() const volatile { return s; }
676
678 KOKKOS_INLINE_FUNCTION
679 const storage_type& storage() const { return s; }
680
682 KOKKOS_INLINE_FUNCTION
683 volatile storage_type& storage() volatile { return s; }
684
686 KOKKOS_INLINE_FUNCTION
687 storage_type& storage() { return s; }
688
693
695 KOKKOS_INLINE_FUNCTION
696 const_volatile_reference val() const volatile { return s[0]; }
697
699 KOKKOS_INLINE_FUNCTION
700 const_reference val() const { return s[0]; }
701
703 KOKKOS_INLINE_FUNCTION
704 volatile_reference val() volatile { return s[0]; }
705
707 KOKKOS_INLINE_FUNCTION
708 reference val() { return s[0]; }
709
711
716
718 KOKKOS_INLINE_FUNCTION
719 ordinal_type size() const { return s.size();}
720
722 KOKKOS_INLINE_FUNCTION
723 ordinal_type size() const volatile { return s.size();}
724
726 KOKKOS_INLINE_FUNCTION
727 bool hasFastAccess(ordinal_type sz) const { return s.size()>=sz;}
728
730 KOKKOS_INLINE_FUNCTION
731 bool hasFastAccess(ordinal_type sz) const volatile { return s.size()>=sz;}
732
734 KOKKOS_INLINE_FUNCTION
735 const_pointer coeff() const { return s.coeff();}
736
738 KOKKOS_INLINE_FUNCTION
739 const_volatile_pointer coeff() const volatile { return s.coeff();}
740
742 KOKKOS_INLINE_FUNCTION
743 volatile_pointer coeff() volatile { return s.coeff();}
744
746 KOKKOS_INLINE_FUNCTION
747 pointer coeff() { return s.coeff();}
748
750 KOKKOS_INLINE_FUNCTION
751 value_type coeff(ordinal_type i) const volatile {
752 return i<s.size() ? s[i] : s[0]; }
753
755 KOKKOS_INLINE_FUNCTION
756 value_type coeff(ordinal_type i) const {
757 return i<s.size() ? s[i] : s[0]; }
758
760 KOKKOS_INLINE_FUNCTION
761 value_type coeff(ordinal_type i) volatile {
762 return i<s.size() ? s[i] : s[0]; }
763
765 KOKKOS_INLINE_FUNCTION
766 value_type coeff(ordinal_type i) {
767 return i<s.size() ? s[i] : s[0]; }
768
770 KOKKOS_INLINE_FUNCTION
771 const_volatile_reference fastAccessCoeff(ordinal_type i) const volatile {
772 return s[i];}
773
775 KOKKOS_INLINE_FUNCTION
776 const_reference fastAccessCoeff(ordinal_type i) const {
777 return s[i];}
778
780 KOKKOS_INLINE_FUNCTION
781 volatile_reference fastAccessCoeff(ordinal_type i) volatile {
782 return s[i];}
783
785 KOKKOS_INLINE_FUNCTION
786 reference fastAccessCoeff(ordinal_type i) {
787 return s[i];}
788
790 KOKKOS_INLINE_FUNCTION
791 const_volatile_reference operator[](ordinal_type i) const volatile {
792 return s[i];}
793
795 KOKKOS_INLINE_FUNCTION
796 const_reference operator[](ordinal_type i) const {
797 return s[i];}
798
800 KOKKOS_INLINE_FUNCTION
801 volatile_reference operator[](ordinal_type i) volatile {
802 return s[i];}
803
805 KOKKOS_INLINE_FUNCTION
806 reference operator[](ordinal_type i) {
807 return s[i];}
808
809 template <int i>
810 KOKKOS_INLINE_FUNCTION
811 value_type getCoeff() const volatile {
812 return s.template getCoeff<i>(); }
813
814 template <int i>
815 KOKKOS_INLINE_FUNCTION
816 value_type getCoeff() const {
817 return s.template getCoeff<i>(); }
818
819 template <int i>
820 KOKKOS_INLINE_FUNCTION
821 volatile_reference getCoeff() volatile {
822 return s.template getCoeff<i>(); }
823
824 template <int i>
825 KOKKOS_INLINE_FUNCTION
826 reference getCoeff() {
827 return s.template getCoeff<i>(); }
828
830 KOKKOS_INLINE_FUNCTION
831 pointer begin() { return s.coeff(); }
832
834 KOKKOS_INLINE_FUNCTION
835 const_pointer begin() const { return s.coeff(); }
836
838 KOKKOS_INLINE_FUNCTION
839 volatile_pointer begin() volatile { return s.coeff(); }
840
842 KOKKOS_INLINE_FUNCTION
843 const_volatile_pointer begin() const volatile { return s.coeff(); }
844
846 KOKKOS_INLINE_FUNCTION
847 const_pointer cbegin() const { return s.coeff(); }
848
850 KOKKOS_INLINE_FUNCTION
851 const_volatile_pointer cbegin() const volatile { return s.coeff(); }
852
854 KOKKOS_INLINE_FUNCTION
855 pointer end() { return s.coeff() + s.size(); }
856
858 KOKKOS_INLINE_FUNCTION
859 const_pointer end() const { return s.coeff() + s.size(); }
860
862 KOKKOS_INLINE_FUNCTION
863 volatile_pointer end() volatile { return s.coeff() + s.size(); }
864
866 KOKKOS_INLINE_FUNCTION
867 const_volatile_pointer end() const volatile { return s.coeff() + s.size(); }
868
870 KOKKOS_INLINE_FUNCTION
871 const_pointer cend() const { return s.coeff()+ s.size(); }
872
874 KOKKOS_INLINE_FUNCTION
875 const_volatile_pointer cend() const volatile { return s.coeff()+ s.size(); }
876
878
883
885 KOKKOS_INLINE_FUNCTION
886 Vector& operator += (const value_type& x) {
887#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
888#pragma ivdep
889#endif
890#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
891#pragma vector aligned
892#endif
893#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
894#pragma unroll
895#endif
896 for (ordinal_type i=0; i<s.size(); i++)
897 s[i] += x;
898 return *this;
899 }
900
902 KOKKOS_INLINE_FUNCTION
903 Vector& operator += (const volatile value_type& x) {
904#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
905#pragma ivdep
906#endif
907#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
908#pragma vector aligned
909#endif
910#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
911#pragma unroll
912#endif
913 for (ordinal_type i=0; i<s.size(); i++)
914 s[i] += x;
915 return *this;
916 }
917
919 KOKKOS_INLINE_FUNCTION
920 /*volatile*/ Vector& operator += (const value_type& x) volatile {
921#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
922#pragma ivdep
923#endif
924#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
925#pragma vector aligned
926#endif
927#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
928#pragma unroll
929#endif
930 for (ordinal_type i=0; i<s.size(); i++)
931 s[i] += x;
932 return const_cast<Vector&>(*this);
933 }
934
936 KOKKOS_INLINE_FUNCTION
937 /*volatile*/ Vector& operator += (const volatile value_type& x) volatile {
938#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
939#pragma ivdep
940#endif
941#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
942#pragma vector aligned
943#endif
944#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
945#pragma unroll
946#endif
947 for (ordinal_type i=0; i<s.size(); i++)
948 s[i] += x;
949 return const_cast<Vector&>(*this);
950 }
951
953 KOKKOS_INLINE_FUNCTION
954 Vector& operator -= (const value_type& x) {
955#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
956#pragma ivdep
957#endif
958#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
959#pragma vector aligned
960#endif
961#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
962#pragma unroll
963#endif
964 for (ordinal_type i=0; i<s.size(); i++)
965 s[i] -= x;
966 return *this;
967 }
968
970 KOKKOS_INLINE_FUNCTION
971 Vector& operator -= (const volatile value_type& x) {
972#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
973#pragma ivdep
974#endif
975#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
976#pragma vector aligned
977#endif
978#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
979#pragma unroll
980#endif
981 for (ordinal_type i=0; i<s.size(); i++)
982 s[i] -= x;
983 return *this;
984 }
985
987 KOKKOS_INLINE_FUNCTION
988 /*volatile*/ Vector& operator -= (const value_type& x) volatile {
989#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
990#pragma ivdep
991#endif
992#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
993#pragma vector aligned
994#endif
995#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
996#pragma unroll
997#endif
998 for (ordinal_type i=0; i<s.size(); i++)
999 s[i] -= x;
1000 return const_cast<Vector&>(*this);
1001 }
1002
1004 KOKKOS_INLINE_FUNCTION
1005 /*volatile*/ Vector& operator -= (const volatile value_type& x) volatile {
1006#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1007#pragma ivdep
1008#endif
1009#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1010#pragma vector aligned
1011#endif
1012#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1013#pragma unroll
1014#endif
1015 for (ordinal_type i=0; i<s.size(); i++)
1016 s[i] -= x;
1017 return const_cast<Vector&>(*this);
1018 }
1019
1021 KOKKOS_INLINE_FUNCTION
1022 Vector& operator *= (const value_type& x) {
1023#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1024#pragma ivdep
1025#endif
1026#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1027#pragma vector aligned
1028#endif
1029#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1030#pragma unroll
1031#endif
1032 for (ordinal_type i=0; i<s.size(); i++)
1033 s[i] *= x;
1034 return *this;
1035 }
1036
1038 KOKKOS_INLINE_FUNCTION
1039 Vector& operator *= (const volatile value_type& x) {
1040#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1041#pragma ivdep
1042#endif
1043#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1044#pragma vector aligned
1045#endif
1046#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1047#pragma unroll
1048#endif
1049 for (ordinal_type i=0; i<s.size(); i++)
1050 s[i] *= x;
1051 return *this;
1052 }
1053
1055 KOKKOS_INLINE_FUNCTION
1056 /*volatile*/ Vector& operator *= (const value_type& x) volatile {
1057#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1058#pragma ivdep
1059#endif
1060#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1061#pragma vector aligned
1062#endif
1063#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1064#pragma unroll
1065#endif
1066 for (ordinal_type i=0; i<s.size(); i++)
1067 s[i] *= x;
1068 return const_cast<Vector&>(*this);
1069 }
1070
1072 KOKKOS_INLINE_FUNCTION
1073 /*volatile*/ Vector& operator *= (const volatile value_type& x) volatile {
1074#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1075#pragma ivdep
1076#endif
1077#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1078#pragma vector aligned
1079#endif
1080#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1081#pragma unroll
1082#endif
1083 for (ordinal_type i=0; i<s.size(); i++)
1084 s[i] *= x;
1085 return const_cast<Vector&>(*this);
1086 }
1087
1089 KOKKOS_INLINE_FUNCTION
1090 Vector& operator /= (const value_type& x) {
1091#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1092#pragma ivdep
1093#endif
1094#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1095#pragma vector aligned
1096#endif
1097#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1098#pragma unroll
1099#endif
1100 for (ordinal_type i=0; i<s.size(); i++)
1101 s[i] /= x;
1102 return *this;
1103 }
1104
1106 KOKKOS_INLINE_FUNCTION
1107 Vector& operator /= (const volatile value_type& x) {
1108#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1109#pragma ivdep
1110#endif
1111#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1112#pragma vector aligned
1113#endif
1114#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1115#pragma unroll
1116#endif
1117 for (ordinal_type i=0; i<s.size(); i++)
1118 s[i] /= x;
1119 return *this;
1120 }
1121
1123 KOKKOS_INLINE_FUNCTION
1124 /*volatile*/ Vector& operator /= (const value_type& x) volatile {
1125#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1126#pragma ivdep
1127#endif
1128#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1129#pragma vector aligned
1130#endif
1131#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1132#pragma unroll
1133#endif
1134 for (ordinal_type i=0; i<s.size(); i++)
1135 s[i] /= x;
1136 return const_cast<Vector&>(*this);
1137 }
1138
1140 KOKKOS_INLINE_FUNCTION
1141 /*volatile*/ Vector& operator /= (const volatile value_type& x) volatile {
1142#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1143#pragma ivdep
1144#endif
1145#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1146#pragma vector aligned
1147#endif
1148#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1149#pragma unroll
1150#endif
1151 for (ordinal_type i=0; i<s.size(); i++)
1152 s[i] /= x;
1153 return const_cast<Vector&>(*this);
1154 }
1155
1157 template <typename S>
1158 KOKKOS_INLINE_FUNCTION
1159 Vector& operator += (const Expr<S>& xx) {
1160 //*this = *this + x;
1161 typedef typename Expr<S>::derived_type expr_type;
1162 const expr_type& x = xx.derived();
1163
1164 if (x.size() > s.size())
1165 this->reset(x.size());
1166
1167#ifdef STOKHOS_DEBUG
1168 if (s.size() < x.size())
1169 Kokkos::Impl::raise_error("Vector::operator+=(): Mismatched sizes");
1170#endif
1171
1172 if (x.hasFastAccess(s.size())) {
1173#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1174#pragma ivdep
1175#endif
1176#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1177#pragma vector aligned
1178#endif
1179#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1180#pragma unroll
1181#endif
1182 for (ordinal_type i=0; i<s.size(); i++)
1183 s[i] += x.fastAccessCoeff(i);
1184 }
1185 else {
1186 for (ordinal_type i=0; i<s.size(); i++)
1187 s[i] += x.coeff(i);
1188 }
1189 return *this;
1190 }
1191
1193 template <typename S>
1194 KOKKOS_INLINE_FUNCTION
1195 Vector& operator += (const volatile Expr<S>& xx) {
1196 //*this = *this + x;
1197 typedef typename Expr<S>::derived_type expr_type;
1198 const volatile expr_type& x = xx.derived();
1199
1200 if (x.size() > s.size())
1201 this->reset(x.size());
1202
1203#ifdef STOKHOS_DEBUG
1204 if (s.size() < x.size())
1205 Kokkos::Impl::raise_error("Vector::operator+=(): Mismatched sizes");
1206#endif
1207
1208 if (x.hasFastAccess(s.size())) {
1209#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1210#pragma ivdep
1211#endif
1212#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1213#pragma vector aligned
1214#endif
1215#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1216#pragma unroll
1217#endif
1218 for (ordinal_type i=0; i<s.size(); i++)
1219 s[i] += x.fastAccessCoeff(i);
1220 }
1221 else {
1222 for (ordinal_type i=0; i<s.size(); i++)
1223 s[i] += x.coeff(i);
1224 }
1225 return *this;
1226 }
1227
1229 template <typename S>
1230 KOKKOS_INLINE_FUNCTION
1231 /*volatile*/ Vector& operator += (const Expr<S>& xx) volatile {
1232 //*this = *this + x;
1233 typedef typename Expr<S>::derived_type expr_type;
1234 const expr_type& x = xx.derived();
1235
1236 if (x.size() > s.size())
1237 this->reset(x.size());
1238
1239#ifdef STOKHOS_DEBUG
1240 if (s.size() < x.size())
1241 Kokkos::Impl::raise_error("Vector::operator+=(): Mismatched sizes");
1242#endif
1243
1244 if (x.hasFastAccess(s.size())) {
1245#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1246#pragma ivdep
1247#endif
1248#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1249#pragma vector aligned
1250#endif
1251#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1252#pragma unroll
1253#endif
1254 for (ordinal_type i=0; i<s.size(); i++)
1255 s[i] += x.fastAccessCoeff(i);
1256 }
1257 else {
1258 for (ordinal_type i=0; i<s.size(); i++)
1259 s[i] += x.coeff(i);
1260 }
1261 return const_cast<Vector&>(*this);
1262 }
1263
1265 template <typename S>
1266 KOKKOS_INLINE_FUNCTION
1267 /*volatile*/ Vector& operator += (const volatile Expr<S>& xx) volatile {
1268 //*this = *this + x;
1269 typedef typename Expr<S>::derived_type expr_type;
1270 const volatile expr_type& x = xx.derived();
1271
1272 if (x.size() > s.size())
1273 this->reset(x.size());
1274
1275#ifdef STOKHOS_DEBUG
1276 if (s.size() < x.size())
1277 Kokkos::Impl::raise_error("Vector::operator+=(): Mismatched sizes");
1278#endif
1279
1280 if (x.hasFastAccess(s.size())) {
1281#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1282#pragma ivdep
1283#endif
1284#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1285#pragma vector aligned
1286#endif
1287#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1288#pragma unroll
1289#endif
1290 for (ordinal_type i=0; i<s.size(); i++)
1291 s[i] += x.fastAccessCoeff(i);
1292 }
1293 else {
1294 for (ordinal_type i=0; i<s.size(); i++)
1295 s[i] += x.coeff(i);
1296 }
1297 return const_cast<Vector&>(*this);
1298 }
1299
1301 template <typename S>
1302 KOKKOS_INLINE_FUNCTION
1303 Vector& operator -= (const Expr<S>& xx) {
1304 //*this = *this - x;
1305 typedef typename Expr<S>::derived_type expr_type;
1306 const expr_type& x = xx.derived();
1307
1308 if (x.size() > s.size())
1309 this->reset(x.size());
1310
1311#ifdef STOKHOS_DEBUG
1312 if (s.size() < x.size())
1313 Kokkos::Impl::raise_error("Vector::operator-=(): Mismatched sizes");
1314#endif
1315
1316 if (x.hasFastAccess(s.size())) {
1317#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1318#pragma ivdep
1319#endif
1320#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1321#pragma vector aligned
1322#endif
1323#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1324#pragma unroll
1325#endif
1326 for (ordinal_type i=0; i<s.size(); i++)
1327 s[i] -= x.fastAccessCoeff(i);
1328 }
1329 else {
1330 for (ordinal_type i=0; i<s.size(); i++)
1331 s[i] -= x.coeff(i);
1332 }
1333 return *this;
1334 }
1335
1337 template <typename S>
1338 KOKKOS_INLINE_FUNCTION
1339 Vector& operator -= (const volatile Expr<S>& xx) {
1340 //*this = *this - x;
1341 typedef typename Expr<S>::derived_type expr_type;
1342 const volatile expr_type& x = xx.derived();
1343
1344 if (x.size() > s.size())
1345 this->reset(x.size());
1346
1347#ifdef STOKHOS_DEBUG
1348 if (s.size() < x.size())
1349 Kokkos::Impl::raise_error("Vector::operator-=(): Mismatched sizes");
1350#endif
1351
1352 if (x.hasFastAccess(s.size())) {
1353#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1354#pragma ivdep
1355#endif
1356#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1357#pragma vector aligned
1358#endif
1359#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1360#pragma unroll
1361#endif
1362 for (ordinal_type i=0; i<s.size(); i++)
1363 s[i] -= x.fastAccessCoeff(i);
1364 }
1365 else {
1366 for (ordinal_type i=0; i<s.size(); i++)
1367 s[i] -= x.coeff(i);
1368 }
1369 return *this;
1370 }
1371
1373 template <typename S>
1374 KOKKOS_INLINE_FUNCTION
1375 /*volatile*/ Vector& operator -= (const Expr<S>& xx) volatile {
1376 //*this = *this - x;
1377 typedef typename Expr<S>::derived_type expr_type;
1378 const expr_type& x = xx.derived();
1379
1380 if (x.size() > s.size())
1381 this->reset(x.size());
1382
1383#ifdef STOKHOS_DEBUG
1384 if (s.size() < x.size())
1385 Kokkos::Impl::raise_error("Vector::operator-=(): Mismatched sizes");
1386#endif
1387
1388 if (x.hasFastAccess(s.size())) {
1389#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1390#pragma ivdep
1391#endif
1392#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1393#pragma vector aligned
1394#endif
1395#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1396#pragma unroll
1397#endif
1398 for (ordinal_type i=0; i<s.size(); i++)
1399 s[i] -= x.fastAccessCoeff(i);
1400 }
1401 else {
1402 for (ordinal_type i=0; i<s.size(); i++)
1403 s[i] -= x.coeff(i);
1404 }
1405 return const_cast<Vector&>(*this);
1406 }
1407
1409 template <typename S>
1410 KOKKOS_INLINE_FUNCTION
1411 /*volatile*/ Vector& operator -= (const volatile Expr<S>& xx) volatile {
1412 //*this = *this - x;
1413 typedef typename Expr<S>::derived_type expr_type;
1414 const volatile expr_type& x = xx.derived();
1415
1416 if (x.size() > s.size())
1417 this->reset(x.size());
1418
1419#ifdef STOKHOS_DEBUG
1420 if (s.size() < x.size())
1421 Kokkos::Impl::raise_error("Vector::operator-=(): Mismatched sizes");
1422#endif
1423
1424 if (x.hasFastAccess(s.size())) {
1425#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1426#pragma ivdep
1427#endif
1428#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1429#pragma vector aligned
1430#endif
1431#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1432#pragma unroll
1433#endif
1434 for (ordinal_type i=0; i<s.size(); i++)
1435 s[i] -= x.fastAccessCoeff(i);
1436 }
1437 else {
1438 for (ordinal_type i=0; i<s.size(); i++)
1439 s[i] -= x.coeff(i);
1440 }
1441 return const_cast<Vector&>(*this);
1442 }
1443
1445 template <typename S>
1446 KOKKOS_INLINE_FUNCTION
1447 Vector& operator *= (const Expr<S>& xx) {
1448 //*this = *this * x;
1449 typedef typename Expr<S>::derived_type expr_type;
1450 const expr_type& x = xx.derived();
1451
1452 if (x.size() > s.size())
1453 this->reset(x.size());
1454
1455#ifdef STOKHOS_DEBUG
1456 if (s.size() < x.size())
1457 Kokkos::Impl::raise_error("Vector::operator*=(): Mismatched sizes");
1458#endif
1459
1460 if (x.hasFastAccess(s.size())) {
1461#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1462#pragma ivdep
1463#endif
1464#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1465#pragma vector aligned
1466#endif
1467#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1468#pragma unroll
1469#endif
1470 for (ordinal_type i=0; i<s.size(); i++)
1471 s[i] *= x.fastAccessCoeff(i);
1472 }
1473 else {
1474 for (ordinal_type i=0; i<s.size(); i++)
1475 s[i] *= x.coeff(i);
1476 }
1477 return *this;
1478 }
1479
1481 template <typename S>
1482 KOKKOS_INLINE_FUNCTION
1483 Vector& operator *= (const volatile Expr<S>& xx) {
1484 //*this = *this * x;
1485 typedef typename Expr<S>::derived_type expr_type;
1486 const volatile expr_type& x = xx.derived();
1487
1488 if (x.size() > s.size())
1489 this->reset(x.size());
1490
1491#ifdef STOKHOS_DEBUG
1492 if (s.size() < x.size())
1493 Kokkos::Impl::raise_error("Vector::operator*=(): Mismatched sizes");
1494#endif
1495
1496 if (x.hasFastAccess(s.size())) {
1497#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1498#pragma ivdep
1499#endif
1500#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1501#pragma vector aligned
1502#endif
1503#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1504#pragma unroll
1505#endif
1506 for (ordinal_type i=0; i<s.size(); i++)
1507 s[i] *= x.fastAccessCoeff(i);
1508 }
1509 else {
1510 for (ordinal_type i=0; i<s.size(); i++)
1511 s[i] *= x.coeff(i);
1512 }
1513 return *this;
1514 }
1515
1517 template <typename S>
1518 KOKKOS_INLINE_FUNCTION
1519 /*volatile*/ Vector& operator *= (const Expr<S>& xx) volatile {
1520 //*this = *this * x;
1521 typedef typename Expr<S>::derived_type expr_type;
1522 const expr_type& x = xx.derived();
1523
1524 if (x.size() > s.size())
1525 this->reset(x.size());
1526
1527#ifdef STOKHOS_DEBUG
1528 if (s.size() < x.size())
1529 Kokkos::Impl::raise_error("Vector::operator*=(): Mismatched sizes");
1530#endif
1531
1532 if (x.hasFastAccess(s.size())) {
1533#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1534#pragma ivdep
1535#endif
1536#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1537#pragma vector aligned
1538#endif
1539#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1540#pragma unroll
1541#endif
1542 for (ordinal_type i=0; i<s.size(); i++)
1543 s[i] *= x.fastAccessCoeff(i);
1544 }
1545 else {
1546 for (ordinal_type i=0; i<s.size(); i++)
1547 s[i] *= x.coeff(i);
1548 }
1549 return const_cast<Vector&>(*this);
1550 }
1551
1553 template <typename S>
1554 KOKKOS_INLINE_FUNCTION
1555 /*volatile*/ Vector& operator *= (const volatile Expr<S>& xx) volatile {
1556 //*this = *this * x;
1557 typedef typename Expr<S>::derived_type expr_type;
1558 const volatile expr_type& x = xx.derived();
1559
1560 if (x.size() > s.size())
1561 this->reset(x.size());
1562
1563#ifdef STOKHOS_DEBUG
1564 if (s.size() < x.size())
1565 Kokkos::Impl::raise_error("Vector::operator*=(): Mismatched sizes");
1566#endif
1567
1568 if (x.hasFastAccess(s.size())) {
1569#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1570#pragma ivdep
1571#endif
1572#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1573#pragma vector aligned
1574#endif
1575#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1576#pragma unroll
1577#endif
1578 for (ordinal_type i=0; i<s.size(); i++)
1579 s[i] *= x.fastAccessCoeff(i);
1580 }
1581 else {
1582 for (ordinal_type i=0; i<s.size(); i++)
1583 s[i] *= x.coeff(i);
1584 }
1585 return const_cast<Vector&>(*this);
1586 }
1587
1589 template <typename S>
1590 KOKKOS_INLINE_FUNCTION
1591 Vector& operator /= (const Expr<S>& xx) {
1592 //*this = *this / x;
1593 typedef typename Expr<S>::derived_type expr_type;
1594 const expr_type& x = xx.derived();
1595
1596 if (x.size() > s.size())
1597 this->reset(x.size());
1598
1599#ifdef STOKHOS_DEBUG
1600 if (s.size() < x.size())
1601 Kokkos::Impl::raise_error("Vector::operator/=(): Mismatched sizes");
1602#endif
1603
1604 if (x.hasFastAccess(s.size())) {
1605#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1606#pragma ivdep
1607#endif
1608#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1609#pragma vector aligned
1610#endif
1611#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1612#pragma unroll
1613#endif
1614 for (ordinal_type i=0; i<s.size(); i++)
1615 s[i] /= x.fastAccessCoeff(i);
1616 }
1617 else {
1618 for (ordinal_type i=0; i<s.size(); i++)
1619 s[i] /= x.coeff(i);
1620 }
1621 return *this;
1622 }
1623
1625 template <typename S>
1626 KOKKOS_INLINE_FUNCTION
1627 Vector& operator /= (const volatile Expr<S>& xx) {
1628 //*this = *this / x;
1629 typedef typename Expr<S>::derived_type expr_type;
1630 const volatile expr_type& x = xx.derived();
1631
1632 if (x.size() > s.size())
1633 this->reset(x.size());
1634
1635#ifdef STOKHOS_DEBUG
1636 if (s.size() < x.size())
1637 Kokkos::Impl::raise_error("Vector::operator/=(): Mismatched sizes");
1638#endif
1639
1640 if (x.hasFastAccess(s.size())) {
1641#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1642#pragma ivdep
1643#endif
1644#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1645#pragma vector aligned
1646#endif
1647#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1648#pragma unroll
1649#endif
1650 for (ordinal_type i=0; i<s.size(); i++)
1651 s[i] /= x.fastAccessCoeff(i);
1652 }
1653 else {
1654 for (ordinal_type i=0; i<s.size(); i++)
1655 s[i] /= x.coeff(i);
1656 }
1657 return *this;
1658 }
1659
1661 template <typename S>
1662 KOKKOS_INLINE_FUNCTION
1663 /*volatile*/ Vector& operator /= (const Expr<S>& xx) volatile {
1664 //*this = *this / x;
1665 typedef typename Expr<S>::derived_type expr_type;
1666 const expr_type& x = xx.derived();
1667
1668 if (x.size() > s.size())
1669 this->reset(x.size());
1670
1671#ifdef STOKHOS_DEBUG
1672 if (s.size() < x.size())
1673 Kokkos::Impl::raise_error("Vector::operator/=(): Mismatched sizes");
1674#endif
1675
1676 if (x.hasFastAccess(s.size())) {
1677#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1678#pragma ivdep
1679#endif
1680#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1681#pragma vector aligned
1682#endif
1683#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1684#pragma unroll
1685#endif
1686 for (ordinal_type i=0; i<s.size(); i++)
1687 s[i] /= x.fastAccessCoeff(i);
1688 }
1689 else {
1690 for (ordinal_type i=0; i<s.size(); i++)
1691 s[i] /= x.coeff(i);
1692 }
1693 return const_cast<Vector&>(*this);
1694 }
1695
1697 template <typename S>
1698 KOKKOS_INLINE_FUNCTION
1699 /*volatile*/ Vector& operator /= (const volatile Expr<S>& xx) volatile {
1700 //*this = *this / x;
1701 typedef typename Expr<S>::derived_type expr_type;
1702 const volatile expr_type& x = xx.derived();
1703
1704 if (x.size() > s.size())
1705 this->reset(x.size());
1706
1707#ifdef STOKHOS_DEBUG
1708 if (s.size() < x.size())
1709 Kokkos::Impl::raise_error("Vector::operator/=(): Mismatched sizes");
1710#endif
1711
1712 if (x.hasFastAccess(s.size())) {
1713#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1714#pragma ivdep
1715#endif
1716#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1717#pragma vector aligned
1718#endif
1719#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1720#pragma unroll
1721#endif
1722 for (ordinal_type i=0; i<s.size(); i++)
1723 s[i] /= x.fastAccessCoeff(i);
1724 }
1725 else {
1726 for (ordinal_type i=0; i<s.size(); i++)
1727 s[i] /= x.coeff(i);
1728 }
1729 return const_cast<Vector&>(*this);
1730 }
1731
1733 KOKKOS_INLINE_FUNCTION
1734 Vector& operator++() {
1735 for (ordinal_type i=0; i<s.size(); i++)
1736 ++(s[i]);
1737 return *this;
1738 }
1739
1741 KOKKOS_INLINE_FUNCTION
1742 volatile Vector& operator++() volatile {
1743 for (ordinal_type i=0; i<s.size(); i++)
1744 ++(s[i]);
1745 return *this;
1746 }
1747
1749 KOKKOS_INLINE_FUNCTION
1750 Vector operator++(int) {
1751 Vector tmp(*this);
1752 ++(*this);
1753 return tmp;
1754 }
1755
1757 KOKKOS_INLINE_FUNCTION
1758 Vector operator++(int) volatile {
1759 Vector tmp(*this);
1760 ++(*this);
1761 return tmp;
1762 }
1763
1765 KOKKOS_INLINE_FUNCTION
1766 Vector& operator--() {
1767 for (ordinal_type i=0; i<s.size(); i++)
1768 --(s[i]);
1769 return *this;
1770 }
1771
1773 KOKKOS_INLINE_FUNCTION
1774 volatile Vector& operator--() volatile {
1775 for (ordinal_type i=0; i<s.size(); i++)
1776 --(s[i]);
1777 return *this;
1778 }
1779
1781 KOKKOS_INLINE_FUNCTION
1782 Vector operator--(int) {
1783 Vector tmp(*this);
1784 --(*this);
1785 return tmp;
1786 }
1787
1789 KOKKOS_INLINE_FUNCTION
1790 Vector operator--(int) volatile {
1791 Vector tmp(*this);
1792 --(*this);
1793 return tmp;
1794 }
1795
1797
1798 KOKKOS_INLINE_FUNCTION
1799 std::string name() const volatile { return "x"; }
1800
1801 protected:
1802
1803 Storage s;
1804
1805 template <typename expr_type>
1806 struct StaticOp {
1807 storage_type& s;
1808 const expr_type& x;
1809
1810 KOKKOS_INLINE_FUNCTION
1811 StaticOp(storage_type& s_, const expr_type& x_) : s(s_), x(x_) {}
1812
1813 template <typename ArgT>
1814 KOKKOS_INLINE_FUNCTION
1815 void operator() (ArgT arg) const {
1816 const int Arg = ArgT::value;
1817 s.template getCoeff<Arg>() = x.template getCoeff<Arg>();
1818 }
1819
1820 };
1821
1822 }; // class Vector
1823 }
1824}
1825
1826#if STOKHOS_USE_MP_VECTOR_SFS_SPEC
1827#include "Sacado_MP_Vector_SFS.hpp"
1828#endif
1829
1830namespace Sacado{
1831 namespace MP {
1832
1834
1838 template <typename T> struct const_expr_ref {
1839 typedef const T type;
1840 };
1841
1843
1847 template <typename S> struct const_expr_ref< Vector<S> > {
1848 typedef const Vector<S>& type;
1849 };
1850
1852
1856 template <typename S> struct const_expr_ref< volatile Vector<S> > {
1857 typedef const volatile Vector<S>& type;
1858 };
1859
1861 template <typename T> struct remove_volatile {
1862 typedef T type;
1863 };
1864 template <typename T> struct remove_volatile<volatile T> {
1865 typedef T type;
1866 };
1867
1869 template <typename T> struct add_volatile {
1870 typedef volatile T type;
1871 };
1872 template <typename T> struct add_volatile<volatile T> {
1873 typedef volatile T type;
1874 };
1875
1876 template <typename Storage>
1877 std::ostream&
1878 operator << (std::ostream& os, const Vector<Storage>& a)
1879 {
1881
1882 os << "[ ";
1883
1884 for (ordinal_type i=0; i<a.size(); i++) {
1885 os << a.coeff(i) << " ";
1886 }
1887
1888 os << "]";
1889 return os;
1890 }
1891
1892 template <typename Storage>
1893 std::ostream&
1894 operator << (std::ostream& os, const volatile Vector<Storage>& a)
1895 {
1897
1898 os << "[ ";
1899
1900 for (ordinal_type i=0; i<a.size(); i++) {
1901 os << a.coeff(i) << " ";
1902 }
1903
1904 os << "]";
1905 return os;
1906 }
1907
1908 template <typename Storage>
1909 std::istream&
1910 operator >> (std::istream& is, Vector<Storage>& a)
1911 {
1913 typedef typename Vector<Storage>::value_type value_type;
1914
1915 //
1916 // Need to check all of this for errors, end-of-line, etc...
1917 //
1918
1919 char b = 0;
1920 if (Storage::is_static) {
1921 is >> b; // "["
1922 for (ordinal_type i=0; i<a.size(); i++) {
1923 is >> a.fastAccessCoeff(i);
1924 }
1925 is >> b; // "]";
1926 }
1927 else {
1928 std::vector<value_type> c;
1929 value_type v;
1930 is >> b; // "["
1931 while (is >> b && b != ']') {
1932 is.putback(b);
1933 is >> v;
1934 c.push_back(v);
1935 }
1936 ordinal_type n = c.size();
1937 a.reset(n);
1938 for (ordinal_type i=0; i<n; ++i)
1939 a.fastAccessCoeff(i) = c[i];
1940 }
1941
1942 return is;
1943 }
1944
1945 //------------------------------------------------------------------------
1946 //------------------------------------------------------------------------
1947
1949 template <unsigned Size = 0>
1950 struct VectorPartition {
1951 static const unsigned PartitionSize = Size;
1952 unsigned begin ;
1953 unsigned end ;
1954
1955 template< typename iType0 , typename iType1 >
1956 KOKKOS_INLINE_FUNCTION
1957 VectorPartition( const iType0 & i0 , const iType1 & i1 ) :
1958 begin(i0), end(i1) {
1959 }
1960 };
1961
1962 template <typename T>
1963 struct is_vector_partition {
1964 static const bool value = false;
1965 };
1966
1967 template <unsigned Size>
1968 struct is_vector_partition< VectorPartition<Size> > {
1969 static const bool value = true;
1970 };
1971
1972 } // namespace MP
1973
1974 template <typename T>
1975 struct IsExpr< MP::Expr<T> > {
1976 static const bool value = true;
1977 };
1978
1979 template <typename T>
1980 struct BaseExprType< MP::Expr<T> > {
1981 typedef typename MP::Expr<T>::derived_type derived_type;
1982 typedef typename derived_type::base_expr_type type;
1983 };
1984
1985 template <typename S>
1986 struct IsExpr< MP::Vector<S> > {
1987 static const bool value = true;
1988 };
1989
1990 template <typename S>
1991 struct BaseExprType< MP::Vector<S> > {
1992 typedef MP::Vector<S> type;
1993 };
1994
1996 template <typename T> struct is_mp_vector {
1997 static const bool value = false;
1998 };
1999 template <typename S> struct is_mp_vector< MP::Vector<S> > {
2000 static const bool value = true;
2001 };
2002 template <typename T> struct is_mp_vector< const T > {
2003 static const bool value = is_mp_vector<T>::value;
2004 };
2005 template <typename T> struct is_mp_vector< T* > {
2006 static const bool value = is_mp_vector<T>::value;
2007 };
2008 template <typename T> struct is_mp_vector< T[] > {
2009 static const bool value = is_mp_vector<T>::value;
2010 };
2011 template <typename T, unsigned N> struct is_mp_vector< T[N] > {
2012 static const bool value = is_mp_vector<T>::value;
2013 };
2014
2015 // Utility function to see if a MP::Vector is really a constant
2016 template <typename Storage>
2017 bool is_constant(const Sacado::MP::Vector<Storage>& x)
2018 {
2019 typedef typename Storage::ordinal_type ordinal_type;
2020 typedef typename Storage::value_type value_type;
2021
2022 // All size-1 vectors are constants
2023 const ordinal_type sz = x.size();
2024 if (sz == 1) return true;
2025
2026 // Maybe use a tolerance????
2027 const value_type val = x.fastAccessCoeff(0);
2028 for (ordinal_type i=1; i<sz; ++i)
2029 if (x.fastAccessCoeff(i) != val) return false;
2030
2031 return true;
2032 }
2033
2034} // namespace Sacado
2035
2036#include "Sacado_MP_Vector_ops.hpp"
2038
2039#if STOKHOS_ALIGN_MEMORY
2040
2041#include <memory>
2042
2043namespace std {
2044
2045template <typename Storage>
2046class allocator< Sacado::MP::Vector< Storage > >
2047 : public Stokhos::aligned_allocator< Sacado::MP::Vector< Storage > > {
2048public:
2049 typedef Sacado::MP::Vector<Storage> T;
2050 typedef Stokhos::aligned_allocator<T> Base;
2051 typedef typename Base::value_type value_type;
2052 typedef typename Base::pointer pointer;
2053 typedef typename Base::const_pointer const_pointer;
2054 typedef typename Base::reference reference;
2055 typedef typename Base::const_reference const_reference;
2056 typedef typename Base::size_type size_type;
2057 typedef typename Base::difference_type difference_type;
2058
2059 template <class U> struct rebind { typedef allocator<U> other; };
2060 allocator() {}
2061 template <class U> allocator(const allocator<U>&) {}
2062};
2063
2064template <typename Storage>
2065class allocator< const Sacado::MP::Vector< Storage > >
2066 : public Stokhos::aligned_allocator< const Sacado::MP::Vector< Storage > > {
2067public:
2068 typedef Sacado::MP::Vector<Storage> T;
2069 typedef Stokhos::aligned_allocator<const T> Base;
2070 typedef typename Base::value_type value_type;
2071 typedef typename Base::pointer pointer;
2072 typedef typename Base::const_pointer const_pointer;
2073 typedef typename Base::reference reference;
2074 typedef typename Base::const_reference const_reference;
2075 typedef typename Base::size_type size_type;
2076 typedef typename Base::difference_type difference_type;
2077
2078 template <class U> struct rebind { typedef allocator<U> other; };
2079 allocator() {}
2080 template <class U> allocator(const allocator<U>&) {}
2081};
2082
2083}
2084
2085#endif
2086
2087#include "Kokkos_NumericTraits.hpp"
2088
2089namespace Kokkos {
2090
2091template <typename Storage>
2092struct reduction_identity< Sacado::MP::Vector<Storage> > {
2093 typedef Sacado::MP::Vector<Storage> Vector;
2094 typedef typename Storage::value_type scalar;
2095 typedef reduction_identity<scalar> RIS;
2096 KOKKOS_FORCEINLINE_FUNCTION constexpr static Vector sum() {
2097 return Vector(RIS::sum());
2098 }
2099 KOKKOS_FORCEINLINE_FUNCTION constexpr static Vector prod() {
2100 return Vector(RIS::prod());
2101 }
2102 KOKKOS_FORCEINLINE_FUNCTION constexpr static Vector max() {
2103 return Vector(RIS::max());
2104 }
2105 KOKKOS_FORCEINLINE_FUNCTION constexpr static Vector min() {
2106 return Vector(RIS::min());
2107 }
2108};
2109
2110namespace Impl {
2111 template <typename Storage>
2112 struct promote<Sacado::MP::Vector<Storage>,false> {
2113 using type = typename Sacado::MP::Vector<Storage>;
2114 };
2115}
2116
2117}
2118
2119#endif // HAVE_STOKHOS_SACADO
2120
2121#endif // SACADO_MP_VECTOR_HPP
expr1 expr1 expr1 expr2 expr1 expr1 c expr2 expr1 c fastAccessCoeff(j) - expr2.val(j)
expr val()
Stokhos::StandardStorage< int, double > storage_type
Kokkos::DefaultHostExecutionSpace execution_space
SparseArrayIterator< index_iterator, value_iterator >::value_reference value(const SparseArrayIterator< index_iterator, value_iterator > &it)
Stokhos::StandardStorage< int, double > Storage
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)
KOKKOS_INLINE_FUNCTION void raise_error(const char *msg)
std::ostream & operator<<(std::ostream &os, const Expr< T > &x)
KOKKOS_INLINE_FUNCTION PCE< Storage > min(const typename PCE< Storage >::value_type &a, const PCE< Storage > &b)
KOKKOS_INLINE_FUNCTION PCE< Storage > max(const typename PCE< Storage >::value_type &a, const PCE< Storage > &b)
KOKKOS_INLINE_FUNCTION bool is_constant(const T &x)
const IndexType const IndexType const IndexType const IndexType const ValueType const ValueType * x
Definition csr_vector.h:265