Module 18: Loop Optimizations
  Lecture 35: Amdahl’s Law
 


Loop Vectorization

  • Generate vector instructions out of the loop
  • Check for all dependencies in the loop
for I = 1,n
A[i] = B[i] + C[i]
D[i] = B[i] * k
endfor
A[1..n] = B[1..n] + C[1..n]
D[1..n] = k * B[1..n]

Partial Loop Vectorization

For I = 1,n
A[i+1] = B[I-1] + C[i]
B[i] = A[i] * k
C[i] = B[i] -1
endfor

 

for I = 1,n
A[i+1] = B[i-1] + C[i]
B[i] = A[i] * k
endfor
C[1..n] = B[1..n] –1

Nested Loops

  • Useful to identify which loop 'carries the dependence'.
  • Assume loops are numbered: outermost is 1, next one is 2 and so on
  • Example
    for I=1,N
    for J=1,M
    X[I,J]=X[I-1,J]
    endfor
    endfor