Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
Sacado_MP_Vector_SFS.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_SFS_HPP
43 #define SACADO_MP_VECTOR_SFS_HPP
44 
45 #include "Stokhos_ConfigDefs.h"
46 
47 #ifdef HAVE_STOKHOS_SACADO
48 
49 //#include "Sacado_MP_Vector.hpp"
51 
52 namespace Sacado {
53 
54  namespace MP {
55 
57  template <typename ordinal_t, typename value_t, int Num, typename device_t>
58  class Vector< Stokhos::StaticFixedStorage<ordinal_t,value_t,Num,device_t> >{
59  public:
60 
63  typedef Storage storage_type;
64 
65  typedef typename storage_type::value_type value_type;
68  typedef typename storage_type::pointer pointer;
69  typedef typename storage_type::volatile_pointer volatile_pointer;
70  typedef typename storage_type::const_pointer const_pointer;
71  typedef typename storage_type::const_volatile_pointer const_volatile_pointer;
72  typedef typename storage_type::reference reference;
73  typedef typename storage_type::volatile_reference volatile_reference;
74  typedef typename storage_type::const_reference const_reference;
75  typedef typename storage_type::const_volatile_reference const_volatile_reference;
76 
78  typedef typename ScalarType<value_type>::type scalar_type;
79 
81  template < class NewStorageType >
82  struct apply {
83  typedef Vector< NewStorageType > type;
84  };
85 
87 
90  KOKKOS_INLINE_FUNCTION
91  Vector() : s(1) {}
92 
94 
97  KOKKOS_INLINE_FUNCTION
98  Vector(const value_type& x) : s(1) { s.init(x); }
99 
101 
105  KOKKOS_INLINE_FUNCTION
106  Vector(ordinal_type sz, pointer v, bool owned) : s(sz,v,owned) {}
107 
109 
112  KOKKOS_INLINE_FUNCTION
113  Vector(ordinal_type sz, const value_type& x) : s(sz,x) {}
114 
116  KOKKOS_INLINE_FUNCTION
117  Vector(const storage_type& ss) : s(ss) {}
118 
120  KOKKOS_INLINE_FUNCTION
121  Vector(const Vector& x) : s(x.s) {}
122 
124  KOKKOS_INLINE_FUNCTION
125  Vector(const volatile Vector& x) : s(x.s) {}
126 
128  KOKKOS_INLINE_FUNCTION
129  ~Vector() {}
130 
132  KOKKOS_INLINE_FUNCTION
133  void init(const value_type& v) { s.init(v); }
134 
136  KOKKOS_INLINE_FUNCTION
137  void init(const value_type& v) volatile { s.init(v); }
138 
140  KOKKOS_INLINE_FUNCTION
141  void init(const value_type* v) { s.init(v); }
142 
144  KOKKOS_INLINE_FUNCTION
145  void init(const value_type* v) volatile { s.init(v); }
146 
148  template <typename S>
149  KOKKOS_INLINE_FUNCTION
150  void init(const Vector<S>& v) {
151  s.init(v.s.coeff(), v.s.size());
152  }
153 
155  template <typename S>
156  KOKKOS_INLINE_FUNCTION
157  void init(const Vector<S>& v) volatile {
158  s.init(v.s.coeff(), v.s.size());
159  }
160 
162  KOKKOS_INLINE_FUNCTION
163  void load(value_type* v) { s.load(v); }
164 
166  KOKKOS_INLINE_FUNCTION
167  void load(value_type* v) volatile { s.load(v); }
168 
170  template <typename S>
171  KOKKOS_INLINE_FUNCTION
172  void load(Vector<S>& v) { s.load(v.s.coeff()); }
173 
175  template <typename S>
176  KOKKOS_INLINE_FUNCTION
177  void load(Vector<S>& v) volatile { s.load(v.s.coeff()); }
178 
180 
183  KOKKOS_INLINE_FUNCTION
184  void reset(ordinal_type sz_new) {}
185 
187 
190  KOKKOS_INLINE_FUNCTION
191  void reset(ordinal_type sz_new) volatile {}
192 
194 
203  KOKKOS_INLINE_FUNCTION
204  void copyForWrite() volatile { }
205 
207  template <typename S>
208  KOKKOS_INLINE_FUNCTION
209  bool isEqualTo(const Expr<S>& xx) const {
210  const typename Expr<S>::derived_type& x = xx.derived();
211  typedef IsEqual<value_type> IE;
212  bool eq = true;
213  for (ordinal_type i=0; i<this->size(); i++)
214  eq = eq && IE::eval(x.coeff(i), this->coeff(i));
215  return eq;
216  }
217 
219  template <typename S>
220  KOKKOS_INLINE_FUNCTION
221  bool isEqualTo(const Expr<S>& xx) const volatile {
222  const typename Expr<S>::derived_type& x = xx.derived();
223  typedef IsEqual<value_type> IE;
224  bool eq = true;
225  for (ordinal_type i=0; i<this->size(); i++)
226  eq = eq && IE::eval(x.coeff(i), this->coeff(i));
227  return eq;
228  }
229 
234 
236  KOKKOS_INLINE_FUNCTION
237  Vector& operator=(const value_type& x) {
238  s.init(x);
239  return *this;
240  }
241 
243  KOKKOS_INLINE_FUNCTION
244  /*volatile*/ Vector& operator=(const value_type& x) volatile {
245  s.init(x);
246  return const_cast<Vector&>(*this);
247  }
248 
250  KOKKOS_INLINE_FUNCTION
251  Vector& operator=(const Vector& x) {
252  if (this != &x) {
253  s = x.s;
254  }
255 
256  return *this;
257  }
258 
260  KOKKOS_INLINE_FUNCTION
261  Vector& operator=(const volatile Vector& x) {
262  if (this != &x) {
263  s = x.s;
264  }
265 
266  return *this;
267  }
268 
270  KOKKOS_INLINE_FUNCTION
271  /*volatile*/ Vector& operator=(const Vector& x) volatile {
272  if (this != &x) {
273  s = x.s;
274  }
275 
276  return const_cast<Vector&>(*this);
277  }
278 
280  KOKKOS_INLINE_FUNCTION
281  /*volatile*/ Vector& operator=(const volatile Vector& x) volatile {
282  if (this != &x) {
283  s = x.s;
284  }
285 
286  return const_cast<Vector&>(*this);
287  }
288 
290 
295  KOKKOS_INLINE_FUNCTION
297  const volatile storage_type& storage() const volatile { return s; }
298 
300  KOKKOS_INLINE_FUNCTION
301  const storage_type& storage() const { return s; }
302 
304  KOKKOS_INLINE_FUNCTION
305  volatile storage_type& storage() volatile { return s; }
306 
308  KOKKOS_INLINE_FUNCTION
309  storage_type& storage() { return s; }
310 
315 
317  KOKKOS_INLINE_FUNCTION
318  const_volatile_reference val() const volatile { return s[0]; }
319 
321  KOKKOS_INLINE_FUNCTION
322  const_reference val() const { return s[0]; }
323 
325  KOKKOS_INLINE_FUNCTION
326  volatile_reference val() volatile { return s[0]; }
327 
329  KOKKOS_INLINE_FUNCTION
330  reference val() { return s[0]; }
331 
333 
338 
340  KOKKOS_INLINE_FUNCTION
341  static ordinal_type size() { return storage_type::size();}
342 
344  KOKKOS_INLINE_FUNCTION
345  static bool hasFastAccess(ordinal_type sz) { return true; }
346 
348  KOKKOS_INLINE_FUNCTION
349  const_pointer coeff() const { return s.coeff();}
350 
352  KOKKOS_INLINE_FUNCTION
353  const_volatile_pointer coeff() const volatile { return s.coeff();}
354 
356  KOKKOS_INLINE_FUNCTION
357  volatile_pointer coeff() volatile { return s.coeff();}
358 
360  KOKKOS_INLINE_FUNCTION
361  pointer coeff() { return s.coeff();}
362 
364  KOKKOS_INLINE_FUNCTION
365  value_type coeff(ordinal_type i) const volatile { return s[i]; }
366 
368  KOKKOS_INLINE_FUNCTION
369  value_type coeff(ordinal_type i) const { return s[i]; }
370 
372  KOKKOS_INLINE_FUNCTION
373  value_type coeff(ordinal_type i) volatile { return s[i]; }
374 
376  KOKKOS_INLINE_FUNCTION
377  value_type coeff(ordinal_type i) { return s[i]; }
378 
380  KOKKOS_INLINE_FUNCTION
381  const_volatile_reference fastAccessCoeff(ordinal_type i) const volatile {
382  return s[i];}
383 
385  KOKKOS_INLINE_FUNCTION
386  const_reference fastAccessCoeff(ordinal_type i) const {
387  return s[i];}
388 
390  KOKKOS_INLINE_FUNCTION
391  volatile_reference fastAccessCoeff(ordinal_type i) volatile {
392  return s[i];}
393 
395  KOKKOS_INLINE_FUNCTION
396  reference fastAccessCoeff(ordinal_type i) {
397  return s[i];}
398 
400 
405 
407  KOKKOS_INLINE_FUNCTION
408  Vector& operator += (const value_type& x) {
409  for (ordinal_type i=0; i<s.size(); i++)
410  s[i] += x;
411  return *this;
412  }
413 
415  KOKKOS_INLINE_FUNCTION
416  Vector& operator += (const volatile value_type& x) {
417  for (ordinal_type i=0; i<s.size(); i++)
418  s[i] += x;
419  return *this;
420  }
421 
423  KOKKOS_INLINE_FUNCTION
424  /*volatile*/ Vector& operator += (const value_type& x) volatile {
425  for (ordinal_type i=0; i<s.size(); i++)
426  s[i] += x;
427  return const_cast<Vector&>(*this);
428  }
429 
431  KOKKOS_INLINE_FUNCTION
432  /*volatile*/ Vector& operator += (const volatile value_type& x) volatile {
433  for (ordinal_type i=0; i<s.size(); i++)
434  s[i] += x;
435  return const_cast<Vector&>(*this);
436  }
437 
439  KOKKOS_INLINE_FUNCTION
440  Vector& operator -= (const value_type& x) {
441  for (ordinal_type i=0; i<s.size(); i++)
442  s[i] -= x;
443  return *this;
444  }
445 
447  KOKKOS_INLINE_FUNCTION
448  Vector& operator -= (const volatile value_type& x) {
449  for (ordinal_type i=0; i<s.size(); i++)
450  s[i] -= x;
451  return *this;
452  }
453 
455  KOKKOS_INLINE_FUNCTION
456  /*volatile*/ Vector& operator -= (const value_type& x) volatile {
457  for (ordinal_type i=0; i<s.size(); i++)
458  s[i] -= x;
459  return const_cast<Vector&>(*this);
460  }
461 
463  KOKKOS_INLINE_FUNCTION
464  /*volatile*/ Vector& operator -= (const volatile value_type& x) volatile {
465  for (ordinal_type i=0; i<s.size(); i++)
466  s[i] -= x;
467  return const_cast<Vector&>(*this);
468  }
469 
471  KOKKOS_INLINE_FUNCTION
472  Vector& operator *= (const value_type& x) {
473  for (ordinal_type i=0; i<s.size(); i++)
474  s[i] *= x;
475  return *this;
476  }
477 
479  KOKKOS_INLINE_FUNCTION
480  Vector& operator *= (const volatile value_type& x) {
481  for (ordinal_type i=0; i<s.size(); i++)
482  s[i] *= x;
483  return *this;
484  }
485 
487  KOKKOS_INLINE_FUNCTION
488  /*volatile*/ Vector& operator *= (const value_type& x) volatile {
489  for (ordinal_type i=0; i<s.size(); i++)
490  s[i] *= x;
491  return const_cast<Vector&>(*this);
492  }
493 
495  KOKKOS_INLINE_FUNCTION
496  /*volatile*/ Vector& operator *= (const volatile value_type& x) volatile {
497  for (ordinal_type i=0; i<s.size(); i++)
498  s[i] *= x;
499  return const_cast<Vector&>(*this);
500  }
501 
503  KOKKOS_INLINE_FUNCTION
504  Vector& operator /= (const value_type& x) {
505  for (ordinal_type i=0; i<s.size(); i++)
506  s[i] /= x;
507  return *this;
508  }
509 
511  KOKKOS_INLINE_FUNCTION
512  Vector& operator /= (const volatile value_type& x) {
513  for (ordinal_type i=0; i<s.size(); i++)
514  s[i] /= x;
515  return *this;
516  }
517 
519  KOKKOS_INLINE_FUNCTION
520  /*volatile*/ Vector& operator /= (const value_type& x) volatile {
521  for (ordinal_type i=0; i<s.size(); i++)
522  s[i] /= x;
523  return const_cast<Vector&>(*this);
524  }
525 
527  KOKKOS_INLINE_FUNCTION
528  /*volatile*/ Vector& operator /= (const volatile value_type& x) volatile {
529  for (ordinal_type i=0; i<s.size(); i++)
530  s[i] /= x;
531  return const_cast<Vector&>(*this);
532  }
533 
535  KOKKOS_INLINE_FUNCTION
536  Vector& operator += (const Vector& x) {
537  for (ordinal_type i=0; i<s.size(); i++)
538  s[i] += x.fastAccessCoeff(i);
539  return *this;
540  }
541 
543  KOKKOS_INLINE_FUNCTION
544  Vector& operator += (const volatile Vector& x) {
545  *this = *this + x;
546  return *this;
547  }
548 
550  KOKKOS_INLINE_FUNCTION
551  /*volatile*/ Vector& operator += (const Vector& x) volatile {
552  *this = *this + x;
553  return const_cast<Vector&>(*this);
554  }
555 
557  KOKKOS_INLINE_FUNCTION
558  /*volatile*/ Vector& operator += (const volatile Vector& x) volatile {
559  *this = *this + x;
560  return const_cast<Vector&>(*this);
561  }
562 
564  KOKKOS_INLINE_FUNCTION
565  Vector& operator -= (const Vector& x) {
566  *this = *this - x;
567  return *this;
568  }
569 
571  KOKKOS_INLINE_FUNCTION
572  Vector& operator -= (const volatile Vector& x) {
573  *this = *this - x;
574  return *this;
575  }
576 
578  KOKKOS_INLINE_FUNCTION
579  /*volatile*/ Vector& operator -= (const Vector& x) volatile {
580  *this = *this - x;
581  return const_cast<Vector&>(*this);
582  }
583 
585  KOKKOS_INLINE_FUNCTION
586  /*volatile*/ Vector& operator -= (const volatile Vector& x) volatile {
587  *this = *this - x;
588  return const_cast<Vector&>(*this);
589  }
590 
592  KOKKOS_INLINE_FUNCTION
593  Vector& operator *= (const Vector& x) {
594  *this = *this * x;
595  return *this;
596  }
597 
599  KOKKOS_INLINE_FUNCTION
600  Vector& operator *= (const volatile Vector& x) {
601  *this = *this * x;
602  return *this;
603  }
604 
606  KOKKOS_INLINE_FUNCTION
607  /*volatile*/ Vector& operator *= (const Vector& x) volatile {
608  *this = *this * x;
609  return const_cast<Vector&>(*this);
610  }
611 
613  KOKKOS_INLINE_FUNCTION
614  /*volatile*/ Vector& operator *= (const volatile Vector& x) volatile {
615  *this = *this * x;
616  return const_cast<Vector&>(*this);
617  }
618 
620  KOKKOS_INLINE_FUNCTION
621  Vector& operator /= (const Vector& x) {
622  *this = *this / x;
623  return *this;
624  }
625 
627  KOKKOS_INLINE_FUNCTION
628  Vector& operator /= (const volatile Vector& x) {
629  *this = *this / x;
630  return *this;
631  }
632 
634  KOKKOS_INLINE_FUNCTION
635  /*volatile*/ Vector& operator /= (const Vector& x) volatile {
636  *this = *this / x;
637  return const_cast<Vector&>(*this);
638  }
639 
641  KOKKOS_INLINE_FUNCTION
642  /*volatile*/ Vector& operator /= (const volatile Vector& x) volatile {
643  *this = *this / x;
644  return const_cast<Vector&>(*this);
645  }
646 
648  KOKKOS_INLINE_FUNCTION
649  Vector& operator++() {
650  for (ordinal_type i=0; i<s.size(); i++)
651  ++(s[i]);
652  return *this;
653  }
654 
656  KOKKOS_INLINE_FUNCTION
657  volatile Vector& operator++() volatile {
658  for (ordinal_type i=0; i<s.size(); i++)
659  ++(s[i]);
660  return *this;
661  }
662 
664  KOKKOS_INLINE_FUNCTION
665  Vector operator++(int) {
666  Vector tmp(*this);
667  ++(*this);
668  return tmp;
669  }
670 
672  KOKKOS_INLINE_FUNCTION
673  Vector operator++(int) volatile {
674  Vector tmp(*this);
675  ++(*this);
676  return tmp;
677  }
678 
680  KOKKOS_INLINE_FUNCTION
681  Vector& operator--() {
682  for (ordinal_type i=0; i<s.size(); i++)
683  --(s[i]);
684  return *this;
685  }
686 
688  KOKKOS_INLINE_FUNCTION
689  volatile Vector& operator--() volatile {
690  for (ordinal_type i=0; i<s.size(); i++)
691  --(s[i]);
692  return *this;
693  }
694 
696  KOKKOS_INLINE_FUNCTION
697  Vector operator--(int) {
698  Vector tmp(*this);
699  --(*this);
700  return tmp;
701  }
702 
704  KOKKOS_INLINE_FUNCTION
705  Vector operator--(int) volatile {
706  Vector tmp(*this);
707  --(*this);
708  return tmp;
709  }
710 
712 
713  KOKKOS_INLINE_FUNCTION
714  std::string name() const volatile { return "x"; }
715 
716  protected:
717 
718  Storage s;
719 
720  }; // class Vector
721 
722  //------------------------------------------------------------------------
723  //------------------------------------------------------------------------
724 
725  } // namespace MP
726 
727 } // namespace Sacado
728 
730 
731 #endif // HAVE_STOKHOS_SACADO
732 
733 #endif // SACADO_MP_VECTOR_SFS_HPP
Stokhos::StandardStorage< int, double > storage_type
Stokhos::StandardStorage< int, double > Storage
expr val()
Statically allocated storage class.
Kokkos::DefaultExecutionSpace execution_space
const IndexType const IndexType const IndexType const IndexType const ValueType const ValueType * x
Definition: csr_vector.h:260
Top-level namespace for Stokhos classes and functions.