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