Tpetra parallel linear algebra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Tpetra_Details_ScalarViewTraits.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Tpetra: Templated Linear Algebra Services Package
5 // Copyright (2008) Sandia Corporation
6 //
7 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8 // the U.S. Government retains certain rights in this software.
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 // ************************************************************************
38 // @HEADER
39 
40 #ifndef TPETRA_DETAILS_SCALARVIEWTRAITS_HPP
41 #define TPETRA_DETAILS_SCALARVIEWTRAITS_HPP
42 
48 
50 
51 namespace Tpetra {
52 namespace Details {
53 
58 template<class T, class D>
60  using value_type = T;
61  using device_type = D;
62 
92  static Kokkos::View<value_type*, device_type>
93  allocateArray (const value_type& x,
94  const size_t numEnt,
95  const std::string& label = "")
96  {
97  using view_type = Kokkos::View<value_type*, device_type>;
98 
99  // When the traits::specialize type is non-void this exploits
100  // the fact that Kokkos::View's constructor ignores
101  // size arguments beyond what the View's type specifies. For
102  // value_type = Stokhos::UQ::PCE<S>, numValuesPerScalar returns
103  // something other than 1, and the constructor will actually use
104  // that value.
105  // Otherwise, the number of arguments must match the dynamic rank
106  // (i.e. number *'s with the value_type of the View)
107  const size_t numVals = PackTraits<value_type>::numValuesPerScalar (x);
108  if (std::is_same<typename view_type::traits::specialize, void>::value ) {
109  return view_type (label, numEnt);
110  }
111  else {
112  return view_type (label, numEnt, numVals);
113  }
114  }
115 }; // struct ScalarViewTraits
116 
117 } // namespace Details
118 } // namespace Tpetra
119 
120 #endif // TPETRA_DETAILS_SCALARVIEWTRAITS_HPP
static KOKKOS_INLINE_FUNCTION size_t numValuesPerScalar(const value_type &)
Given an instance of value_type allocated with the right size, return the &quot;number of values&quot; that mak...
static Kokkos::View< value_type *, device_type > allocateArray(const value_type &x, const size_t numEnt, const std::string &label="")
Given an instance of value_type allocated with the right size, allocate and return a one-dimensional ...
Traits class for allocating a Kokkos::View&lt;T*, D&gt;.
Declaration and generic definition of traits class that tells Tpetra::CrsMatrix how to pack and unpac...