Morpheus 1.0.0
Dynamic matrix type and algorithms for sparse matrices
Loading...
Searching...
No Matches
DenseVector/OpenMP/Morpheus_WAXPBY_Impl.hpp
1
24#ifndef MORPHEUS_DENSEVECTOR_OPENMP_WAXPBY_IMPL_HPP
25#define MORPHEUS_DENSEVECTOR_OPENMP_WAXPBY_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
35#include <cassert>
36
37namespace Morpheus {
38namespace Impl {
39
40template <typename ExecSpace, typename Vector1, typename Vector2,
41 typename Vector3>
42inline void waxpby(
43 const typename Vector1::size_type n,
44 const typename Vector1::value_type alpha, const Vector1& x,
45 const typename Vector2::value_type beta, const Vector2& y, Vector3& w,
46 typename std::enable_if_t<
47 Morpheus::is_dense_vector_format_container_v<Vector1> &&
48 Morpheus::is_dense_vector_format_container_v<Vector2> &&
49 Morpheus::is_dense_vector_format_container_v<Vector3> &&
50 Morpheus::has_custom_backend_v<ExecSpace> &&
51 Morpheus::has_openmp_execution_space_v<ExecSpace> &&
52 Morpheus::has_access_v<ExecSpace, Vector1, Vector2, Vector3>>* =
53 nullptr) {
54 using size_type = typename Vector1::size_type;
55
56 assert(x.size() >= n);
57 assert(y.size() >= n);
58 assert(w.size() >= n);
59
60 if (alpha == 1.0) {
61#pragma omp parallel for
62 for (size_type i = 0; i < n; i++) w[i] = x[i] + beta * y[i];
63 } else if (beta == 1.0) {
64#pragma omp parallel for
65 for (size_type i = 0; i < n; i++) w[i] = alpha * x[i] + y[i];
66 } else {
67#pragma omp parallel for
68 for (size_type i = 0; i < n; i++) w[i] = alpha * x[i] + beta * y[i];
69 }
70}
71
72} // namespace Impl
73} // namespace Morpheus
74
75#endif // MORPHEUS_ENABLE_OPENMP
76#endif // MORPHEUS_DENSEVECTOR_OPENMP_WAXPBY_IMPL_HPP
Generic Morpheus interfaces.
Definition: dummy.cpp:24