lecture-13-6up

# lecture-13-6up - Motivating question Can the loops on the...

This preview shows pages 1–3. Sign up to view the full content.

Dependence Analysis Friday, November 18, 2011 Motivating question Can the loops on the right be run in parallel? i.e. , can different processors run different iterations in parallel? What needs to be true for a loop to be parallelizable? Iterations cannot interfere with each other No dependence between iterations for (i = 1; i < N; i++) { a [i] = b [i]; c [i] = a [i - 1]; } for (i = 1; i < N; i++) { a [i] = b [i]; c [i] = a [i] + b [i - 1]; } Friday, November 18, 2011 Dependences A fow dependence occurs when one iteration writes a location that a later iteration reads for (i = 1; i < N; i++) { a [i] = b [i]; c [i] = a [i - 1]; } i = 1 W(a[1]) R(b[1]) W(c[1]) R(a[0]) i = 2 W(a[2]) R(b[2]) W(c[2]) R(a[1]) i = 3 W(a[3]) R(b[3]) W(c[3]) R(a[2]) i = 4 W(a[4]) R(b[4]) W(c[4]) R(a[3]) i = 5 W(a[5]) R(b[5]) W(c[5]) R(a[4]) Friday, November 18, 2011 Running a loop in parallel If there is a dependence in a loop, we cannot guarantee that the loop will run correctly in parallel What if the iterations run out of order? Might read from a location before the correct value was written to it What if the iterations do not run in lock-step? Same problem! Friday, November 18, 2011 Other kinds of dependence Anti dependence – When an iteration reads a location that a later iteration writes (why is this a problem?) Output dependence – When an iteration writes a location that a later iteration writes (why is this a problem?) for (i = 1; i < N; i++) { a [i - 1] = b [i]; c [i] = a [i]; } for (i = 1; i < N; i++) { a [i] = b [i]; a [i + 1] = c [i]; } Friday, November 18, 2011 Data dependence concepts Dependence source is the earlier statement (the statement at the tail of the dependence arrow) Dependence sink is the later statement (the statement at the head of the dependence arrow) Dependences can only go forward in time: always from an earlier iteration to a later iteration. i = 1 W(a[1]) R(b[1]) W(c[1]) R(a[0]) i = 2 W(a[2]) R(b[2]) W(c[2]) R(a[1]) i = 3 W(a[3]) R(b[3]) W(c[3]) R(a[2]) i = 4 W(a[4]) R(b[4]) W(c[4]) R(a[3]) i = 5 W(a[5]) R(b[5]) W(c[5]) R(a[4]) Friday, November 18, 2011

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Using dependences If there are no dependences, we can parallelize a loop None of the iterations interfere with each other Can also use dependence information to drive other optimizations Loop interchange Loop fusion (We will discuss these later) Two questions: How do we represent dependences in loops? How do we determine if there are dependences? Friday, November 18, 2011 Representing dependences Focus on ±ow dependences for now Dependences in straight line code are easy to represent: One statement writes a location (variable, array location, etc.) and another reads that same location Can ²gure this out using reaching de²nitions What do we do about loops?
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 02/19/2012 for the course ECE 468 taught by Professor Test during the Fall '08 term at Purdue.

### Page1 / 9

lecture-13-6up - Motivating question Can the loops on the...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online