6 07 36 08 task 6 task 7 36 11 36 15 36

Info iconThis preview shows page 1. Sign up to view the full content.

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

Unformatted text preview: 3 3.6 0.5 Task 4 3.6 0.6 Task 5 3.6 0.7 3.6 0.8 Task 6 Task 7 3.6 1.1 3.6 1.5 3.6 2.6 What to do with the result? 1)  Leave it with one task 2)  Broadcast it back to all 3.6 totTime CSEP 524: Parallel ComputaCon Winter 2013: Chamberlain 60 Reduc3on Opera3ons •  Typical operaCons: +, *, &, |, ^, min[loc], max[loc], … –  typically operators that are commutaCve and associaCve •  Two main flavors: –  collecCve (“members contribute”) create tasks… const myContribution = doSomeWork(…); const total = sumReduceAll(myContribution); join tasks… –  global-­‐view (“holis!c”) const total = + reduce A; CSEP 524: Parallel ComputaCon // sum A’s elements Winter 2013: Chamberlain 61 —  Syntax reduce-expr: reduce-op reduce iterator-expr —  SemanCcs —  Combines argument values using reduce-­‐op —  Reduce-­‐op may be built-­‐in or user-­‐defined —  Examples total = + reduce A; bigDiff = max reduce [i in Inner] abs(A[i]-B[i]); (minVal, minLoc) = minloc reduce zip(A, D); 62 Fixing RRWW bugs with reduc3ons Collec3ve Style Global-­‐View Style create tasks … myTotTime = sumReduce(myTime); … join tasks var times: [0..#numTasks] real; Interes!ngly, collec!ve-­‐style reduc!ons are supported by neither Pthreads (to my knowledge) nor Chapel (planned as future work) CSEP 524: Parallel ComputaCon coforall tid in 0..#numTasks { … times[tid] = myTime; … } const totTime = + reduce times; Winter 2013: Chamberlain 63 Defining Parallel Reduc3ons •  What’s required? •  In the simplest case (result type == state type == input type) –  An idenCty element •  What should we return if we end up reducing nothing? –  A combiner funcCon •  Combines two input values to create a result value CSEP 524: Parallel ComputaCon Winter 2013: Chamberlain 64 Defining Parallel Reduc3ons •  What’s required? •  In the simplest case (result type == state type == input type) •  example1: sum reducCon •  example2: min reducCon –  An idenCty element •  0 •  max(type)? –  A combiner funcCon •  v1 + v2 •  max(v1, v2) CSEP 524: Parallel ComputaCon Winter 2013: Chamberlain 65 3.6 0.1 Task 0 3.6 0.2 Task 1 0.3 1.0 Fix: Use a Reduc>on 3.6 0.3 Task 2 0.7 3.6 0.4 Task 3 3.6 0.5 Task 4 1.1 3.6 0.6 Task 5 3.6 0.7 3.6 0.8 Task 6 Task 7 1.5 2.6 3.6 totTime CSEP 524: Parallel ComputaCon Winter 2013: Chamberlain 66 Defining Parallel Reduc3ons •  What’s required? •  More generally (result type != input type, or state is required) –  An idenCty element •  What should we iniCalize our state to? –  An accumulator funcCon •  Combines an input value and a state value, creaCng a state value –  A combiner funcCon •  Combines two state values, creates a state value –  A result funcCon •  Transforms a state value into an answer CSEP 524: Parallel ComputaCon Winter 2013: Chamberlain 67 Defining Parallel Reduc3ons •  What’s required? •  More generally (result type != input type, or state is required) –  example: “min-­‐max reducCon” (find range of values) •  e.g., min-­‐max reduce of [4, 2, 9, -­‐3, 7, 8] would be -­‐3..9 –  An idenCty element •  (max, min) –  An accumulator funcCon •  (min(newval, state.min), max(newval, state.max)) –  A combiner funcCon •  (min(state1.min, state2.min), max(state1.max, state2.max)) –  A result funcCon •  return state.min..state.max CSEP 524: Parallel ComputaCon Winter 2013: Chamberlain 68 That’s it for today! •  QuesCons? CSEP 524: Parallel ComputaCon Winter 2013: Chamberlain 69...
View Full Document

This document was uploaded on 04/04/2014.

Ask a homework question - tutors are online