Site Tools


saxpy

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
saxpy [May 05, 2026 at 14:42] – created yanevskivsaxpy [August 22, 2026 at 15:22] (current) – external edit 127.0.0.1
Line 1: Line 1:
 +# SAXPY
 +
 +**[SAXPY](https://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms#Level_1)** (Scalar Alpha X Plus Y) is a fundamental HPC operation: $\mathbf{y} = a\mathbf{x} + \mathbf{y}$ where $a$ is a scalar and $\mathbf{x}$, $\mathbf{y}$ are vectors. It's embarrassingly parallel—each element can be updated independently—making it a canonical benchmark for measuring parallel overhead.
 +
 +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: parallel SAXPY: y = a*x + y
 +
 +#include <omp.h>
 +#include <stdio.h>
 +
 +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("y[0] = %f\n", y[0]);
 +    return 0;
 +}
 +```