Previous | Next --- Slide 43 of 48
Back to Lecture Thumbnails
SR_94

Memory Barriers can be thought of as "fences" in the sense that a thread won't be allowed to move forward unless all the threads have performed all the work before that barrier.

axiao
  1. The first barrier is needed to ensure that all threads have set diff to 0. If this barrier didn't exist then a thread lagging behind the others could reset diff to 0 after another thread has already finished the computations and increments diff.

  2. The second barrier is needed to ensure that all threads have finished their updates to diff before checking convergence.

  3. The third barrier is needed to ensure that all threads have checked for convergence. If this barrier didn't exist, then a lagging thread could check for convergence after another thread resets diff back to 0 at the start of the while loop, which could make the lagging thread incorrectly detect convergence.

albusshin

Memory fence exists because the modern computer processors have some fancy features of executing instructions with no respect to the program order. In parallel programs this can be dangerous.