Morpheus 1.0.0
Dynamic matrix type and algorithms for sparse matrices
Loading...
Searching...
No Matches
DenseVector/OpenMP/Morpheus_Reduction_Impl.hpp
1
24#ifndef MORPHEUS_DENSEVECTOR_OPENMP_REDUCTION_IMPL_HPP
25#define MORPHEUS_DENSEVECTOR_OPENMP_REDUCTION_IMPL_HPP
26
27#if defined(MORPHEUS_ENABLE_OPENMP)
28
29#include <Morpheus_SpaceTraits.hpp>
30#include <Morpheus_FormatTraits.hpp>
31#include <Morpheus_FormatTags.hpp>
32#include <Morpheus_Spaces.hpp>
33
34namespace Morpheus {
35namespace Impl {
36
37template <typename ExecSpace, typename Vector>
38typename Vector::value_type reduce(
39 const Vector& in, typename Vector::size_type size,
40 typename std::enable_if_t<
41 Morpheus::is_dense_vector_format_container_v<Vector> &&
42 Morpheus::has_custom_backend_v<ExecSpace> &&
43 Morpheus::has_openmp_execution_space_v<ExecSpace> &&
44 Morpheus::has_access_v<ExecSpace, Vector>>* = nullptr) {
45 using value_type = typename Vector::value_type;
46 using size_type = typename Vector::size_type;
47
48 value_type sum = value_type(0);
49
50#pragma omp parallel for reduction(+ : sum)
51 for (size_type i = 0; i < size; i++) sum += in[i];
52
53 return sum;
54}
55
56} // namespace Impl
57} // namespace Morpheus
58
59#endif // MORPHEUS_ENABLE_OPENMP
60
61#endif // MORPHEUS_DENSEVECTOR_OPENMP_REDUCTION_IMPL_HPP
Generic Morpheus interfaces.
Definition: dummy.cpp:24