Skip to content
BIASED

Multicore processors and thread-level parallelism

Block 1 of 3~2 min

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.

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