Lecture 06 · Concurrency and Parallelism on CPUs

The whole deck on two pages.

Page numbers are the numbers printed on the slides of ../lectures/Lecture_06_ConcurrencyParallelism.pdf.

Parallelism taxonomy

Level Mechanism Extracted by Coordinated via Bounded by
Instruction pipelining, superscalar, OoO hardware registers hazards (RAW/WAR), branches
SIMD AVX/SSE compiler / intrinsics predication, masks dependencies, memory wall
Thread threads on 10s of cores programmer locks, atomics, messages Amdahl, sync overhead
Thread across NUMA threads across sockets programmer + OS same locks + topology awareness remote memory latency
Distributed processes on many machines programmer + frameworks message passing network, failures, consistency

p.5

Amdahl's law

T_new = T(1 − p) + T·p/s Speedup = 1 / ((1 − p) + p/s) limit = 1 / (1 − p)

OS concepts

Synchronization

Kind Examples Waiting p.
software / OS semaphore, mutex sleep 28
hardware CAS, fetch-and-add, atomic logic ops spin 28
fences order w.r.t. earlier loads — 28
futex test-and-set in user space, kernel only on contention sleep after failing 31

Patterns

Exam-style questions from the deck p.40

  1. What do a loop-carried dependency and a branching instruction have in common for a superscalar, pipelined CPU?
  2. T/F: compiler hints, used correctly, can express the same level of detail as intrinsics.
  3. Can for x: for y in 0..16: sum[y] += A[x*16+y] be vectorized? Why or why not?
  4. A software pipeline with one thread per stage needs no synchronization. Why or why not?
  5. The disk + parallel compute example.