3 // ************************************************************************
6 // Copyright (2020) National Technology & Engineering
7 // Solutions of Sandia, LLC (NTESS).
9 // Under the terms of Contract DE-NA0003525 with NTESS,
10 // the U.S. Government retains certain rights in this software.
12 // Redistribution and use in source and binary forms, with or without
13 // modification, are permitted provided that the following conditions are
16 // 1. Redistributions of source code must retain the above copyright
17 // notice, this list of conditions and the following disclaimer.
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.
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.
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.
39 // Questions? Contact Christian R. Trott (crtrott@sandia.gov)
41 // ************************************************************************
45 #ifndef KOKKOS_STD_ALGORITHMS_REDUCER_WITH_ARBITRARY_JOINER_NONEUTRAL_ELEMENT_HPP
46 #define KOKKOS_STD_ALGORITHMS_REDUCER_WITH_ARBITRARY_JOINER_NONEUTRAL_ELEMENT_HPP
48 #include <Kokkos_Core.hpp>
49 #include "Kokkos_ValueWrapperForNoNeutralElement.hpp"
52 namespace Experimental {
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.
59 template <class Scalar, class JoinerType, class Space = HostSpace>
60 struct ReducerWithArbitraryJoinerNoNeutralElement {
61 using scalar_type = std::remove_cv_t<Scalar>;
66 ReducerWithArbitraryJoinerNoNeutralElement<Scalar, JoinerType, Space>;
67 using value_type = ValueWrapperForNoNeutralElement<scalar_type>;
69 using result_view_type = Kokkos::View<value_type, Space>;
73 result_view_type m_value;
74 bool m_references_scalar_v;
78 ReducerWithArbitraryJoinerNoNeutralElement(value_type& value_,
80 : m_joiner(joiner_), m_value(&value_), m_references_scalar_v(true) {}
83 ReducerWithArbitraryJoinerNoNeutralElement(const result_view_type& value_,
85 : m_joiner(joiner_), m_value(value_), m_references_scalar_v(false) {}
89 void join(value_type& dest, const value_type& src) const {
90 dest.val = m_joiner(dest.val, src.val);
94 void init(value_type& val) const {
95 // I cannot call reduction_identity, so need to default this
100 value_type& reference() const { return *m_value.data(); }
103 result_view_type view() const { return m_value; }
106 bool references_scalar() const { return m_references_scalar_v; }
110 } // namespace Experimental
111 } // namespace Kokkos
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