Morpheus 1.0.0
Dynamic matrix type and algorithms for sparse matrices
Loading...
Searching...
No Matches
DenseVector/Kokkos/Morpheus_Reduction_Impl.hpp
1
24#ifndef MORPHEUS_DENSEVECTOR_KOKKOS_REDUCTION_IMPL_HPP
25#define MORPHEUS_DENSEVECTOR_KOKKOS_REDUCTION_IMPL_HPP
26
27#include <Morpheus_SpaceTraits.hpp>
28#include <Morpheus_FormatTraits.hpp>
29#include <Morpheus_FormatTags.hpp>
30#include <Morpheus_Spaces.hpp>
31
32namespace Morpheus {
33namespace Impl {
34
35template <typename ExecSpace, typename Vector>
36typename Vector::value_type reduce(
37 const Vector& in, typename Vector::size_type size,
38 typename std::enable_if_t<
39 Morpheus::is_dense_vector_format_container_v<Vector> &&
40 Morpheus::has_generic_backend_v<ExecSpace> &&
41 Morpheus::has_access_v<ExecSpace, Vector>>* = nullptr) {
42 using execution_space = typename ExecSpace::execution_space;
43 using size_type = typename Vector::size_type;
44 using IndexType = Kokkos::IndexType<size_type>;
45 using range_policy = Kokkos::RangePolicy<IndexType, execution_space>;
46 using ValueArray = typename Vector::value_array_type;
47 using value_type = typename Vector::non_const_value_type;
48
49 const ValueArray in_view = in.const_view();
50 range_policy policy(0, size);
51
52 value_type result = value_type(0);
53 Kokkos::parallel_reduce(
54 "reduce", policy,
55 KOKKOS_LAMBDA(const size_type& i, value_type& lsum) {
56 lsum += in_view[i];
57 },
58 result);
59
60 return result;
61}
62
63} // namespace Impl
64} // namespace Morpheus
65
66#endif // MORPHEUS_DENSEVECTOR_KOKKOS_REDUCTION_IMPL_HPP
Generic Morpheus interfaces.
Definition: dummy.cpp:24