SenK
SenK is a C++ library for high-performance linear solvers.
senk_blas1.hpp
Go to the documentation of this file.
1
7#ifndef SENK_BLAS1_HPP
8#define SENK_BLAS1_HPP
9
10#include <cmath>
11
12#include "senk_helper.hpp"
13
14namespace senk {
18namespace blas1 {
26template <typename T> inline
27void Copy(T *x, T *y, int N) {
28 #pragma omp parallel for simd
29 for(int i=0; i<N; i++) { y[i] = x[i]; }
30}
38template <typename T> inline
39void Scal(T a, T *x, int N) {
40 #pragma omp parallel for simd
41 for(int i=0; i<N; i++) { x[i] *= a; }
42}
51template <typename T> inline
52void Axpy(T a, T *x, T *y, int N) {
53 #pragma omp parallel for simd
54 for(int i=0; i<N; i++) { y[i] += a * x[i]; }
55}
65template <typename T> inline
66void Axpby(T a, T *x, T b, T *y, int N) {
67 #pragma omp parallel for simd
68 for(int i=0; i<N; i++) { y[i] = a * x[i] + b * y[i]; }
69}
79template <typename T> inline
80void Axpyz(T a, T *x, T *y, T *z, int N) {
81 #pragma omp parallel for simd
82 for(int i=0; i<N; i++) { z[i] = a * x[i] + y[i]; }
83}
92template <typename T> inline
93T Dot(T *x, T *y, int N) {
94 T res = 0;
95 #pragma omp parallel for simd reduction(+: res)
96 for(int i=0; i<N; i++) { res += x[i] * y[i]; }
97 return res;
98}
106template <typename T> inline
107T Nrm2(T *x, int N) {
108 T res = 0;
109 #pragma omp parallel for simd reduction(+: res)
110 for(int i=0; i<N; i++) { res += x[i] * x[i]; }
111 return std::sqrt(res);
112}
120template <typename T> inline
121void HadProd(T *x, T *y, int N) {
122 #pragma omp parallel for simd
123 for(int i=0; i<N; i++) { y[i] *= x[i]; }
124}
132template <typename T> inline
133void HadDiv(T *x, T *y, int N) {
134 #pragma omp parallel for simd
135 for(int i=0; i<N; i++) { y[i] /= x[i]; }
136}
145template <typename T> inline
146T Ggen(T a, T b, T *c, T *s)
147{
148 T r;
149 r = std::sqrt(a*a + b*b);
150 c[0] = a / r;
151 s[0] = -b / r;
152 return r;
153}
162template <typename T> inline
163void Grot(T c, T s, T *a, T *b)
164{
165 T temp = a[0];
166 a[0] = c * temp - s * b[0];
167 b[0] = s * temp + c * b[0];
168}
169
170}
171
172}
173
174
175
176#endif
void Axpby(T a, T *x, T b, T *y, int N)
Compute y = a * x + b * y.
Definition: senk_blas1.hpp:66
T Dot(T *x, T *y, int N)
Compute the dot product of x and y.
Definition: senk_blas1.hpp:93
void HadDiv(T *x, T *y, int N)
Compute the element-wise division of x and y.
Definition: senk_blas1.hpp:133
void Copy(T *x, T *y, int N)
Copy x to y.
Definition: senk_blas1.hpp:27
void Scal(T a, T *x, int N)
Multiply x by a.
Definition: senk_blas1.hpp:39
T Nrm2(T *x, int N)
Compute the 2-norm of x.
Definition: senk_blas1.hpp:107
void HadProd(T *x, T *y, int N)
Compute the Hadamard product of x and y.
Definition: senk_blas1.hpp:121
void Axpyz(T a, T *x, T *y, T *z, int N)
Compute z = a * x + y.
Definition: senk_blas1.hpp:80
void Grot(T c, T s, T *a, T *b)
Compute the Gives rotation.
Definition: senk_blas1.hpp:163
void Axpy(T a, T *x, T *y, int N)
Compute y = a * x + y.
Definition: senk_blas1.hpp:52
T Ggen(T a, T b, T *c, T *s)
Generate a Gives rotation matrix.
Definition: senk_blas1.hpp:146
The top-level namespace of SenK.
Some supplemental functions are defined.