Stokhos Package Browser (Single Doxygen Collection) Version of the Day
Loading...
Searching...
No Matches
Kokkos_InnerProductSpaceTraits_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 KOKKOS_INNER_PRODUCT_SPACE_TRAITS_MP_VECTOR_HPP
43#define KOKKOS_INNER_PRODUCT_SPACE_TRAITS_MP_VECTOR_HPP
44
45#include "Sacado_ConfigDefs.h"
46#if defined(HAVE_STOKHOS_ENSEMBLE_REDUCT)
47
48#include "Sacado_MP_Vector.hpp"
49#include "Kokkos_InnerProductSpaceTraits.hpp"
51
52//----------------------------------------------------------------------------
53// Specializations of Kokkos::InnerProductSpaceTraits for Sacado::MP::Vector
54// scalar type
55//----------------------------------------------------------------------------
56
57namespace Kokkos {
58namespace Details {
59
60template <typename S>
61class InnerProductSpaceTraits< Sacado::MP::Vector<S> > {
62public:
63 typedef Sacado::MP::Vector<S> val_type;
64
65 typedef typename val_type::value_type base_value_type;
66 typedef typename val_type::ordinal_type ordinal_type;
67 typedef InnerProductSpaceTraits<base_value_type> BIT;
68 typedef typename BIT::dot_type base_dot_type;
69
70 typedef typename ArithTraits<val_type>::mag_type mag_type;
71 typedef base_dot_type dot_type;
72
73 static KOKKOS_FORCEINLINE_FUNCTION
74 mag_type norm (const val_type& x) {
75 //return ArithTraits<val_type>::abs (x);
76 const ordinal_type sz = x.size();
77 mag_type nrm = mag_type(0);
78 for (ordinal_type i=0; i<sz; ++i) {
79 const mag_type n = BIT::norm( x.fastAccessCoeff(i) );
80 nrm += n*n;
81 }
82 return std::sqrt(nrm);
83 }
84
85 static KOKKOS_FORCEINLINE_FUNCTION
86 dot_type dot (const val_type& x, const val_type& y) {
87 const ordinal_type xsz = x.size();
88 const ordinal_type ysz = y.size();
89 const ordinal_type sz = xsz > ysz ? xsz : ysz;
90
91 dot_type r = dot_type(0);
92 if (x.hasFastAccess(sz) && y.hasFastAccess(sz))
93 for (ordinal_type i=0; i<sz; ++i)
94 r += BIT::dot( x.fastAccessCoeff(i), y.fastAccessCoeff(i) );
95 else
96 for (ordinal_type i=0; i<sz; ++i)
97 r += BIT::dot( x.coeff(i), y.coeff(i) );
98
99 return r;
100 }
101
102};
103
104template <typename S>
105class InnerProductSpaceTraits< const Sacado::MP::Vector<S> > {
106public:
107 typedef Sacado::MP::Vector<S> val_type;
108
109 typedef typename val_type::value_type base_value_type;
110 typedef typename val_type::ordinal_type ordinal_type;
111 typedef InnerProductSpaceTraits<base_value_type> BIT;
112 typedef typename BIT::dot_type base_dot_type;
113
114 typedef typename ArithTraits<val_type>::mag_type mag_type;
115 typedef base_dot_type dot_type;
116
117 static KOKKOS_FORCEINLINE_FUNCTION
118 mag_type norm (const val_type& x) {
119 //return ArithTraits<val_type>::abs (x);
120 const ordinal_type sz = x.size();
121 mag_type nrm = mag_type(0);
122 for (ordinal_type i=0; i<sz; ++i) {
123 const mag_type n = BIT::norm( x.fastAccessCoeff(i) );
124 nrm += n*n;
125 }
126 return std::sqrt(nrm);
127 }
128
129 static KOKKOS_FORCEINLINE_FUNCTION
130 dot_type dot (const val_type& x, const val_type& y) {
131 const ordinal_type xsz = x.size();
132 const ordinal_type ysz = y.size();
133 const ordinal_type sz = xsz > ysz ? xsz : ysz;
134
135 dot_type r = dot_type(0);
136 if (x.hasFastAccess(sz) && y.hasFastAccess(sz))
137 for (ordinal_type i=0; i<sz; ++i)
138 r += BIT::dot( x.fastAccessCoeff(i), y.fastAccessCoeff(i) );
139 else
140 for (ordinal_type i=0; i<sz; ++i)
141 r += BIT::dot( x.coeff(i), y.coeff(i) );
142
143 return r;
144 }
145
146};
147
148}
149}
150
151#endif
152
153#endif /* #ifndef KOKKOS_INNER_PRODUCT_SPACE_TRAITS_MP_VECTOR_HPP */
std::enable_if< Kokkos::is_view_uq_pce< Kokkos::View< XD, XP... > >::value &&Kokkos::is_view_uq_pce< Kokkos::View< YD, YP... > >::value, typenameKokkos::Details::InnerProductSpaceTraits< typenameKokkos::View< XD, XP... >::non_const_value_type >::dot_type >::type dot(const Kokkos::View< XD, XP... > &x, const Kokkos::View< YD, YP... > &y)
const IndexType const IndexType const IndexType const IndexType const ValueType const ValueType * x
Definition: csr_vector.h:265
const IndexType const IndexType const IndexType const IndexType const ValueType const ValueType ValueType * y
Definition: csr_vector.h:267