numerics 0.1.0
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)
14 v[i] *= alpha;
15#else
17#endif
18}
19
20void axpy(real alpha, const Vector& x, Vector& y) {
21#ifdef NUMERICS_HAS_OMP
22 const idx n = x.size();
23 #pragma omp parallel for schedule(static)
24 for (idx i = 0; i < n; ++i)
25 y[i] += alpha * x[i];
26#else
27 num::backends::seq::axpy(alpha, x, y);
28#endif
29}
30
31real dot(const Vector& x, const Vector& y) {
32#ifdef NUMERICS_HAS_OMP
33 real sum = 0;
34 const idx n = x.size();
35 #pragma omp parallel for reduction(+ : sum) schedule(static)
36 for (idx i = 0; i < n; ++i)
37 sum += x[i] * y[i];
38 return sum;
39#else
40 return num::backends::seq::dot(x, y);
41#endif
42}
43
44} // namespace num::backends::omp
constexpr idx size() const noexcept
Definition vector.hpp:80
real dot(const Vector &x, const Vector &y)
Definition vector.cpp:31
void scale(Vector &v, real alpha)
Definition vector.cpp:9
void axpy(real alpha, const Vector &x, Vector &y)
Definition vector.cpp:20
real dot(const Vector &x, const Vector &y)
Definition vector.cpp:24
void scale(Vector &v, real alpha)
Definition vector.cpp:9
void axpy(real alpha, const Vector &x, Vector &y)
Definition vector.cpp:19
double real
Definition types.hpp:10
std::size_t idx
Definition types.hpp:11
Vector operations.