Vectorizing a Loop
Turn a scalar loop into vector work.
The Scalar Loop
A plain loop touches one element per step. It is clear but leaves your CPU's vector lanes mostly unused.
for i in range(n):
out[i] = a[i] + b[i]The Vector Idea
Vectorizing means each loop step handles a whole pack of elements instead of one. You do more work per iteration.
All lessons in this course
- Meet the SIMD Type
- Element-Wise SIMD Math
- Choosing a SIMD Width
- Vectorizing a Loop