Race Conditions, Chess, Matrix Multiplication




CS255

Chris Pollett

Feb 18, 2019

Outline

Introduction

Race Conditions

Preventing Race Conditions

Another Race Example

Quiz

Which of the following statements is true?

  1. For parallel algorithms, work is the longest time to execute strands along any path in a computation dag.
  2. Brent's Theorem is the upper bound: `T_P le T_1/P`.
  3. The running time `T_P` of any multithreaded computation scheduled by a greedy scheduler on an ideal parallel computer with P processors is within a factor of 2 of optimal.

Chess Program Socrates

Multithreaded Matrix Multiplication

Multithreaded Matrix Multiplication - Take 2

Divide-and-Conquer Matrix Multiply with Parallelism

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]

Analysis of P-MATRIX-MULTIPLY-RECURSIVE(C, A, B)