Skip to content
BIASED

Multicore processors and thread-level parallelism

Why cores instead of clock, Amdahl and Gustafson, coherence and MESI, false sharing, sequential consistency, SMT.

Why many cores

After Dennard scaling, power — not transistors — limited clocks. Several moderate cores do more work per watt on parallel work than one hotter core. Sequential programs need rewriting to benefit.

Worked example (measured). Two threads each add 1 to their own counter 100 million times with an atomic add (the usual way to keep shared statistics counters correct; the synchronization note explains atomics). In the first run the two counters are 8 bytes apart, on one line; in the second, each starts a 128-byte line of its own, the line size macOS reports for the M1. On the M1 (macOS 26.5, Apple clang 21, -O0), one run took 2.52 s with the counters on one line and 0.22 s on separate lines, 11 times longer for the same work, though the threads never touch each other’s counter. The times vary from run to run and between machines; three runs gave 2.46–2.52 s and 0.21–0.22 s. With plain volatile long counters and (*c)++ instead of atomics, the difference on the same machine was much smaller and unstable, between 1.0 and 1.7 times in eight runs: an atomic read-modify-write needs the line in M at every step, while plain stores can wait in the core’s store buffer and reach the cache together.

Worked example. A program with p=0.95 runs 1/(0.05+0.95/8)=5.931/(0.05 + 0.95/8) = 5.931/(0.05+0.95/8)=5.93 times faster on 8 cores, an efficiency of 74 %. On 1,024 cores it runs 19.64 times faster, and no number of cores gets it past 20: the 5 % that is serial on one core is 98 % of the time on 1,024 cores. Read backwards, the law says how parallel a program must be. Solving S=1/((1−p)+p/n)S = 1/((1 - p) + p/n)S=1/((1−p)+p/n) for ppp gives p=(1−1/S)/(1−1/n)p = (1 - 1/S)/(1 - 1/n)p=(1−1/S)/(1−1/n): a speed-up of 6 on 8 cores needs p=0.952, and a speed-up of 50 on 64 cores needs p=0.9956, a serial part below half a percent.

Amdahl and Gustafson

Amdahl: S(n)=1/((1−p)+p/n)≤1/(1−p)S(n)=1/((1-p)+p/n)\le 1/(1-p). With p=0.95p=0.95: ≈5.93 on 8 cores, never above 20.

Gustafson: when the problem grows with the machine, S=s+(1−s)nS=s+(1-s)n with ss the serial fraction of the parallel run.

Worked example. A four-wide core runs a thread that alternates between 6 cycles in which it starts 2 instructions per cycle and 4 cycles stalled on a cache miss: 12 instructions in 10 cycles, IPC 1.2, using 30 % of the 40 issue slots. With SMT and a second thread of the same kind, the core starts up to 4 instructions per cycle from the two threads together, and 24 instructions in 10 cycles, IPC 2.4, if the two threads do not slow each other down in the caches. Each thread is no faster than alone; the core gets more done. Intel’s first implementation of SMT, Hyper-Threading, ran two threads per core, added less than 5 % to the chip’s size and power, and measured gains of up to 30 % on server benchmarks (Marr et al., 2002). The M1 used here has no SMT: macOS reports 8 cores and 8 hardware threads.

Worked example. Two cores, A and B, with write-back caches as in the caches note, and a variable X that is 0 in memory.

MESI and false sharing

Private caches need coherence: reads see the latest write; writes to one location serialize. MESI (Modified/Exclusive/Shared/Invalid) uses invalidation — many readers or one writer per line. False sharing: unrelated variables on one line bounce it between cores; pad hot per-thread data to the line size (M1: 2.52 s → 0.22 s). Sequential consistency (Lamport): some interleaving explains the execution. Store buffers weaken that; fences and SC atomics restore it. SMT issues from several hardware threads in one core. Why multicore. After Dennard scaling ended, power — not transistor count — capped clocks near 3–4 GHz. Several moderate cores deliver more work per watt on parallel jobs than one hotter core; sequential codes must be rewritten to benefit. Amdahl: S(n)=1/((1-p)+p/n)\≤ 1/(1-p). With p=0.95: ≈5.93× on 8 cores, never above 20×. Gustafson scales the problem with the machine: S=s+(1-s)n using the serial fraction of the parallel run. Coherence. Private caches need a protocol so reads see the latest write and writes to one location serialize. MESI (Modified/Exclusive/Shared/Invalid) uses invalidation: many readers or one writer per line. A store on one core forces others’ copies to I; the next reader misses and refills. False sharing: unrelated variables on one line bounce it between cores. Padding hot per-thread counters to the line size cut an M1 demo from 2.52 s → 0.22 s. Sequential consistency (Lamport) is what programmers often assume; store buffers weaken it — fences and sequentially consistent atomics restore ordering. SMT issues from several hardware threads in one core to hide latency. MESI walk: Core A reads line L → Shared (or Exclusive if alone). Core B reads → both Shared. A writes → B’s copy Invalid, A Modified. B reads again → writeback or forward from A, both Shared. False sharing is the same protocol firing on a line that happens to hold two hot variables. Programming models: pthreads/OpenMP for shared memory; MPI for distributed; GPU kernels for DLP-heavy loops. Start with Amdahl: if 20% is serial, 64 cores cannot give more than 5× — profile before buying hardware. Pinning threads (OMP_PROC_BIND, taskset) reduces migration noise when measuring scaling curves. Next: Vectors, SIMD and GPUs — one instruction, many data elements. Worked example. One core runs at frequency fff and voltage VVV and draws power PPP. Replace it by two cores of the same design, each at 0.8f0.8f0.8f and 0.8V0.8V0.8V. Each draws 0.8⋅0.82⋅P=0.512 P0.8 · 0.8^2 · P = 0.512 P0.8⋅0.82⋅P=0.512P, both together 1.02 P1.02 P1.02P: the same power budget. If the work splits evenly between them, they do 2⋅0.8=1.62 · 0.8 = 1.62⋅0.8=1.6 times as much per second. If it does not split at all, the program runs at 0.80.80.8 of its old speed. Multicore is a

Check your understanding

The same questions as in Pulse. Answers are shared between modes.

Full notes

Answers are saved on the server and tied to this browser until you sign in.