simd-openmp
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| simd-openmp [June 11, 2026 at 09:19] – created - external edit 127.0.0.1 | simd-openmp [Unknown date] (current) – removed - external edit (Unknown date) 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | # SIMD (OpenMP) | ||
| - | A modern CPU can add four floats in a single instruction rather than one, loading them into a wide register and operating on all four lanes simultaneously. This is **SIMD** (single instruction, | ||
| - | |||
| - | ```c | ||
| - | #pragma omp simd reduction(+: | ||
| - | for (int i = 0; i < N; i++) { | ||
| - | sum += a[i] * b[i]; | ||
| - | } | ||
| - | ``` | ||
| - | |||
| - | `simd` can be combined with `parallel for` as `#pragma omp parallel for simd` to both distribute iterations across threads and vectorise the iterations within each thread. The `aligned(ptr : 32)` clause tells the compiler that `ptr` is aligned to a 32-byte boundary, which is a prerequisite for some AVX load/store instructions. | ||
simd-openmp.1781169582.md.gz · Last modified: by 127.0.0.1
