lecture-12

# lecture-12 - Dependence Analysis Monday Motivating question...

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

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

View Full Document

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

View Full Document

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

View Full Document

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Dependence Analysis Monday, November 29, 2010 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]; } Monday, November 29, 2010 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]) Monday, November 29, 2010 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! Monday, November 29, 2010 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]; } Monday, November 29, 2010 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]) Monday, November 29, 2010 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? Monday, November 29, 2010 Representing dependences • Focus on fow dependences ¡or 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?...
View Full 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 / 51

lecture-12 - Dependence Analysis Monday Motivating question...

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

View Full Document
Ask a homework question - tutors are online