






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







Program has high synchronization cost: n2 forks and synchronizations. Different processors may access c[i,j] and c[i,j+1] which may be on the same cache line.
doall i := 1 to n do for k := 1 to n do for j := 1 to n do c[i,j] = c[i,j] + a[i,k] * b[k,j] endfor endfor endall
Only one fork and synchronization Each task is large grain operation Each task fetches whole array B
Single front end issuing instructions Back ends or PEs execute each instruction Code divided into scalar and parallel code Scalar code executes on front end Each PE can access local memory directly Messages must be used to access values from another PE’s memory Assume each PE has one row of each matrix Variables 1A, 1B and 1C contain rows of A, B and C on each PE Fetch operation fetches 1B[j] from PE B kj is front end variable
for j := 1 to n do PE(0:n-1):ctmp = 0 for k := 1 to n do B kj = fetch(k-1)(1B[j]) PE(0:n-1):ctmp = ctmp + 1A(k) * B kj endfor PE(0:n-1):1C[j] = ctmp endfor
for k := 1 to n do if (k-1 = Pindex) then Bk[1 : n] = 1B[1:n] broadcast(Bk[1 : n]) else receive(Bk[1 : n]) endif for j = 1 to n do for i = 1 to nrows do 1C[i,j] = 1C[i,j] + 1A(i,k) * Bk[j] endfor endfor endfor
Sequential Loop: The second iteration does not start until the first iteration is complete. Forall Loop: This is a parallel loop corresponding to an array assignment. Each of the statements is executed completely for all the values of the index variable before the next statement is started.
Forall i= 1, n S S
Sm Endall
is equivalent to
S1(1:n) S2(1:n)
Sm(1:n)
Dopar Loop: This is a parallel loop corresponding to parallel processors. Each iteration of the loop is executed in parallel by a different processor.
The code within each iteration executes sequentially Initial state seen by each processor is same as the state before the loop Any variable update done by a processor can not be seen by any other processor If two iteration change the same variable, the result is non-deterministic merge
Represents single assignment statement Each variable assigned must be indexed by all loop index variables Each element must be assigned only once A statement in a dosingle sees all the updates From previous or subsequent iterations From previous or subsequent statements
dosingle i = 1 to 4 do a[i] = a[i-1] + 1 b[i] = b[i+1] + a[i-1] enddo
Re-structure code to exploit pipeline and caches. Convert sequential loops involving scalars to vector operation. Convert sequential loops into parallel loops. Partition data for data parallel model. Minimize messages to reduce overheads.
Shows hierarchical flow of control Source control flow is not available in MIR or LIR Loops may be constructed of ifs and gotos
Useful for collecting information for optimization Basic Block : Sequence of consecutive statements where flow of control enters at the beginning and leaves at the end. No branching permitted at an intermediate statement.
Input : A sequence of three address statements Output : A list of basic blocks
(1) i := m - 1 (2) j := n (3) t1 := 4* n (4) v := a[t1] (5) i := i + 1 (6) t2 := 4 * i (7) t3 := a[t2] (8) if t3 < v goto (5) (9) j := j - 1 (10) t4 := 4 * j (11) t5 := a[t4] (12) if t5 > v goto (9) (13) if i >= j goto (23) (14) t6 := 4 * i (15) x := a[t6]
(16) t7 := 4 * i (17) t8 := 4 * j (18) t9 := a[t8] (19) a[t7] := t (20) t10 := 4 * j (21) a[t10] := x (22) goto (5) (23) t11 := 4 * i (24) x := a[t11] (25) t12 := 4 * i (26) t13 := 4 * n (27) t14 := a[t13] (28) a[t12] := t (29) t15 := 4 * n (30) a[t15] := x
Add flow of control information to basic blocks. The directed graph is called flow graph. The nodes of the flow graph are basic blocks. One node is initial. There is a directed edge from block B1 to block B2 if B follows B1 in execution order.
Jump from B1 to B B2 follows B1 in the order of the program
Introduce two special nodes entry and exit Control always enters through the entry node Control always leaves through the exit node
A loop has a single entry point and the components of a loop are strongly connected in a CFG.
Dominators
A node d dominates a node n if every path from entry to n passes through d. Every node dominates itself. Dominance is a reflexive partial order.
Reflexive: A dom a a Antisymmetry: A dom b and b dom a a=b Transitive: A dom b and b dom c a dom c