]> https://gitweb.dealii.org/ - dealii.git/blob
d8e383b859218bd33b67efdd9f11c374372b8fb5
[dealii.git] /
1 /*
2 //@HEADER
3 // ************************************************************************
4 //
5 //                        Kokkos v. 3.0
6 //       Copyright (2020) National Technology & Engineering
7 //               Solutions of Sandia, LLC (NTESS).
8 //
9 // Under the terms of Contract DE-NA0003525 with NTESS,
10 // the U.S. Government retains certain rights in this software.
11 //
12 // Redistribution and use in source and binary forms, with or without
13 // modification, are permitted provided that the following conditions are
14 // met:
15 //
16 // 1. Redistributions of source code must retain the above copyright
17 // notice, this list of conditions and the following disclaimer.
18 //
19 // 2. Redistributions in binary form must reproduce the above copyright
20 // notice, this list of conditions and the following disclaimer in the
21 // documentation and/or other materials provided with the distribution.
22 //
23 // 3. Neither the name of the Corporation nor the names of the
24 // contributors may be used to endorse or promote products derived from
25 // this software without specific prior written permission.
26 //
27 // THIS SOFTWARE IS PROVIDED BY NTESS "AS IS" AND ANY
28 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NTESS OR THE
31 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
32 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
33 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
34 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
35 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
36 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
37 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 //
39 // Questions? Contact Christian R. Trott (crtrott@sandia.gov)
40 //
41 // ************************************************************************
42 //@HEADER
43 */
44
45 #ifndef KOKKOS_STD_ALGORITHMS_REDUCER_WITH_ARBITRARY_JOINER_NONEUTRAL_ELEMENT_HPP
46 #define KOKKOS_STD_ALGORITHMS_REDUCER_WITH_ARBITRARY_JOINER_NONEUTRAL_ELEMENT_HPP
47
48 #include <Kokkos_Core.hpp>
49 #include "Kokkos_ValueWrapperForNoNeutralElement.hpp"
50
51 namespace Kokkos {
52 namespace Experimental {
53 namespace Impl {
54
55 // This reducer is here and not where all other reducers are
56 // because it is inside Impl and also because it would not work
57 // for OpenMPTarget backend. We can move this later.
58
59 template <class Scalar, class JoinerType, class Space = HostSpace>
60 struct ReducerWithArbitraryJoinerNoNeutralElement {
61   using scalar_type = std::remove_cv_t<Scalar>;
62
63  public:
64   // Required
65   using reducer =
66       ReducerWithArbitraryJoinerNoNeutralElement<Scalar, JoinerType, Space>;
67   using value_type = ValueWrapperForNoNeutralElement<scalar_type>;
68
69   using result_view_type = Kokkos::View<value_type, Space>;
70
71  private:
72   JoinerType m_joiner;
73   result_view_type m_value;
74   bool m_references_scalar_v;
75
76  public:
77   KOKKOS_FUNCTION
78   ReducerWithArbitraryJoinerNoNeutralElement(value_type& value_,
79                                              JoinerType joiner_)
80       : m_joiner(joiner_), m_value(&value_), m_references_scalar_v(true) {}
81
82   KOKKOS_FUNCTION
83   ReducerWithArbitraryJoinerNoNeutralElement(const result_view_type& value_,
84                                              JoinerType joiner_)
85       : m_joiner(joiner_), m_value(value_), m_references_scalar_v(false) {}
86
87   // Required
88   KOKKOS_FUNCTION
89   void join(value_type& dest, const value_type& src) const {
90     dest.val = m_joiner(dest.val, src.val);
91   }
92
93   KOKKOS_FUNCTION
94   void init(value_type& val) const {
95     // I cannot call reduction_identity, so need to default this
96     val = {};
97   }
98
99   KOKKOS_FUNCTION
100   value_type& reference() const { return *m_value.data(); }
101
102   KOKKOS_FUNCTION
103   result_view_type view() const { return m_value; }
104
105   KOKKOS_FUNCTION
106   bool references_scalar() const { return m_references_scalar_v; }
107 };
108
109 }  // namespace Impl
110 }  // namespace Experimental
111 }  // namespace Kokkos
112
113 #endif

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.