numerics
Loading...
Searching...
No Matches
vector.cpp
Go to the documentation of this file.
1/// @file core/backends/omp/vector.cpp
2/// @brief OpenMP backend -- parallelised vector operations
3
4#include "core/vector.hpp"
5#include "../seq/impl.hpp"
6
7namespace num::backends::omp {
8
9void scale(Vector& v, real alpha) {
10#ifdef NUMERICS_HAS_OMP
11 const idx n = v.size();
12# pragma omp parallel for schedule(static)
13 for (idx i = 0; i < n; ++i) v[i] *= alpha;
14#else
16#endif
17}
18
19void axpy(real alpha, const Vector& x, Vector& y) {
20#ifdef NUMERICS_HAS_OMP
21 const idx n = x.size();
22# pragma omp parallel for schedule(static)
23 for (idx i = 0; i < n; ++i) y[i] += alpha * x[i];
24#else
26#endif
27}
28
29real dot(const Vector& x, const Vector& y) {
30#ifdef NUMERICS_HAS_OMP
31 real sum = 0;
32 const idx n = x.size();
33# pragma omp parallel for reduction(+:sum) schedule(static)
34 for (idx i = 0; i < n; ++i) sum += x[i] * y[i];
35 return sum;
36#else
37 return num::backends::seq::dot(x, y);
38#endif
39}
40
41} // namespace num::backends::omp
constexpr idx size() const noexcept
Definition vector.hpp:77
real dot(const Vector &x, const Vector &y)
Definition vector.cpp:29
void scale(Vector &v, real alpha)
Definition vector.cpp:9
void axpy(real alpha, const Vector &x, Vector &y)
Definition vector.cpp:19
real dot(const Vector &x, const Vector &y)
Definition vector.cpp:21
void scale(Vector &v, real alpha)
Definition vector.cpp:9
void axpy(real alpha, const Vector &x, Vector &y)
Definition vector.cpp:17
double real
Definition types.hpp:10
constexpr T ipow(T x) noexcept
Compute x^N at compile time via repeated squaring.
std::size_t idx
Definition types.hpp:11
Vector operations.