saxpy
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| saxpy [May 05, 2026 at 14:42] – created yanevskiv | saxpy [August 22, 2026 at 15:22] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | # SAXPY | ||
| + | |||
| + | **[SAXPY](https:// | ||
| + | |||
| + | SAXPY is the prototypical memory-bound operation in BLAS (Basic Linear Algebra Subprograms). | ||
| + | |||
| + | ## Example | ||
| + | |||
| + | This example shows SAXPY computation and its natural parallelism. | ||
| + | |||
| + | ```c | ||
| + | // compile: gcc -fopenmp -o saxpy saxpy.c | ||
| + | // run: ./saxpy | ||
| + | // description: | ||
| + | |||
| + | #include < | ||
| + | #include < | ||
| + | |||
| + | void saxpy(float* y, const float* x, float a, int n) { | ||
| + | #pragma omp parallel for | ||
| + | for (int i = 0; i < n; i++) { | ||
| + | y[i] = a * x[i] + y[i]; | ||
| + | } | ||
| + | } | ||
| + | |||
| + | int main() { | ||
| + | float x[1000], y[1000]; | ||
| + | for (int i = 0; i < 1000; i++) { | ||
| + | x[i] = i * 0.1f; | ||
| + | y[i] = i * 0.2f; | ||
| + | } | ||
| + | | ||
| + | saxpy(y, x, 2.5f, 1000); | ||
| + | printf(" | ||
| + | return 0; | ||
| + | } | ||
| + | ``` | ||
