saxpy
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| saxpy [May 05, 2026 at 14:45] – yanevskiv | saxpy [June 13, 2026 at 03:13] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | # SAXPY | ||
| + | **SAXPY** is an algorithm in high-performance computing (HPC). | ||
| + | ## Math | ||
| + | ### Vectors | ||
| + | Let $\mathbf{y}^{(t)}, | ||
| + | |||
| + | 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 | ||
| + | ```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]; | ||
| + | } | ||
| + | } | ||
| + | ``` | ||
