CS255
Chris Pollett
Feb 16, 2015
RACE-EXAMPLE 1 x = 0 2 parallel for i = 1 to 2 3 x = x + 1 4 print xAfter line 1 two parallel strands try to increment x in line 3, and print x in line 4.
MAT-VEC-WRONG(A, x) 1 n = A.rows 2 let y be a new vector of length n 3 parallel for i = 1 to n 4 y[i] = 0 5 parallel for i = 1 to n 6 parallel for j = 1 to n 7 y[i] = y[i] + a[i][j] * x[j] 8 return y
Which of the following is true?
P-SQUARE-MATRIX-MULTIPLY(A, B) 1 n = A.rows 2 let C be a new n x n matrix 3 parallel for i = 1 to n 4 parallel for j = 1 to n 5 c[i][j] = 0 6 for k = 1 to n 7 c[i][j] = c[i][j] + a[i][k] * b[k][j] 8 return C
P-MATRIX-MULTIPLY-RECURSIVE(C, A, B) 1 n = A.rows 2 if n == 1 3 c[1][1] = a[1][1] * b[1][1] 4 else let T be a new n x n matrix 5 partition A, B , C , and T into n/2 x n/2 submatrices A_(11), A_(12), A_(21), A_(22); B_(11), B_(12), B_(21), B_(22); C_(11), C_(12), C_(21), C_(22); and T_(11), T_(12), T_(21), T_(22) respectively 6 spawn P-MATRIX-MULTIPLY-RECURSIVE(C_(11), A_(11), B_(11)) 7 spawn P-MATRIX-MULTIPLY-RECURSIVE(C_(12), A_(11), B_(12)) 8 spawn P-MATRIX-MULTIPLY-RECURSIVE(C_(21), A_(21), B_(11)) 9 spawn P-MATRIX-MULTIPLY-RECURSIVE(C_(22), A_(21), B_(12)) 10 spawn P-MATRIX-MULTIPLY-RECURSIVE(T_(11), A_(12), B_(21)) 11 spawn P-MATRIX-MULTIPLY-RECURSIVE(T_(12), A_(12), B_(22)) 12 spawn P-MATRIX-MULTIPLY-RECURSIVE(T_(21), A_(22), B_(21)) 13 P-MATRIX-MULTIPLY-RECURSIVE(T_(22), A_(22), B_(22)) 14 sync 15 parallel for i = 1 to n 16 parallel for j = 1 to n 17 c[i][j] = c[i][j] + t[i][j]