0Pricing
Mojo Academy · Lesson

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

  1. Meet the SIMD Type
  2. Element-Wise SIMD Math
  3. Choosing a SIMD Width
  4. Vectorizing a Loop
← Back to Mojo Academy