skip to content
Ivan's wiki
Site Tools
Search
Tools
Show pagesource
Backlinks
Recent Changes
Media Manager
Sitemap
>
Recent Changes
Media Manager
Sitemap
openmp-simd
This page is read only. You can view the source, but not change it.
# OpenMP SIMD **[SIMD](https://en.wikipedia.org/wiki/Single_instruction,_multiple_data)** (single instruction, multiple data) allows a modern CPU to add four floats in a single instruction by loading them into a wide register and operating on all four lanes simultaneously, exposed on x86 as SSE/AVX and on ARM as NEON. The compiler attempts to use these instructions automatically (auto-vectorisation), but it can be blocked by pointer aliasing, non-unit strides, or conditionals it cannot prove safe. `#pragma omp simd` is an explicit assertion that a loop is safe to vectorise, allowing the compiler to emit SIMD instructions even when it would otherwise be cautious: ```c #pragma omp simd reduction(+:sum) 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.
Page Tools
Show pagesource
Backlinks
Back to top