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 };
117
119 template <typename Storage>
120 class Vector : public Expr< Vector<Storage> > {
121 public:
122
124 typedef Storage storage_type;
125
126 typedef typename storage_type::value_type value_type;
127 typedef typename storage_type::ordinal_type ordinal_type;
128 typedef typename storage_type::execution_space execution_space;
129 typedef typename storage_type::pointer pointer;
130 typedef typename storage_type::volatile_pointer volatile_pointer;
131 typedef typename storage_type::const_pointer const_pointer;
132 typedef typename storage_type::const_volatile_pointer const_volatile_pointer;
133 typedef typename storage_type::reference reference;
134 typedef typename storage_type::volatile_reference volatile_reference;
135 typedef typename storage_type::const_reference const_reference;
136 typedef typename storage_type::const_volatile_reference const_volatile_reference;
137
138 typedef typename execution_space::memory_space memory_space;
139 typedef typename Stokhos::MemoryTraits<memory_space> MemTraits;
140
142 typedef typename ScalarType<value_type>::type scalar_type;
143
144 typedef Vector base_expr_type;
145
147 template < class NewStorageType >
148 struct apply {
149 typedef Vector< NewStorageType > type;
150 };
151
153 static const int num_args = 1;
154
155#if STOKHOS_ALIGN_MEMORY
156 KOKKOS_INLINE_FUNCTION
157 static void* operator new(std::size_t sz) {
158 return MemTraits::alloc(sz);
159 }
160 KOKKOS_INLINE_FUNCTION
161 static void* operator new[](std::size_t sz) {
162 return MemTraits::alloc(sz);
163 }
164 KOKKOS_INLINE_FUNCTION
165 static void* operator new(std::size_t sz, void* ptr) {
166 return ptr;
167 }
168 KOKKOS_INLINE_FUNCTION
169 static void* operator new[](std::size_t sz, void* ptr) {
170 return ptr;
171 }
172 KOKKOS_INLINE_FUNCTION
173 static void operator delete(void* ptr) {
174 MemTraits::free(ptr);
175 }
176 KOKKOS_INLINE_FUNCTION
177 static void operator delete[](void* ptr) {
178 MemTraits::free(ptr);
179 }
180 KOKKOS_INLINE_FUNCTION
181 static void operator delete(void* ptr, void*) {
182 MemTraits::free(ptr);
183 }
184 KOKKOS_INLINE_FUNCTION
185 static void operator delete[](void* ptr, void*) {
186 MemTraits::free(ptr);
187 }
188#endif
189
191
194 KOKKOS_DEFAULTED_FUNCTION
195 Vector() = default;
196
198
201 KOKKOS_INLINE_FUNCTION
202 Vector(const value_type& x) : s(1,x) {}
203
205
209 KOKKOS_INLINE_FUNCTION
210 Vector(ordinal_type sz, pointer v, bool owned) : s(sz,v,owned) {}
211
213
216 KOKKOS_INLINE_FUNCTION
217 Vector(ordinal_type sz, const value_type& x) : s(sz,x) {}
218
220 KOKKOS_INLINE_FUNCTION
221 Vector(const storage_type& ss) : s(ss) {}
222
224 KOKKOS_DEFAULTED_FUNCTION
225 Vector(const Vector& x) = default;
226
228 KOKKOS_INLINE_FUNCTION
229 Vector(const volatile Vector& x) : s(x.s) {}
230
232 template <typename S>
233 KOKKOS_INLINE_FUNCTION
234 Vector(const Expr<S>& xx) :
235 s(xx.derived().size()) {
236 typedef typename Expr<S>::derived_type expr_type;
237 const expr_type& x = xx.derived();
238
239#ifdef STOKHOS_DEBUG
240 if (s.size() != x.size())
241 Kokkos::Impl::raise_error("Vector(): Mismatched sizes");
242#endif
243
244 if (x.hasFastAccess(s.size())) {
245#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
246#pragma ivdep
247#endif
248#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
249#pragma vector aligned
250#endif
251#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
252#pragma unroll
253#endif
254 for (ordinal_type i=0; i<s.size(); i++)
255 s[i] = x.fastAccessCoeff(i);
256 }
257 else {
258 for (ordinal_type i=0; i<s.size(); i++)
259 s[i] = x.coeff(i);
260 }
261 }
262
264
270 KOKKOS_INLINE_FUNCTION
271 Vector(std::initializer_list<value_type> l) : s(l.size(), l.begin()) {
272 if constexpr (Storage::is_static) {
273 const auto lsz = static_cast<ordinal_type>(l.size());
274 const ordinal_type sz = this->size();
275 if (lsz < sz) {
276 if (lsz > 1) {
277 Kokkos::abort("Size mismatch in list initialization of MP Vector with static fixed storage.");
278 }
279 else {
280 const value_type v = lsz > 0 ? *l.begin() : value_type(0);
281 s.init(v);
282 }
283 }
284 }
285 }
286
288 KOKKOS_DEFAULTED_FUNCTION
289 ~Vector() = default;
290
292 KOKKOS_INLINE_FUNCTION
293 void init(const value_type& v) { s.init(v); }
294
296 KOKKOS_INLINE_FUNCTION
297 void init(const value_type& v) volatile { s.init(v); }
298
300 KOKKOS_INLINE_FUNCTION
301 void init(const value_type* v) { s.init(v); }
302
304 KOKKOS_INLINE_FUNCTION
305 void init(const value_type* v) volatile { s.init(v); }
306
308 template <typename S>
309 KOKKOS_INLINE_FUNCTION
310 void init(const Vector<S>& v) {
311 s.init(v.s.coeff(), v.s.size());
312 }
313
315 template <typename S>
316 KOKKOS_INLINE_FUNCTION
317 void init(const Vector<S>& v) volatile {
318 s.init(v.s.coeff(), v.s.size());
319 }
320
322 KOKKOS_INLINE_FUNCTION
323 void load(value_type* v) { s.load(v); }
324
326 KOKKOS_INLINE_FUNCTION
327 void load(value_type* v) volatile { s.load(v); }
328
330 template <typename S>
331 KOKKOS_INLINE_FUNCTION
332 void load(Vector<S>& v) { s.load(v.s.coeff()); }
333
335 template <typename S>
336 KOKKOS_INLINE_FUNCTION
337 void load(Vector<S>& v) volatile { s.load(v.s.coeff()); }
338
340
343 KOKKOS_INLINE_FUNCTION
344 void reset(ordinal_type sz_new) {
345 ordinal_type sz = this->size();
346 s.resize(sz_new);
347 if (sz == 1 && sz_new > sz)
348 for (ordinal_type i=1; i<sz_new; i++)
349 s[i] = s[0];
350 }
351
353
356 KOKKOS_INLINE_FUNCTION
357 void reset(ordinal_type sz_new) volatile {
358 ordinal_type sz = this->size();
359 s.resize(sz_new);
360 if (sz == 1 && sz_new > sz)
361 for (ordinal_type i=1; i<sz_new; i++)
362 s[i] = s[0];
363 }
364
366
375 KOKKOS_INLINE_FUNCTION
376 void copyForWrite() volatile { }
377
379 template <typename S>
380 KOKKOS_INLINE_FUNCTION
381 bool isEqualTo(const Expr<S>& xx) const {
382 const typename Expr<S>::derived_type& x = xx.derived();
383 typedef IsEqual<value_type> IE;
384 if (x.size() != this->size()) return false;
385 bool eq = true;
386 for (ordinal_type i=0; i<this->size(); i++)
387 eq = eq && IE::eval(x.coeff(i), this->coeff(i));
388 return eq;
389 }
390
392 template <typename S>
393 KOKKOS_INLINE_FUNCTION
394 bool isEqualTo(const Expr<S>& xx) const volatile {
395 const typename Expr<S>::derived_type& x = xx.derived();
396 typedef IsEqual<value_type> IE;
397 if (x.size() != this->size()) return false;
398 bool eq = true;
399 for (ordinal_type i=0; i<this->size(); i++)
400 eq = eq && IE::eval(x.coeff(i), this->coeff(i));
401 return eq;
402 }
403
408
410
413 Vector& operator=(std::initializer_list<value_type> l) {
414 const ordinal_type lsz = l.size();
415 if (lsz != s.size())
416 s.resize(lsz);
417 s.init(l.begin(), lsz);
418 return *this;
419 }
420
422
425 /*volatile*/ Vector&
426 operator=(std::initializer_list<value_type> l) volatile {
427 const ordinal_type lsz = l.size();
428 if (lsz != s.size())
429 s.resize(lsz);
430 s.init(l.begin(), lsz);
431 return const_cast<Vector&>(*this);
432 }
433
435 KOKKOS_INLINE_FUNCTION
436 Vector& operator=(const value_type& x) {
437 s.init(x);
438 return *this;
439 }
440
442 KOKKOS_INLINE_FUNCTION
443 /*volatile*/ Vector& operator=(const value_type& x) volatile {
444 s.init(x);
445 return const_cast<Vector&>(*this);
446 }
447
449 KOKKOS_INLINE_FUNCTION
450 Vector& operator=(const Vector& x) {
451 if (this != &x) {
452 s = x.s;
453
454 // For DyamicStorage as a view (is_owned=false), we need to set
455 // the trailing entries when assigning a constant vector (because
456 // the copy constructor in this case doesn't reset the size of this)
457 //
458 // Note: supporting this technically makes the Vector non-POD, even
459 // with a static storage type where this branch will get optimized
460 // out. We would have to remove DynamicStorage-as-a view as an option
461 // or partial specialize on StaticFixedStorage to fix this. However
462 // the volatile operator=() and copy constructor overloads make
463 // Vector non-POD anyway.
464 if (s.size() > x.s.size())
465 for (ordinal_type i=x.s.size(); i<s.size(); i++)
466 s[i] = s[0];
467 }
468
469 return *this;
470 }
471
473 KOKKOS_INLINE_FUNCTION
474 Vector& operator=(const volatile Vector& x) {
475 if (this != &x) {
476 s = x.s;
477
478 // For DyamicStorage as a view (is_owned=false), we need to set
479 // the trailing entries when assigning a constant vector (because
480 // the copy constructor in this case doesn't reset the size of this)
481 //
482 // Note: supporting this technically makes the Vector non-POD, even
483 // with a static storage type where this branch will get optimized
484 // out. We would have to remove DynamicStorage-as-a view as an option
485 // or partial specialize on StaticFixedStorage to fix this. However
486 // the volatile operator=() and copy constructor overloads make
487 // Vector non-POD anyway.
488 if (s.size() > x.s.size())
489 for (ordinal_type i=x.s.size(); i<s.size(); i++)
490 s[i] = s[0];
491 }
492
493 return *this;
494 }
495
497 KOKKOS_INLINE_FUNCTION
498 /*volatile*/ Vector& operator=(const Vector& x) volatile {
499 if (this != &x) {
500 s = x.s;
501
502 // For DyamicStorage as a view (is_owned=false), we need to set
503 // the trailing entries when assigning a constant vector (because
504 // the copy constructor in this case doesn't reset the size of this)
505 //
506 // Note: supporting this technically makes the Vector non-POD, even
507 // with a static storage type where this branch will get optimized
508 // out. We would have to remove DynamicStorage-as-a view as an option
509 // or partial specialize on StaticFixedStorage to fix this. However
510 // the volatile operator=() and copy constructor overloads make
511 // Vector non-POD anyway.
512 if (s.size() > x.s.size())
513 for (ordinal_type i=x.s.size(); i<s.size(); i++)
514 s[i] = s[0];
515 }
516
517 return const_cast<Vector&>(*this);
518 }
519
521 KOKKOS_INLINE_FUNCTION
522 /*volatile*/ Vector& operator=(const volatile Vector& x) volatile {
523 if (this != &x) {
524 s = x.s;
525
526 // For DyamicStorage as a view (is_owned=false), we need to set
527 // the trailing entries when assigning a constant vector (because
528 // the copy constructor in this case doesn't reset the size of this)
529 //
530 // Note: supporting this technically makes the Vector non-POD, even
531 // with a static storage type where this branch will get optimized
532 // out. We would have to remove DynamicStorage-as-a view as an option
533 // or partial specialize on StaticFixedStorage to fix this. However
534 // the volatile operator=() and copy constructor overloads make
535 // Vector non-POD anyway.
536 if (s.size() > x.s.size())
537 for (ordinal_type i=x.s.size(); i<s.size(); i++)
538 s[i] = s[0];
539 }
540
541 return const_cast<Vector&>(*this);
542 }
543
545 template <typename S>
546 KOKKOS_INLINE_FUNCTION
547 Vector& operator=(const Expr<S>& xx) {
548 typedef typename Expr<S>::derived_type expr_type;
549 const expr_type& x = xx.derived();
550
551 this->reset(x.size());
552
553#ifdef STOKHOS_DEBUG
554 if (s.size() != x.size())
555 Kokkos::Impl::raise_error("Vector::operator=(): Mismatched sizes");
556#endif
557
558 if (x.hasFastAccess(s.size())) {
559#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
560#pragma ivdep
561#endif
562#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
563#pragma vector aligned
564#endif
565#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
566#pragma unroll
567#endif
568 for (ordinal_type i=0; i<s.size(); i++)
569 s[i] = x.fastAccessCoeff(i);
570 }
571 else {
572 for (ordinal_type i=0; i<s.size(); i++)
573 s[i] = x.coeff(i);
574 }
575 return *this;
576 }
577
579 template <typename S>
580 KOKKOS_INLINE_FUNCTION
581 /*volatile*/ Vector& operator=(const Expr<S>& xx) volatile {
582 typedef typename Expr<S>::derived_type expr_type;
583 const expr_type& x = xx.derived();
584
585 this->reset(x.size());
586
587#ifdef STOKHOS_DEBUG
588 if (s.size() != x.size())
589 Kokkos::Impl::raise_error("Vector::operator=(): Mismatched sizes");
590#endif
591
592 if (x.hasFastAccess(s.size())) {
593#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
594#pragma ivdep
595#endif
596#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
597#pragma vector aligned
598#endif
599#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
600#pragma unroll
601#endif
602 for (ordinal_type i=0; i<s.size(); i++)
603 s[i] = x.fastAccessCoeff(i);
604 }
605 else {
606 for (ordinal_type i=0; i<s.size(); i++)
607 s[i] = x.coeff(i);
608 }
609 return const_cast<Vector&>(*this);
610 }
611
613 template< typename S >
614 KOKKOS_INLINE_FUNCTION
615 typename std::enable_if<( ! std::is_same<S,void>::value &&
617 ), Vector >
618 ::type const & operator = ( const Expr<S> & xx ) const
619 {
620 const typename Expr<S>::derived_type & x = xx.derived();
621
622#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
623#pragma ivdep
624#endif
625#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
626#pragma vector aligned
627#endif
628#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
629#pragma unroll
630#endif
631 for ( ordinal_type i = 0 ; i < s.size() ; ++i ) { s[i] = x.coeff(i); }
632
633 return *this ;
634 }
635
637 template< typename S >
638 KOKKOS_INLINE_FUNCTION
639 volatile
640 typename std::enable_if<( ! std::is_same<S,void>::value &&
642 ), Vector >
643 ::type const & operator = ( const Expr<S> & xx ) const volatile
644 {
645 const typename Expr<S>::derived_type & x = xx.derived();
646
647#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
648#pragma ivdep
649#endif
650#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
651#pragma vector aligned
652#endif
653#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
654#pragma unroll
655#endif
656 for ( ordinal_type i = 0 ; i < s.size() ; ++i ) { s[i] = x.coeff(i); }
657
658 return *this ;
659 }
660
662
668 KOKKOS_INLINE_FUNCTION
669 const volatile storage_type& storage() const volatile { return s; }
670
672 KOKKOS_INLINE_FUNCTION
673 const storage_type& storage() const { return s; }
674
676 KOKKOS_INLINE_FUNCTION
677 volatile storage_type& storage() volatile { return s; }
678
680 KOKKOS_INLINE_FUNCTION
681 storage_type& storage() { return s; }
682
687
689 KOKKOS_INLINE_FUNCTION
690 const_volatile_reference val() const volatile { return s[0]; }
691
693 KOKKOS_INLINE_FUNCTION
694 const_reference val() const { return s[0]; }
695
697 KOKKOS_INLINE_FUNCTION
698 volatile_reference val() volatile { return s[0]; }
699
701 KOKKOS_INLINE_FUNCTION
702 reference val() { return s[0]; }
703
705
710
712 KOKKOS_INLINE_FUNCTION
713 ordinal_type size() const { return s.size();}
714
716 KOKKOS_INLINE_FUNCTION
717 ordinal_type size() const volatile { return s.size();}
718
720 KOKKOS_INLINE_FUNCTION
721 bool hasFastAccess(ordinal_type sz) const { return s.size()>=sz;}
722
724 KOKKOS_INLINE_FUNCTION
725 bool hasFastAccess(ordinal_type sz) const volatile { return s.size()>=sz;}
726
728 KOKKOS_INLINE_FUNCTION
729 const_pointer coeff() const { return s.coeff();}
730
732 KOKKOS_INLINE_FUNCTION
733 const_volatile_pointer coeff() const volatile { return s.coeff();}
734
736 KOKKOS_INLINE_FUNCTION
737 volatile_pointer coeff() volatile { return s.coeff();}
738
740 KOKKOS_INLINE_FUNCTION
741 pointer coeff() { return s.coeff();}
742
744 KOKKOS_INLINE_FUNCTION
745 value_type coeff(ordinal_type i) const volatile {
746 return i<s.size() ? s[i] : s[0]; }
747
749 KOKKOS_INLINE_FUNCTION
750 value_type coeff(ordinal_type i) const {
751 return i<s.size() ? s[i] : s[0]; }
752
754 KOKKOS_INLINE_FUNCTION
755 value_type coeff(ordinal_type i) volatile {
756 return i<s.size() ? s[i] : s[0]; }
757
759 KOKKOS_INLINE_FUNCTION
760 value_type coeff(ordinal_type i) {
761 return i<s.size() ? s[i] : s[0]; }
762
764 KOKKOS_INLINE_FUNCTION
765 const_volatile_reference fastAccessCoeff(ordinal_type i) const volatile {
766 return s[i];}
767
769 KOKKOS_INLINE_FUNCTION
770 const_reference fastAccessCoeff(ordinal_type i) const {
771 return s[i];}
772
774 KOKKOS_INLINE_FUNCTION
775 volatile_reference fastAccessCoeff(ordinal_type i) volatile {
776 return s[i];}
777
779 KOKKOS_INLINE_FUNCTION
780 reference fastAccessCoeff(ordinal_type i) {
781 return s[i];}
782
784 KOKKOS_INLINE_FUNCTION
785 const_volatile_reference operator[](ordinal_type i) const volatile {
786 return s[i];}
787
789 KOKKOS_INLINE_FUNCTION
790 const_reference operator[](ordinal_type i) const {
791 return s[i];}
792
794 KOKKOS_INLINE_FUNCTION
795 volatile_reference operator[](ordinal_type i) volatile {
796 return s[i];}
797
799 KOKKOS_INLINE_FUNCTION
800 reference operator[](ordinal_type i) {
801 return s[i];}
802
803 template <int i>
804 KOKKOS_INLINE_FUNCTION
805 value_type getCoeff() const volatile {
806 return s.template getCoeff<i>(); }
807
808 template <int i>
809 KOKKOS_INLINE_FUNCTION
810 value_type getCoeff() const {
811 return s.template getCoeff<i>(); }
812
813 template <int i>
814 KOKKOS_INLINE_FUNCTION
815 volatile_reference getCoeff() volatile {
816 return s.template getCoeff<i>(); }
817
818 template <int i>
819 KOKKOS_INLINE_FUNCTION
820 reference getCoeff() {
821 return s.template getCoeff<i>(); }
822
824 KOKKOS_INLINE_FUNCTION
825 pointer begin() { return s.coeff(); }
826
828 KOKKOS_INLINE_FUNCTION
829 const_pointer begin() const { return s.coeff(); }
830
832 KOKKOS_INLINE_FUNCTION
833 volatile_pointer begin() volatile { return s.coeff(); }
834
836 KOKKOS_INLINE_FUNCTION
837 const_volatile_pointer begin() const volatile { return s.coeff(); }
838
840 KOKKOS_INLINE_FUNCTION
841 const_pointer cbegin() const { return s.coeff(); }
842
844 KOKKOS_INLINE_FUNCTION
845 const_volatile_pointer cbegin() const volatile { return s.coeff(); }
846
848 KOKKOS_INLINE_FUNCTION
849 pointer end() { return s.coeff() + s.size(); }
850
852 KOKKOS_INLINE_FUNCTION
853 const_pointer end() const { return s.coeff() + s.size(); }
854
856 KOKKOS_INLINE_FUNCTION
857 volatile_pointer end() volatile { return s.coeff() + s.size(); }
858
860 KOKKOS_INLINE_FUNCTION
861 const_volatile_pointer end() const volatile { return s.coeff() + s.size(); }
862
864 KOKKOS_INLINE_FUNCTION
865 const_pointer cend() const { return s.coeff()+ s.size(); }
866
868 KOKKOS_INLINE_FUNCTION
869 const_volatile_pointer cend() const volatile { return s.coeff()+ s.size(); }
870
872
877
879 KOKKOS_INLINE_FUNCTION
880 Vector& operator += (const value_type& x) {
881#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
882#pragma ivdep
883#endif
884#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
885#pragma vector aligned
886#endif
887#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
888#pragma unroll
889#endif
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#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
899#pragma ivdep
900#endif
901#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
902#pragma vector aligned
903#endif
904#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
905#pragma unroll
906#endif
907 for (ordinal_type i=0; i<s.size(); i++)
908 s[i] += x;
909 return *this;
910 }
911
913 KOKKOS_INLINE_FUNCTION
914 /*volatile*/ Vector& operator += (const value_type& x) volatile {
915#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
916#pragma ivdep
917#endif
918#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
919#pragma vector aligned
920#endif
921#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
922#pragma unroll
923#endif
924 for (ordinal_type i=0; i<s.size(); i++)
925 s[i] += x;
926 return const_cast<Vector&>(*this);
927 }
928
930 KOKKOS_INLINE_FUNCTION
931 /*volatile*/ Vector& operator += (const volatile value_type& x) volatile {
932#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
933#pragma ivdep
934#endif
935#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
936#pragma vector aligned
937#endif
938#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
939#pragma unroll
940#endif
941 for (ordinal_type i=0; i<s.size(); i++)
942 s[i] += x;
943 return const_cast<Vector&>(*this);
944 }
945
947 KOKKOS_INLINE_FUNCTION
948 Vector& operator -= (const value_type& x) {
949#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
950#pragma ivdep
951#endif
952#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
953#pragma vector aligned
954#endif
955#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
956#pragma unroll
957#endif
958 for (ordinal_type i=0; i<s.size(); i++)
959 s[i] -= x;
960 return *this;
961 }
962
964 KOKKOS_INLINE_FUNCTION
965 Vector& operator -= (const volatile value_type& x) {
966#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
967#pragma ivdep
968#endif
969#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
970#pragma vector aligned
971#endif
972#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
973#pragma unroll
974#endif
975 for (ordinal_type i=0; i<s.size(); i++)
976 s[i] -= x;
977 return *this;
978 }
979
981 KOKKOS_INLINE_FUNCTION
982 /*volatile*/ Vector& operator -= (const value_type& x) volatile {
983#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
984#pragma ivdep
985#endif
986#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
987#pragma vector aligned
988#endif
989#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
990#pragma unroll
991#endif
992 for (ordinal_type i=0; i<s.size(); i++)
993 s[i] -= x;
994 return const_cast<Vector&>(*this);
995 }
996
998 KOKKOS_INLINE_FUNCTION
999 /*volatile*/ Vector& operator -= (const volatile value_type& x) volatile {
1000#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1001#pragma ivdep
1002#endif
1003#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1004#pragma vector aligned
1005#endif
1006#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1007#pragma unroll
1008#endif
1009 for (ordinal_type i=0; i<s.size(); i++)
1010 s[i] -= x;
1011 return const_cast<Vector&>(*this);
1012 }
1013
1015 KOKKOS_INLINE_FUNCTION
1016 Vector& operator *= (const value_type& x) {
1017#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1018#pragma ivdep
1019#endif
1020#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1021#pragma vector aligned
1022#endif
1023#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1024#pragma unroll
1025#endif
1026 for (ordinal_type i=0; i<s.size(); i++)
1027 s[i] *= x;
1028 return *this;
1029 }
1030
1032 KOKKOS_INLINE_FUNCTION
1033 Vector& operator *= (const volatile value_type& x) {
1034#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1035#pragma ivdep
1036#endif
1037#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1038#pragma vector aligned
1039#endif
1040#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1041#pragma unroll
1042#endif
1043 for (ordinal_type i=0; i<s.size(); i++)
1044 s[i] *= x;
1045 return *this;
1046 }
1047
1049 KOKKOS_INLINE_FUNCTION
1050 /*volatile*/ Vector& operator *= (const value_type& x) volatile {
1051#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1052#pragma ivdep
1053#endif
1054#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1055#pragma vector aligned
1056#endif
1057#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1058#pragma unroll
1059#endif
1060 for (ordinal_type i=0; i<s.size(); i++)
1061 s[i] *= x;
1062 return const_cast<Vector&>(*this);
1063 }
1064
1066 KOKKOS_INLINE_FUNCTION
1067 /*volatile*/ Vector& operator *= (const volatile value_type& x) volatile {
1068#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1069#pragma ivdep
1070#endif
1071#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1072#pragma vector aligned
1073#endif
1074#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1075#pragma unroll
1076#endif
1077 for (ordinal_type i=0; i<s.size(); i++)
1078 s[i] *= x;
1079 return const_cast<Vector&>(*this);
1080 }
1081
1083 KOKKOS_INLINE_FUNCTION
1084 Vector& operator /= (const value_type& x) {
1085#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1086#pragma ivdep
1087#endif
1088#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1089#pragma vector aligned
1090#endif
1091#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1092#pragma unroll
1093#endif
1094 for (ordinal_type i=0; i<s.size(); i++)
1095 s[i] /= x;
1096 return *this;
1097 }
1098
1100 KOKKOS_INLINE_FUNCTION
1101 Vector& operator /= (const volatile value_type& x) {
1102#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1103#pragma ivdep
1104#endif
1105#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1106#pragma vector aligned
1107#endif
1108#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1109#pragma unroll
1110#endif
1111 for (ordinal_type i=0; i<s.size(); i++)
1112 s[i] /= x;
1113 return *this;
1114 }
1115
1117 KOKKOS_INLINE_FUNCTION
1118 /*volatile*/ Vector& operator /= (const value_type& x) volatile {
1119#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1120#pragma ivdep
1121#endif
1122#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1123#pragma vector aligned
1124#endif
1125#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1126#pragma unroll
1127#endif
1128 for (ordinal_type i=0; i<s.size(); i++)
1129 s[i] /= x;
1130 return const_cast<Vector&>(*this);
1131 }
1132
1134 KOKKOS_INLINE_FUNCTION
1135 /*volatile*/ Vector& operator /= (const volatile value_type& x) volatile {
1136#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1137#pragma ivdep
1138#endif
1139#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1140#pragma vector aligned
1141#endif
1142#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1143#pragma unroll
1144#endif
1145 for (ordinal_type i=0; i<s.size(); i++)
1146 s[i] /= x;
1147 return const_cast<Vector&>(*this);
1148 }
1149
1151 template <typename S>
1152 KOKKOS_INLINE_FUNCTION
1153 Vector& operator += (const Expr<S>& xx) {
1154 //*this = *this + x;
1155 typedef typename Expr<S>::derived_type expr_type;
1156 const expr_type& x = xx.derived();
1157
1158 if (x.size() > s.size())
1159 this->reset(x.size());
1160
1161#ifdef STOKHOS_DEBUG
1162 if (s.size() < x.size())
1163 Kokkos::Impl::raise_error("Vector::operator+=(): Mismatched sizes");
1164#endif
1165
1166 if (x.hasFastAccess(s.size())) {
1167#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1168#pragma ivdep
1169#endif
1170#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1171#pragma vector aligned
1172#endif
1173#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1174#pragma unroll
1175#endif
1176 for (ordinal_type i=0; i<s.size(); i++)
1177 s[i] += x.fastAccessCoeff(i);
1178 }
1179 else {
1180 for (ordinal_type i=0; i<s.size(); i++)
1181 s[i] += x.coeff(i);
1182 }
1183 return *this;
1184 }
1185
1187 template <typename S>
1188 KOKKOS_INLINE_FUNCTION
1189 Vector& operator += (const volatile Expr<S>& xx) {
1190 //*this = *this + x;
1191 typedef typename Expr<S>::derived_type expr_type;
1192 const volatile expr_type& x = xx.derived();
1193
1194 if (x.size() > s.size())
1195 this->reset(x.size());
1196
1197#ifdef STOKHOS_DEBUG
1198 if (s.size() < x.size())
1199 Kokkos::Impl::raise_error("Vector::operator+=(): Mismatched sizes");
1200#endif
1201
1202 if (x.hasFastAccess(s.size())) {
1203#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1204#pragma ivdep
1205#endif
1206#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1207#pragma vector aligned
1208#endif
1209#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1210#pragma unroll
1211#endif
1212 for (ordinal_type i=0; i<s.size(); i++)
1213 s[i] += x.fastAccessCoeff(i);
1214 }
1215 else {
1216 for (ordinal_type i=0; i<s.size(); i++)
1217 s[i] += x.coeff(i);
1218 }
1219 return *this;
1220 }
1221
1223 template <typename S>
1224 KOKKOS_INLINE_FUNCTION
1225 /*volatile*/ Vector& operator += (const Expr<S>& xx) volatile {
1226 //*this = *this + x;
1227 typedef typename Expr<S>::derived_type expr_type;
1228 const expr_type& x = xx.derived();
1229
1230 if (x.size() > s.size())
1231 this->reset(x.size());
1232
1233#ifdef STOKHOS_DEBUG
1234 if (s.size() < x.size())
1235 Kokkos::Impl::raise_error("Vector::operator+=(): Mismatched sizes");
1236#endif
1237
1238 if (x.hasFastAccess(s.size())) {
1239#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1240#pragma ivdep
1241#endif
1242#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1243#pragma vector aligned
1244#endif
1245#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1246#pragma unroll
1247#endif
1248 for (ordinal_type i=0; i<s.size(); i++)
1249 s[i] += x.fastAccessCoeff(i);
1250 }
1251 else {
1252 for (ordinal_type i=0; i<s.size(); i++)
1253 s[i] += x.coeff(i);
1254 }
1255 return const_cast<Vector&>(*this);
1256 }
1257
1259 template <typename S>
1260 KOKKOS_INLINE_FUNCTION
1261 /*volatile*/ Vector& operator += (const volatile Expr<S>& xx) volatile {
1262 //*this = *this + x;
1263 typedef typename Expr<S>::derived_type expr_type;
1264 const volatile expr_type& x = xx.derived();
1265
1266 if (x.size() > s.size())
1267 this->reset(x.size());
1268
1269#ifdef STOKHOS_DEBUG
1270 if (s.size() < x.size())
1271 Kokkos::Impl::raise_error("Vector::operator+=(): Mismatched sizes");
1272#endif
1273
1274 if (x.hasFastAccess(s.size())) {
1275#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1276#pragma ivdep
1277#endif
1278#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1279#pragma vector aligned
1280#endif
1281#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1282#pragma unroll
1283#endif
1284 for (ordinal_type i=0; i<s.size(); i++)
1285 s[i] += x.fastAccessCoeff(i);
1286 }
1287 else {
1288 for (ordinal_type i=0; i<s.size(); i++)
1289 s[i] += x.coeff(i);
1290 }
1291 return const_cast<Vector&>(*this);
1292 }
1293
1295 template <typename S>
1296 KOKKOS_INLINE_FUNCTION
1297 Vector& operator -= (const Expr<S>& xx) {
1298 //*this = *this - x;
1299 typedef typename Expr<S>::derived_type expr_type;
1300 const expr_type& x = xx.derived();
1301
1302 if (x.size() > s.size())
1303 this->reset(x.size());
1304
1305#ifdef STOKHOS_DEBUG
1306 if (s.size() < x.size())
1307 Kokkos::Impl::raise_error("Vector::operator-=(): Mismatched sizes");
1308#endif
1309
1310 if (x.hasFastAccess(s.size())) {
1311#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1312#pragma ivdep
1313#endif
1314#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1315#pragma vector aligned
1316#endif
1317#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1318#pragma unroll
1319#endif
1320 for (ordinal_type i=0; i<s.size(); i++)
1321 s[i] -= x.fastAccessCoeff(i);
1322 }
1323 else {
1324 for (ordinal_type i=0; i<s.size(); i++)
1325 s[i] -= x.coeff(i);
1326 }
1327 return *this;
1328 }
1329
1331 template <typename S>
1332 KOKKOS_INLINE_FUNCTION
1333 Vector& operator -= (const volatile Expr<S>& xx) {
1334 //*this = *this - x;
1335 typedef typename Expr<S>::derived_type expr_type;
1336 const volatile expr_type& x = xx.derived();
1337
1338 if (x.size() > s.size())
1339 this->reset(x.size());
1340
1341#ifdef STOKHOS_DEBUG
1342 if (s.size() < x.size())
1343 Kokkos::Impl::raise_error("Vector::operator-=(): Mismatched sizes");
1344#endif
1345
1346 if (x.hasFastAccess(s.size())) {
1347#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1348#pragma ivdep
1349#endif
1350#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1351#pragma vector aligned
1352#endif
1353#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1354#pragma unroll
1355#endif
1356 for (ordinal_type i=0; i<s.size(); i++)
1357 s[i] -= x.fastAccessCoeff(i);
1358 }
1359 else {
1360 for (ordinal_type i=0; i<s.size(); i++)
1361 s[i] -= x.coeff(i);
1362 }
1363 return *this;
1364 }
1365
1367 template <typename S>
1368 KOKKOS_INLINE_FUNCTION
1369 /*volatile*/ Vector& operator -= (const Expr<S>& xx) volatile {
1370 //*this = *this - x;
1371 typedef typename Expr<S>::derived_type expr_type;
1372 const expr_type& x = xx.derived();
1373
1374 if (x.size() > s.size())
1375 this->reset(x.size());
1376
1377#ifdef STOKHOS_DEBUG
1378 if (s.size() < x.size())
1379 Kokkos::Impl::raise_error("Vector::operator-=(): Mismatched sizes");
1380#endif
1381
1382 if (x.hasFastAccess(s.size())) {
1383#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1384#pragma ivdep
1385#endif
1386#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1387#pragma vector aligned
1388#endif
1389#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1390#pragma unroll
1391#endif
1392 for (ordinal_type i=0; i<s.size(); i++)
1393 s[i] -= x.fastAccessCoeff(i);
1394 }
1395 else {
1396 for (ordinal_type i=0; i<s.size(); i++)
1397 s[i] -= x.coeff(i);
1398 }
1399 return const_cast<Vector&>(*this);
1400 }
1401
1403 template <typename S>
1404 KOKKOS_INLINE_FUNCTION
1405 /*volatile*/ Vector& operator -= (const volatile Expr<S>& xx) volatile {
1406 //*this = *this - x;
1407 typedef typename Expr<S>::derived_type expr_type;
1408 const volatile expr_type& x = xx.derived();
1409
1410 if (x.size() > s.size())
1411 this->reset(x.size());
1412
1413#ifdef STOKHOS_DEBUG
1414 if (s.size() < x.size())
1415 Kokkos::Impl::raise_error("Vector::operator-=(): Mismatched sizes");
1416#endif
1417
1418 if (x.hasFastAccess(s.size())) {
1419#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1420#pragma ivdep
1421#endif
1422#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1423#pragma vector aligned
1424#endif
1425#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1426#pragma unroll
1427#endif
1428 for (ordinal_type i=0; i<s.size(); i++)
1429 s[i] -= x.fastAccessCoeff(i);
1430 }
1431 else {
1432 for (ordinal_type i=0; i<s.size(); i++)
1433 s[i] -= x.coeff(i);
1434 }
1435 return const_cast<Vector&>(*this);
1436 }
1437
1439 template <typename S>
1440 KOKKOS_INLINE_FUNCTION
1441 Vector& operator *= (const Expr<S>& xx) {
1442 //*this = *this * x;
1443 typedef typename Expr<S>::derived_type expr_type;
1444 const expr_type& x = xx.derived();
1445
1446 if (x.size() > s.size())
1447 this->reset(x.size());
1448
1449#ifdef STOKHOS_DEBUG
1450 if (s.size() < x.size())
1451 Kokkos::Impl::raise_error("Vector::operator*=(): Mismatched sizes");
1452#endif
1453
1454 if (x.hasFastAccess(s.size())) {
1455#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1456#pragma ivdep
1457#endif
1458#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1459#pragma vector aligned
1460#endif
1461#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1462#pragma unroll
1463#endif
1464 for (ordinal_type i=0; i<s.size(); i++)
1465 s[i] *= x.fastAccessCoeff(i);
1466 }
1467 else {
1468 for (ordinal_type i=0; i<s.size(); i++)
1469 s[i] *= x.coeff(i);
1470 }
1471 return *this;
1472 }
1473
1475 template <typename S>
1476 KOKKOS_INLINE_FUNCTION
1477 Vector& operator *= (const volatile Expr<S>& xx) {
1478 //*this = *this * x;
1479 typedef typename Expr<S>::derived_type expr_type;
1480 const volatile expr_type& x = xx.derived();
1481
1482 if (x.size() > s.size())
1483 this->reset(x.size());
1484
1485#ifdef STOKHOS_DEBUG
1486 if (s.size() < x.size())
1487 Kokkos::Impl::raise_error("Vector::operator*=(): Mismatched sizes");
1488#endif
1489
1490 if (x.hasFastAccess(s.size())) {
1491#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1492#pragma ivdep
1493#endif
1494#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1495#pragma vector aligned
1496#endif
1497#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1498#pragma unroll
1499#endif
1500 for (ordinal_type i=0; i<s.size(); i++)
1501 s[i] *= x.fastAccessCoeff(i);
1502 }
1503 else {
1504 for (ordinal_type i=0; i<s.size(); i++)
1505 s[i] *= x.coeff(i);
1506 }
1507 return *this;
1508 }
1509
1511 template <typename S>
1512 KOKKOS_INLINE_FUNCTION
1513 /*volatile*/ Vector& operator *= (const Expr<S>& xx) volatile {
1514 //*this = *this * x;
1515 typedef typename Expr<S>::derived_type expr_type;
1516 const expr_type& x = xx.derived();
1517
1518 if (x.size() > s.size())
1519 this->reset(x.size());
1520
1521#ifdef STOKHOS_DEBUG
1522 if (s.size() < x.size())
1523 Kokkos::Impl::raise_error("Vector::operator*=(): Mismatched sizes");
1524#endif
1525
1526 if (x.hasFastAccess(s.size())) {
1527#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1528#pragma ivdep
1529#endif
1530#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1531#pragma vector aligned
1532#endif
1533#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1534#pragma unroll
1535#endif
1536 for (ordinal_type i=0; i<s.size(); i++)
1537 s[i] *= x.fastAccessCoeff(i);
1538 }
1539 else {
1540 for (ordinal_type i=0; i<s.size(); i++)
1541 s[i] *= x.coeff(i);
1542 }
1543 return const_cast<Vector&>(*this);
1544 }
1545
1547 template <typename S>
1548 KOKKOS_INLINE_FUNCTION
1549 /*volatile*/ Vector& operator *= (const volatile Expr<S>& xx) volatile {
1550 //*this = *this * x;
1551 typedef typename Expr<S>::derived_type expr_type;
1552 const volatile expr_type& x = xx.derived();
1553
1554 if (x.size() > s.size())
1555 this->reset(x.size());
1556
1557#ifdef STOKHOS_DEBUG
1558 if (s.size() < x.size())
1559 Kokkos::Impl::raise_error("Vector::operator*=(): Mismatched sizes");
1560#endif
1561
1562 if (x.hasFastAccess(s.size())) {
1563#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1564#pragma ivdep
1565#endif
1566#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1567#pragma vector aligned
1568#endif
1569#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1570#pragma unroll
1571#endif
1572 for (ordinal_type i=0; i<s.size(); i++)
1573 s[i] *= x.fastAccessCoeff(i);
1574 }
1575 else {
1576 for (ordinal_type i=0; i<s.size(); i++)
1577 s[i] *= x.coeff(i);
1578 }
1579 return const_cast<Vector&>(*this);
1580 }
1581
1583 template <typename S>
1584 KOKKOS_INLINE_FUNCTION
1585 Vector& operator /= (const Expr<S>& xx) {
1586 //*this = *this / x;
1587 typedef typename Expr<S>::derived_type expr_type;
1588 const expr_type& x = xx.derived();
1589
1590 if (x.size() > s.size())
1591 this->reset(x.size());
1592
1593#ifdef STOKHOS_DEBUG
1594 if (s.size() < x.size())
1595 Kokkos::Impl::raise_error("Vector::operator/=(): Mismatched sizes");
1596#endif
1597
1598 if (x.hasFastAccess(s.size())) {
1599#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1600#pragma ivdep
1601#endif
1602#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1603#pragma vector aligned
1604#endif
1605#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1606#pragma unroll
1607#endif
1608 for (ordinal_type i=0; i<s.size(); i++)
1609 s[i] /= x.fastAccessCoeff(i);
1610 }
1611 else {
1612 for (ordinal_type i=0; i<s.size(); i++)
1613 s[i] /= x.coeff(i);
1614 }
1615 return *this;
1616 }
1617
1619 template <typename S>
1620 KOKKOS_INLINE_FUNCTION
1621 Vector& operator /= (const volatile Expr<S>& xx) {
1622 //*this = *this / x;
1623 typedef typename Expr<S>::derived_type expr_type;
1624 const volatile expr_type& x = xx.derived();
1625
1626 if (x.size() > s.size())
1627 this->reset(x.size());
1628
1629#ifdef STOKHOS_DEBUG
1630 if (s.size() < x.size())
1631 Kokkos::Impl::raise_error("Vector::operator/=(): Mismatched sizes");
1632#endif
1633
1634 if (x.hasFastAccess(s.size())) {
1635#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1636#pragma ivdep
1637#endif
1638#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1639#pragma vector aligned
1640#endif
1641#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1642#pragma unroll
1643#endif
1644 for (ordinal_type i=0; i<s.size(); i++)
1645 s[i] /= x.fastAccessCoeff(i);
1646 }
1647 else {
1648 for (ordinal_type i=0; i<s.size(); i++)
1649 s[i] /= x.coeff(i);
1650 }
1651 return *this;
1652 }
1653
1655 template <typename S>
1656 KOKKOS_INLINE_FUNCTION
1657 /*volatile*/ Vector& operator /= (const Expr<S>& xx) volatile {
1658 //*this = *this / x;
1659 typedef typename Expr<S>::derived_type expr_type;
1660 const expr_type& x = xx.derived();
1661
1662 if (x.size() > s.size())
1663 this->reset(x.size());
1664
1665#ifdef STOKHOS_DEBUG
1666 if (s.size() < x.size())
1667 Kokkos::Impl::raise_error("Vector::operator/=(): Mismatched sizes");
1668#endif
1669
1670 if (x.hasFastAccess(s.size())) {
1671#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1672#pragma ivdep
1673#endif
1674#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1675#pragma vector aligned
1676#endif
1677#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1678#pragma unroll
1679#endif
1680 for (ordinal_type i=0; i<s.size(); i++)
1681 s[i] /= x.fastAccessCoeff(i);
1682 }
1683 else {
1684 for (ordinal_type i=0; i<s.size(); i++)
1685 s[i] /= x.coeff(i);
1686 }
1687 return const_cast<Vector&>(*this);
1688 }
1689
1691 template <typename S>
1692 KOKKOS_INLINE_FUNCTION
1693 /*volatile*/ Vector& operator /= (const volatile Expr<S>& xx) volatile {
1694 //*this = *this / x;
1695 typedef typename Expr<S>::derived_type expr_type;
1696 const volatile expr_type& x = xx.derived();
1697
1698 if (x.size() > s.size())
1699 this->reset(x.size());
1700
1701#ifdef STOKHOS_DEBUG
1702 if (s.size() < x.size())
1703 Kokkos::Impl::raise_error("Vector::operator/=(): Mismatched sizes");
1704#endif
1705
1706 if (x.hasFastAccess(s.size())) {
1707#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1708#pragma ivdep
1709#endif
1710#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1711#pragma vector aligned
1712#endif
1713#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1714#pragma unroll
1715#endif
1716 for (ordinal_type i=0; i<s.size(); i++)
1717 s[i] /= x.fastAccessCoeff(i);
1718 }
1719 else {
1720 for (ordinal_type i=0; i<s.size(); i++)
1721 s[i] /= x.coeff(i);
1722 }
1723 return const_cast<Vector&>(*this);
1724 }
1725
1727 KOKKOS_INLINE_FUNCTION
1728 Vector& operator++() {
1729 for (ordinal_type i=0; i<s.size(); i++)
1730 ++(s[i]);
1731 return *this;
1732 }
1733
1735 KOKKOS_INLINE_FUNCTION
1736 volatile Vector& operator++() volatile {
1737 for (ordinal_type i=0; i<s.size(); i++)
1738 ++(s[i]);
1739 return *this;
1740 }
1741
1743 KOKKOS_INLINE_FUNCTION
1744 Vector operator++(int) {
1745 Vector tmp(*this);
1746 ++(*this);
1747 return tmp;
1748 }
1749
1751 KOKKOS_INLINE_FUNCTION
1752 Vector operator++(int) volatile {
1753 Vector tmp(*this);
1754 ++(*this);
1755 return tmp;
1756 }
1757
1759 KOKKOS_INLINE_FUNCTION
1760 Vector& operator--() {
1761 for (ordinal_type i=0; i<s.size(); i++)
1762 --(s[i]);
1763 return *this;
1764 }
1765
1767 KOKKOS_INLINE_FUNCTION
1768 volatile Vector& operator--() volatile {
1769 for (ordinal_type i=0; i<s.size(); i++)
1770 --(s[i]);
1771 return *this;
1772 }
1773
1775 KOKKOS_INLINE_FUNCTION
1776 Vector operator--(int) {
1777 Vector tmp(*this);
1778 --(*this);
1779 return tmp;
1780 }
1781
1783 KOKKOS_INLINE_FUNCTION
1784 Vector operator--(int) volatile {
1785 Vector tmp(*this);
1786 --(*this);
1787 return tmp;
1788 }
1789
1791
1792 KOKKOS_INLINE_FUNCTION
1793 std::string name() const volatile { return "x"; }
1794
1795 protected:
1796
1797 Storage s;
1798
1799 template <typename expr_type>
1800 struct StaticOp {
1801 storage_type& s;
1802 const expr_type& x;
1803
1804 KOKKOS_INLINE_FUNCTION
1805 StaticOp(storage_type& s_, const expr_type& x_) : s(s_), x(x_) {}
1806
1807 template <typename ArgT>
1808 KOKKOS_INLINE_FUNCTION
1809 void operator() (ArgT arg) const {
1810 const int Arg = ArgT::value;
1811 s.template getCoeff<Arg>() = x.template getCoeff<Arg>();
1812 }
1813
1814 };
1815
1816 }; // class Vector
1817 }
1818}
1819
1820#if STOKHOS_USE_MP_VECTOR_SFS_SPEC
1821#include "Sacado_MP_Vector_SFS.hpp"
1822#endif
1823
1824namespace Sacado{
1825 namespace MP {
1826
1828
1832 template <typename T> struct const_expr_ref {
1833 typedef const T type;
1834 };
1835
1837
1841 template <typename S> struct const_expr_ref< Vector<S> > {
1842 typedef const Vector<S>& type;
1843 };
1844
1846
1850 template <typename S> struct const_expr_ref< volatile Vector<S> > {
1851 typedef const volatile Vector<S>& type;
1852 };
1853
1855 template <typename T> struct remove_volatile {
1856 typedef T type;
1857 };
1858 template <typename T> struct remove_volatile<volatile T> {
1859 typedef T type;
1860 };
1861
1863 template <typename T> struct add_volatile {
1864 typedef volatile T type;
1865 };
1866 template <typename T> struct add_volatile<volatile T> {
1867 typedef volatile T type;
1868 };
1869
1870 template <typename Storage>
1871 std::ostream&
1872 operator << (std::ostream& os, const Vector<Storage>& a)
1873 {
1874 typedef typename Vector<Storage>::ordinal_type ordinal_type;
1875
1876 os << "[ ";
1877
1878 for (ordinal_type i=0; i<a.size(); i++) {
1879 os << a.coeff(i) << " ";
1880 }
1881
1882 os << "]";
1883 return os;
1884 }
1885
1886 template <typename Storage>
1887 std::ostream&
1888 operator << (std::ostream& os, const volatile Vector<Storage>& a)
1889 {
1890 typedef typename Vector<Storage>::ordinal_type ordinal_type;
1891
1892 os << "[ ";
1893
1894 for (ordinal_type i=0; i<a.size(); i++) {
1895 os << a.coeff(i) << " ";
1896 }
1897
1898 os << "]";
1899 return os;
1900 }
1901
1902 template <typename Storage>
1903 std::istream&
1904 operator >> (std::istream& is, Vector<Storage>& a)
1905 {
1906 typedef typename Vector<Storage>::ordinal_type ordinal_type;
1907 typedef typename Vector<Storage>::value_type value_type;
1908
1909 //
1910 // Need to check all of this for errors, end-of-line, etc...
1911 //
1912
1913 char b = 0;
1914 if (Storage::is_static) {
1915 is >> b; // "["
1916 for (ordinal_type i=0; i<a.size(); i++) {
1917 is >> a.fastAccessCoeff(i);
1918 }
1919 is >> b; // "]";
1920 }
1921 else {
1922 std::vector<value_type> c;
1923 value_type v;
1924 is >> b; // "["
1925 while (is >> b && b != ']') {
1926 is.putback(b);
1927 is >> v;
1928 c.push_back(v);
1929 }
1930 ordinal_type n = c.size();
1931 a.reset(n);
1932 for (ordinal_type i=0; i<n; ++i)
1933 a.fastAccessCoeff(i) = c[i];
1934 }
1935
1936 return is;
1937 }
1938
1939 //------------------------------------------------------------------------
1940 //------------------------------------------------------------------------
1941
1943 template <unsigned Size = 0>
1944 struct VectorPartition {
1945 static const unsigned PartitionSize = Size;
1946 unsigned begin ;
1947 unsigned end ;
1948
1949 template< typename iType0 , typename iType1 >
1950 KOKKOS_INLINE_FUNCTION
1951 VectorPartition( const iType0 & i0 , const iType1 & i1 ) :
1952 begin(i0), end(i1) {
1953 }
1954 };
1955
1956 template <typename T>
1957 struct is_vector_partition {
1958 static const bool value = false;
1959 };
1960
1961 template <unsigned Size>
1962 struct is_vector_partition< VectorPartition<Size> > {
1963 static const bool value = true;
1964 };
1965
1966 } // namespace MP
1967
1968 template <typename T>
1969 struct IsExpr< MP::Expr<T> > {
1970 static const bool value = true;
1971 };
1972
1973 template <typename T>
1974 struct BaseExprType< MP::Expr<T> > {
1975 typedef typename MP::Expr<T>::derived_type derived_type;
1976 typedef typename derived_type::base_expr_type type;
1977 };
1978
1979 template <typename S>
1980 struct IsExpr< MP::Vector<S> > {
1981 static const bool value = true;
1982 };
1983
1984 template <typename S>
1985 struct BaseExprType< MP::Vector<S> > {
1986 typedef MP::Vector<S> type;
1987 };
1988
1990 template <typename T> struct is_mp_vector {
1991 static const bool value = false;
1992 };
1993 template <typename S> struct is_mp_vector< MP::Vector<S> > {
1994 static const bool value = true;
1995 };
1996 template <typename T> struct is_mp_vector< const T > {
1997 static const bool value = is_mp_vector<T>::value;
1998 };
1999 template <typename T> struct is_mp_vector< T* > {
2000 static const bool value = is_mp_vector<T>::value;
2001 };
2002 template <typename T> struct is_mp_vector< T[] > {
2003 static const bool value = is_mp_vector<T>::value;
2004 };
2005 template <typename T, unsigned N> struct is_mp_vector< T[N] > {
2006 static const bool value = is_mp_vector<T>::value;
2007 };
2008
2009 // Utility function to see if a MP::Vector is really a constant
2010 template <typename Storage>
2012 {
2013 typedef typename Storage::ordinal_type ordinal_type;
2014 typedef typename Storage::value_type value_type;
2015
2016 // All size-1 vectors are constants
2017 const ordinal_type sz = x.size();
2018 if (sz == 1) return true;
2019
2020 // Maybe use a tolerance????
2021 const value_type val = x.fastAccessCoeff(0);
2022 for (ordinal_type i=1; i<sz; ++i)
2023 if (x.fastAccessCoeff(i) != val) return false;
2024
2025 return true;
2026 }
2027
2028} // namespace Sacado
2029
2030#include "Sacado_MP_Vector_ops.hpp"
2032
2033#if STOKHOS_ALIGN_MEMORY
2034
2035#include <memory>
2036
2037namespace std {
2038
2039template <typename Storage>
2040class allocator< Sacado::MP::Vector< Storage > >
2041 : public Stokhos::aligned_allocator< Sacado::MP::Vector< Storage > > {
2042public:
2044 typedef Stokhos::aligned_allocator<T> Base;
2045 typedef typename Base::value_type value_type;
2046 typedef typename Base::pointer pointer;
2047 typedef typename Base::const_pointer const_pointer;
2048 typedef typename Base::reference reference;
2049 typedef typename Base::const_reference const_reference;
2050 typedef typename Base::size_type size_type;
2051 typedef typename Base::difference_type difference_type;
2052
2053 template <class U> struct rebind { typedef allocator<U> other; };
2054 allocator() {}
2055 template <class U> allocator(const allocator<U>&) {}
2056};
2057
2058template <typename Storage>
2059class allocator< const Sacado::MP::Vector< Storage > >
2060 : public Stokhos::aligned_allocator< const Sacado::MP::Vector< Storage > > {
2061public:
2064 typedef typename Base::value_type value_type;
2065 typedef typename Base::pointer pointer;
2066 typedef typename Base::const_pointer const_pointer;
2067 typedef typename Base::reference reference;
2068 typedef typename Base::const_reference const_reference;
2069 typedef typename Base::size_type size_type;
2070 typedef typename Base::difference_type difference_type;
2071
2072 template <class U> struct rebind { typedef allocator<U> other; };
2073 allocator() {}
2074 template <class U> allocator(const allocator<U>&) {}
2075};
2076
2077}
2078
2079#endif
2080
2081#include "Kokkos_NumericTraits.hpp"
2082
2083namespace Kokkos {
2084
2085template <typename Storage>
2086struct reduction_identity< Sacado::MP::Vector<Storage> > {
2087 typedef Sacado::MP::Vector<Storage> Vector;
2088 typedef typename Storage::value_type scalar;
2089 typedef reduction_identity<scalar> RIS;
2090 KOKKOS_FORCEINLINE_FUNCTION constexpr static Vector sum() {
2091 return Vector(RIS::sum());
2092 }
2093 KOKKOS_FORCEINLINE_FUNCTION constexpr static Vector prod() {
2094 return Vector(RIS::prod());
2095 }
2096 KOKKOS_FORCEINLINE_FUNCTION constexpr static Vector max() {
2097 return Vector(RIS::max());
2098 }
2099 KOKKOS_FORCEINLINE_FUNCTION constexpr static Vector min() {
2100 return Vector(RIS::min());
2101 }
2102};
2103
2104namespace Impl {
2105 template <typename Storage>
2106 struct promote<Sacado::MP::Vector<Storage>,false> {
2107 using type = typename Sacado::MP::Vector<Storage>;
2108 };
2109}
2110
2111}
2112
2113#endif // HAVE_STOKHOS_SACADO
2114
2115#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::DefaultExecutionSpace execution_space
An aligned STL allocator.
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
Traits class encapsulting memory alignment.