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 // Tpetra: Templated Linear Algebra Services Package
4 //
5 // Copyright 2008 NTESS and the Tpetra contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef TPETRA_DETAILS_SCALARVIEWTRAITS_HPP
11 #define TPETRA_DETAILS_SCALARVIEWTRAITS_HPP
12 
18 
20 
21 namespace Tpetra {
22 namespace Details {
23 
28 template <class T, class D>
30  using value_type = T;
31  using device_type = D;
32 
62  static Kokkos::View<value_type*, device_type>
63  allocateArray(const value_type& x,
64  const size_t numEnt,
65  const std::string& label = "") {
66  using view_type = Kokkos::View<value_type*, device_type>;
67 
68  // When the traits::specialize type is non-void this exploits
69  // the fact that Kokkos::View's constructor ignores
70  // size arguments beyond what the View's type specifies. For
71  // value_type = Stokhos::UQ::PCE<S>, numValuesPerScalar returns
72  // something other than 1, and the constructor will actually use
73  // that value.
74  // Otherwise, the number of arguments must match the dynamic rank
75  // (i.e. number *'s with the value_type of the View)
76  const size_t numVals = PackTraits<value_type>::numValuesPerScalar(x);
77  if (std::is_same<typename view_type::traits::specialize, void>::value) {
78  return view_type(label, numEnt);
79  } else {
80  return view_type(label, numEnt, numVals);
81  }
82  }
83 }; // struct ScalarViewTraits
84 
85 } // namespace Details
86 } // namespace Tpetra
87 
88 #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...