Module 18: Loop Optimizations
  Lecture 36: Cycle Shrinking
 


The Final Code After Skewing is

For js = 2, n+m-2
for is = max(0, js-m+2), min(n-2, js)
I = is+2
j = js-is+2
A[I,j] = 0.5 * (A[i-1, j-1] + A[i-1, j+1])
endfor
endfor

Loop Blocking or Strip Mining

  • Creates doubly nested loops out of single loops
  • Organizes computation into chunks of approximately equal sizes
  • Used to overcome size limitations of caches and local memory
for I = 1,n
A[i] = B[i] + C[i]
endfor
for j = 1, n, k
for I = j, min(j+k, n)
A[i]=B[i]+C[i]
endfor
endfor

Example

for I = 1, 16
A[i+3]=A[i]+B[i]
endfor
for It = 1, 16, 5
for i=it, min(16, it+4)
A[i+3]=A[i]+B[i]
endfor
endfor