saxpy
SAXPY
SAXPY is an algorithm in high-performance computing (HPC).
Math
Vectors
Let $\mathbf{y}^{(t)}, \mathbf{x}^{(t)}\in\mathbb{R}^n$ be vectors over real numbers at some discrete time $t\in\mathbb{N}$ and let $a\in\mathbb{R}$ be a real parameter.
SAXPY is defined as a vector update of $\mathbf{y}$ at time $t+1$ according to the formula:
$$\mathbf{y}^{(t+1)} = a\mathbf{x}^{(t)} + \mathbf{y}^{(t)}$$
Elements
We can write $\mathbf{y}^{(t)} = (y_0^{(t)}, y_1^{(t)}, \dots, y_n^{(t)})$ and $\mathbf{x}^{(t)} = (x_0^{(t)}, x_1^{(t)}, \dots, x_n^{(t)})$
Thus if we look at individual vector elements, where $k\in\{0, 1, \dots, n\}$, we have the following formula: $$y_k^{(t + 1)} = a\cdot x_k^{(t)} + y_k^{(t)}$$
C
// y - Y vector // x - X vector // a - parameter // N - size of both vectors void saxpy(float* y, float* x, float a, size_t N) { size_t i; for (i = 0; i < N; i++) { y[i] = a * x[i] + y[i]; } }
saxpy.txt ยท Last modified: by Ivan Janevski
