Lecture 6 · Performance Optimization II: Locality, Communication and Contention

Parallel Computing · Lecture 06。个人学习讲义与配套实验,按主题整理并持续修订。

课程源码 ZIP ↓

个人整理的学习笔记,非官方讲义;课程来源与整理说明见课程介绍。配套示例未逐一运行验证。

本篇目录

Maps to: Stanford CS149 Fall 2025, Lecture 6 (Oct 9), slide deck 06_progperf2 (68 slides). Sources: the public Fall 2025 slides; the 2023 lecture video. Every experiment and number below was written for these notes and run on the author’s machine (Apple M4 Pro, 8 performance + 4 efficiency cores; clang 21, macOS 27). The message passing library of §2 is a small one written for these notes; it runs threads on one chip and can simulate a network latency. Code: code/lecture06/. Reading time: ~90 minutes for the prose; ~20 more for the demos.


0. How to read this lecture

0.1 Learning goals

After this lecture you should be able to:

  1. Describe how a shared address space (共享地址空间) is implemented (interconnects such as rings and crossbars, NUMA (非一致内存访问)), and write a program in the message passing (消息传递) model: private address spaces, ghost cells (幽灵单元), send and receive.
  2. Explain why synchronous (同步/阻塞) sends can deadlock (死锁), fix it by ordering, and use asynchronous (异步/非阻塞) sends to overlap communication with computation.
  3. Treat every data movement as communication, using the “extended memory hierarchy” view, and compute a program’s arithmetic intensity (算术强度).
  4. Separate inherent communication (固有通信), which the algorithm and assignment require, from artifactual communication (人为通信), which the machine adds: line granularity, capacity misses, write-allocate and conflict misses.
  5. Apply the standard cures: better assignment (2D blocks), blocking/tiling (分块), loop fusion (循环融合), sharing data between co-located tasks.
  6. Recognize contention (争用) for a shared resource and reduce it by replication, staggering and tree-structured communication.
  7. Use the roofline model (屋顶线模型) and slide 57’s “high watermark” experiments to decide whether a program is limited by compute, bandwidth or synchronization.
  8. Explain how problem size changes speedup: strong vs. weak scaling (强/弱扩展), and super-linear speedup (超线性加速).

0.2 Prerequisites and scope

  • Prerequisites: Lecture 1 (caches, locality), Lecture 3 (latency vs. bandwidth, bandwidth-bound programs), Lecture 4 (the grid solver, barriers), Lecture 5 (work queues and stealing).
  • Scope: everything about moving data: between processors, between a processor and memory, and between a processor’s cache and another’s. Lecture 5 was about who does the work; this lecture is about what moves where while they do it. Cache coherence, the mechanism behind “a line moves between cores”, is Lecture 14.

0.3 Section → code map

SectionIdeaDemo in code/lecture06/
§2message passing, ghost rows, deadlock, async sends, overlap01_message_passing
§3–§4arithmetic intensity; inherent vs. artifactual communication02_communication.py, 03_locality (Parts A–B)
§5blocking, loop fusion, conflict misses03_locality (Parts C–D)
§6contention: office hours, trees, a shared histogram04_contention.py, 05_histogram_contention
§7the roofline; high watermarks06_roofline, 07_high_watermarks
§8problem size and scaling08_scaling

Run them all with cd code/lecture06 && make run (~30 seconds).

0.4 Notation and conventions

  • P = number of processors (threads). N = grid side, or problem size. GB/s = 10⁹ bytes per second. “Line” = cache line, 128 bytes on the author’s machine (64 on most x86 machines).
  • The author’s machine has 8 performance cores in two clusters of 4; each cluster shares one 16 MiB L2 cache. This matters in §8.
  • As in Lectures 4–5, another program kept one performance core busy during the runs, so programs with a barrier every step often run slower on 8 threads than on 6. Several demos use 4 or 6 threads for that reason and say so.

1. Where the time goes when processors cooperate

Slide 2 lists today’s topic: techniques for reducing the cost of communication, between processors and between processors and memory, plus general program optimization tips.

So far we have assumed (slide 3) that all processors are connected to a memory that offers the abstraction of a single shared address space: any thread can load or store any address. That abstraction is convenient. Its implementation is not simple. Slide 4: on a modern chip, “load the value at address X into register R0” may involve the core’s L1, its L2, a shared L3 slice somewhere else on the chip, the memory controller and DRAM, plus messages between caches to find the newest copy. A program that ignores what happens behind the abstraction can be correct and still slow.

The intuition for this lecture. In Lecture 5 a processor was idle because it had no work. Today it is idle because it waits for data. Lecture 3 showed that a core computes far faster than memory can feed it, so where data lives, and how often it has to move, often decides performance more than the arithmetic does.


2. Two ways to communicate

2.1 Shared address space, and how it is built

In the shared address space model (slide 9), threads communicate by reading and writing shared variables, and coordinate with locks, atomics and barriers. It is the logical extension of single-threaded programming, and it needs hardware support: any processor must be able to load from and store to any address.

How is “any processor can reach any address” built?

  • A ring (slides 5–6): Intel’s client chips since Sandy Bridge connect the cores, the slices of the L3 cache, the graphics unit and the “system agent” (memory controller) on rings. Each L3 slice is a stop on the ring. Separate rings carry requests, snoops, acknowledgements and 32-byte data. The theoretical peak from cores to L3 is ~435 GB/s when every core uses its local slice. A core whose data lives in a slice across the ring waits longer.
  • A crossbar (slide 7, Sun Niagara 2): every core is connected directly to every L2 bank. It is fast and uniform, but the crossbar’s area is about that of a whole core, and it grows quadratically with the number of endpoints. This is one reason chips with many cores are expensive.
  • NUMA (slide 8): in a multi-socket server, each socket has its own memory controller. Memory attached to your socket is faster than memory on the other socket, and bandwidth differs too. That is non-uniform memory access. Slide 8’s footnote: NUMA effects exist even on one chip, because different cache slices are at different distances from a core. On the author’s machine, a line in the other cluster’s L2 is farther away than one in your own.

Summary (slide 9): shared memory is the easy model to program, but NUMA implementations require reasoning about locality for performance.

2.2 The message passing model

Slides 10–13 introduce a different abstraction that makes communication explicit:

  • every thread has its own private address space; nothing is shared;
  • threads communicate only by sending and receiving messages:
    • send(X, 2, my_msg_id): send the contents of local variable X to thread 2, tagged with the id my_msg_id;
    • recv(Y, 1, my_msg_id): receive the message with that tag from thread 1 into local variable Y.

The metaphor is snail mail (slide 12): you cannot reach into someone’s house; you put a letter in the post.

Why would anyone choose this? Because the hardware becomes simpler (slide 13). The machine no longer has to provide one address space; it only needs a way to deliver messages between nodes. You can connect commodity computers with a network (e.g. InfiniBand) into a cluster or a supercomputer. Message passing, in practice the MPI library, is how programs run on such machines. And even on one chip, explicit communication has a virtue: you can see in the source code every byte that moves.

2.3 The grid solver with messages

Slides 14–19 take Lecture 4’s grid solver into this model. The grid (N × N, red-black updates, repeat until the average change is small) is split into blocks of rows, one block per thread. Each block lives in a different private address space (slide 16).

A cell on the edge of a block needs its neighbour’s row, which belongs to someone else. The fix is data replication (slide 17): each thread allocates rows_per_thread + 2 rows. The two extra rows are ghost rows, local copies of the neighbours’ boundary rows, which the neighbours send when they change. “Ghost cells are grid cells replicated from a remote address space.” They are owned by another thread; the local copy is only a cache of their values.

Slide 18’s solver (pseudocode from Culler, Singh and Gupta) per iteration:

// send my boundary rows to the neighbours, then receive theirs
if (tid != 0)               send(&localA[1,0],               sizeof(float)*(N+2), tid-1, MSG_ID_ROW);
if (tid != num_threads-1)   send(&localA[rows_per_thread,0], sizeof(float)*(N+2), tid+1, MSG_ID_ROW);
if (tid != 0)               recv(&localA[0,0],               sizeof(float)*(N+2), tid-1, MSG_ID_ROW);
if (tid != num_threads-1)   recv(&localA[rows_per_thread+1,0], sizeof(float)*(N+2), tid+1, MSG_ID_ROW);
// ... update my rows, exactly as in the shared-memory version, accumulating my_diff ...
if (tid != 0) {
    send(&my_diff, sizeof(float), 0, MSG_ID_DIFF);       // everyone reports to thread 0
    recv(&done, sizeof(bool), 0, MSG_ID_DONE);           // ... and waits for its verdict
} else {
    // receive all diffs, add them, decide, send "done" to everyone
}

Notes from slide 19:

  • Computation: array indexing is relative to the local address space (local row 1 is some global row).
  • Communication: done by messages, in bulk: whole rows at a time, not single values.
  • Synchronization: also done by messages. There is no lock and no barrier. The diff reduction plus the “done” broadcast play the role of Lecture 4’s barriers and shared diff.

01_message_passing runs this on 4 threads with private arrays. A small library in the file gives every thread a mailbox; send copies the data into a message and recv copies it out, so no thread ever reads another thread’s rows directly. To compare exactly with Lecture 4, each colour phase exchanges ghost rows (the red update needs neighbours’ newest black values and vice versa). Every working version reproduces the serial red-black grid bit for bit: 244 sweeps, identical floats.

2.4 Synchronous send and deadlock

What does send return? Slide 20 defines the synchronous (blocking) version:

  • send() returns when the sender has received an acknowledgement that the data is in the receiver’s address space;
  • recv() returns when the data has been copied into the receiver’s buffer, and the acknowledgement has been sent back.

Slide 21’s question: what goes wrong with slide 18’s solver if send is synchronous? Every thread starts with a send. Thread 1’s send to thread 0 cannot return until thread 0 posts a matching receive, but thread 0 is itself stuck in its send to thread 1. Every thread waits for a neighbour that is waiting for it: a cycle of waits, which is a deadlock.

Demo 01, Part A runs exactly that code. The library declares a deadlock when a wait lasts more than one second, and reports where each thread was:

deadlock detected: YES (after the 1-second timeout)
thread 0 was waiting in send(to 1, ROW_DOWN)
thread 1 was waiting in send(to 0, ROW_UP)
thread 2 was waiting in send(to 1, ROW_UP)
thread 3 was waiting in send(to 2, ROW_UP)

Slide 22’s fix, still with synchronous sends: break the cycle by ordering. Even-numbered threads send and then receive; odd-numbered threads receive and then send. Every send now meets a receive that is already waiting:

if (tid % 2 == 0) { sendDown(); recvDown(); sendUp(); recvUp(); }
else              { recvUp();   sendUp();   recvDown(); sendDown(); }

A practical warning. MPI’s ordinary MPI_Send may buffer small messages and return early (an “eager” protocol), so slide 18’s code often works with small rows and then deadlocks when the rows get bigger and MPI switches to a rendezvous protocol. A program that is correct only because the library buffers is not correct. Our library makes the synchronous case explicit.

2.5 Asynchronous send and overlap

Slide 23 defines the non-blocking, asynchronous versions:

  • send() returns immediately. The buffer passed to send must not be modified until the message has gone, because message processing continues concurrently with the thread; checksend() tells when it is safe.
  • recv() posts the intent to receive and returns immediately; checkrecv() tells when the data has arrived.
  • In between, the calling thread can do other work.

Two things follow. First, the ordering puzzle disappears: a send that never waits cannot be part of a cycle of waits. Second, communication can overlap computation: send your boundary rows as soon as you have computed them, update your interior rows while they travel, and only then wait for the neighbours’ rows.

Demo 01, Part B times the working versions. Latency 0 means threads on one chip; 20 µs is a cluster network with a software messaging stack (the library delays each message, and each synchronous acknowledgement, by that much):

versionlatency 0latency 20 µs
slide 22: even/odd order, synchronous sends0.193 ms per sweep (3.32×)0.394 ms (1.62×)
slide 18’s order, asynchronous sends0.186 ms (3.43×)0.253 ms (2.52×)
asynchronous + overlap (send boundary rows first)0.179 ms (3.58×)0.213 ms (3.00×)

(Speedups over the serial solver, 0.639 ms per sweep, with 4 threads.)

On one chip the versions cost about the same: 18 messages per sweep are little next to 262,144 cell updates per thread. With a 20-µs network the differences are exactly what the model predicts:

  • Synchronous even/odd pays its waits one after another: each rendezvous costs a delivery and an acknowledgement.
  • Asynchronous sends its ghost rows at the start of each phase and then waits one latency for the neighbours’ rows; with two phases plus the gather and broadcast of the diff, that is 4 latencies per sweep. Predicted 0.186 + 4 × 0.020 = 0.266 ms; measured 0.253.
  • Overlap hides the ghost rows behind the interior update. Only the diff reduction’s two latencies remain, because no work is available to cover them. Predicted 0.179 + 2 × 0.020 = 0.219 ms; measured 0.213.

The last point generalizes: overlap needs independent work to do while waiting. The interior rows are independent of the incoming ghost rows; the convergence test is not independent of the diff. (Exercise 1 of the code README: test convergence less often.)

2.6 What this taught us about communication

Message passing makes every byte visible. Demo 01, Part C counts them: per sweep, 6 ghost-row messages per phase × 2 phases + 3 diffs + 3 “done”s = 18 messages, 48 KiB in total. Per interior thread: 262,144 cell updates for 4,104 floats received, 64 updates per float communicated. That ratio is the key quantity of the next section.

Plan vs reality. The first version of the library was 3× too slow: async sends gave 0.95× on 4 threads, and a 20-µs network looked faster than none. A thread waiting in recv locked and unlocked its mailbox in a tight loop, and the sender needed that same lock to deliver the message. The waiting thread kept delaying exactly what it waited for. That is contention (§6) in the very code meant to show communication. Waiters now watch an arrival counter and take the lock only when it changes.


3. Communication is everywhere: the extended memory hierarchy

3.1 Not only messages

Slide 24: “communication” does not only mean messages between machines. It includes communication between cores on a chip, between a core and its cache, and between a core and memory. Slide 25 asks you to think of a parallel system as an extended memory hierarchy. From one processor’s point of view:

registers → local L1 → local L2 → L3 / another core's L2 → local memory
          → remote memory (1 network hop) → remote memory (N hops)
lower latency, higher bandwidth, smaller capacity  ......  higher latency, lower bandwidth, larger capacity

An access not satisfied at one level causes communication with the next. Managing locality to reduce the amount of communication matters at every level: the same reasoning applies to a cache miss, to a page on another socket and to a row on another cluster node.

3.2 One example: a load from memory

Slide 26 traces a single load: the core issues the load, the L1 is looked up (miss), the L2 is looked up (miss), a request is sent to memory, memory transfers the line over the memory bus, and the value reaches the register. The total latency is the sum, but in a well-designed system many such requests are in flight at once (Lecture 2 measured ~34 outstanding misses per core).

Slides 27–29 recall Lecture 3’s bandwidth-bound example: a processor that executes 2 math instructions per cache line it loads. In steady state the memory bus transfers data 100% of the time and the core stalls in between. The core’s utilization depends only on the instruction throughput and the memory throughput, not on the latency and not on the number of outstanding requests, provided there are enough of them. Slide 29’s questions, with answers:

  • How can you tell the memory bus is fully utilized? There is no gap between consecutive transfers.
  • How would you show higher latency? Each request starts earlier relative to its use, and more requests are outstanding at once; the throughput does not change.
  • What if bandwidth increased? Transfers get shorter, stalls shrink, and utilization rises until compute becomes the limit.
  • Would there still be stalls with many more math instructions per load? No, once the math per line takes longer than transferring a line: the program becomes compute-bound.

3.3 Arithmetic intensity

Slide 30 names the ratio that decides which limit applies:

arithmetic intensity = amount of computation (e.g. instructions or FLOPs) / amount of communication (e.g. bytes)

Its inverse, the communication-to-computation ratio, says the same thing; Kayvon prefers intensity “since higher is better” (and “it sounds cooler”). If the numerator is the computation’s execution time, the ratio gives the average bandwidth requirement of the code.

Why it matters: modern processors have a very high ratio of compute capability to bandwidth. Lecture 3 measured C = A × B at ~3% of the chip’s arithmetic peak. High arithmetic intensity is required to use a parallel processor efficiently. §7 turns this into a picture (the roofline); first, where does the communication come from?


4. Inherent vs. artifactual communication

Slide 31 splits communication in two:

  • Inherent communication (slides 32, 35): information that fundamentally must move between processors to carry out the algorithm with the chosen assignment, assuming unlimited cache capacity, transfers of exactly the needed size, and so on. The ghost rows of §2 are inherent.
  • Artifactual communication: all other communication, which results from practical details of the system implementation: cache line sizes, cache capacities, write policies, memory layout.

The distinction tells you where to look. Inherent communication changes only with the algorithm or the assignment. Artifactual communication changes with the code’s traversal order and data layout, and with the machine.

4.1 Inherent communication depends on the assignment

Slides 33–34 compare assignments of the N × N grid to P processors. 02_communication.py, Part A counts the cells each processor must receive per sweep by enumerating every cell and its four neighbours (N = 256):

P1D blocked rows: received / intensity1D interleaved rows2D blocks
4512 / 3232,768 / 0.5256 / 64
16512 / 88,192 / 0.5256 / 16
64512 / 22,048 / 0.5128 / 8
256512 / 0.5512 / 0.564 / 4

(“Intensity” here = cells computed per cell received, for the busiest processor.)

  • 1D blocked: each processor computes N²/P cells and receives two rows, 2N cells, whatever P is. Intensity ∝ N/P: it shrinks as processors are added.
  • 1D interleaved: every row’s neighbours belong to other processors, so each processor receives about twice what it computes. Intensity 1/2 at any P. The worst choice for this stencil (Lecture 4 measured 73× more communication than blocked).
  • 2D blocked: a processor’s block is (N/√P) × (N/√P); it receives only the perimeter, ≈ 4N/√P cells. Intensity ∝ N/√P. Slide 34: “asymptotically better communication scaling than 1D blocked… communication costs increase sub-linearly with P; the assignment captures the 2D locality of the algorithm.”

The geometry is general. Computation grows with a block’s volume (area, here), communication with its surface (perimeter). The more compact the block, the better the ratio. That is why 3D simulations use cubes, not slabs.

4.2 Artifactual communication from caches

Slides 36–39 look at communication between memory and one processor running the stencil. Assume (slide 37) a row-major grid, cache lines of 4 grid elements and a cache of 24 elements (6 lines). Updating cell (i, j) reads (i−1, j), (i, j±1), (i, j) and (i+1, j).

Traverse row by row. By the time the sweep returns to row i for the cells of row i+1, the lines of row i have been evicted: the cache cannot hold three rows. So every row is loaded three times, once as the “row below”, once as “my row” and once as the “row above”. Slide 39: “this program loads three cache lines for every four elements of output”, even though every element is used five times.

02_communication.py, Part B replays this through Lecture 1’s LRU cache simulator, on a 34 × 32 grid with border:

traversallines loaded per output (middle of the sweep)
row-major (slide 37)0.800 = 3.2 per 4 outputs (3 per 4 columns; border columns produce no output)
slide 42’s blocked strip, columns 1–60.333 = 2.00 per 6 outputs
strips of 4 over the whole grid0.533 (33% fewer than row-major)
strips of 6 over the whole grid1.042 (worse than row-major)
strips of 14 over the whole grid0.981
ideal: every line loaded once0.283

The slide’s blocked iteration (§5.1) is reproduced exactly. But tiling the whole grid with strips of 6 is worse than not blocking at all. From the second strip on, the 8 columns a strip reads straddle three lines per row: 3 rows × 3 lines = 9 lines, more than the 6 the cache holds, so the strip thrashes. A tile must fit the cache including the partial lines at its edges. Strips of 4 (always exactly two aligned lines per row) work.

Slide 40 lists the other artifactual sources:

  1. Minimum granularity of transfer. A program that loads one 4-byte float still moves a whole line: 64 bytes on most x86 chips (16× more than needed), 128 on the author’s.
  2. Unnecessary system operations. A program that writes 16 consecutive floats (one whole 64-byte line) may first load that line from memory (write-allocate), overwrite it entirely, then write it back: 2× the necessary traffic.
  3. Finite replication capacity. The same data is communicated to the processor several times because the cache is too small to keep it between uses (capacity misses), as in slide 39.

4.3 Measured on the real machine

03_locality, Part A reads one element out of every s from a 256 MiB array with 8 threads:

stride s (4-byte elements)timeuseful GB/sbytes moved per byte used
11.44 ms1861
41.20 ms564
32 (one per 128-byte line)1.32 ms6.432
64 (every other line)0.72 ms5.832

Strides 1 to 32 take the same time: the whole line moves either way. Useful bandwidth falls 29× at stride 32. Only skipping whole lines saves time. A data layout that uses a few bytes per line, such as an array of large structs of which you read one field, pays the same price.

Part B asks whether the M4 pays slide 40’s write-allocate penalty. It does not: with 8 threads, store-only streams reach 241 GB/s and copies 212 GB/s, against 215 for read-only streams. With write-allocate, store-only would move 2 bytes per byte stored and fall far below the read rate. This machine evidently avoids reading lines that are about to be overwritten entirely; we did not find documentation of the mechanism. Many x86 machines do pay the penalty for ordinary stores, which is why they offer “non-temporal” (streaming) store instructions. Check your own machine instead of assuming either behaviour.


5. Techniques for reducing communication

5.1 Blocking: change the traversal order for temporal locality

Slide 42: blocking reorders the computation to reduce capacity misses. Process the grid in column strips. Within a strip, rows i−1 and i are still in the cache when row i+1 is needed, so each new row of outputs costs only the lines of the row below. The rule behind every tiling: choose the tile so that its working set fits the cache.

Real caches add something the slides’ fully associative cache cannot show: conflict misses. A real cache is set-associative: a line can live in only a few places, chosen by some bits of its address. Addresses that differ by a large power of two land in the same set. 03_locality, Part D transposes an 8,192 × 8,192 float matrix (B[j][i] = A[i][j]). The naive loop reads rows of A and writes columns of B, so every write lands in a different line, 32 KiB from the last:

row lengththreadsnaivebest tilespeedup from tiling
8,192 floats (power of 2)1326 msT = 8: 119 ms2.7×
8,192 + 32 floats (padded)1132 msT = 64: 29 ms4.5×
8,192 (power of 2)868 msT = 8: 15 ms4.5×
8,192 + 32 (padded)821 msT = 64: 8.0 ms2.6×

With power-of-two rows, all the lines of one column of B map to the same few cache sets and evict each other. Padding each row by 32 floats made the naive loop 2.5× faster on its own, and changed the best tile from 8 to 64. Tiling and padding together: 11× over the naive loop on one thread. Two lessons: avoid power-of-two strides between things used together, and measure tile sizes rather than derive them.

5.2 Loop fusion: improve temporal locality across operations

Slide 43 computes E = D + (A + B) × C in two ways:

// modular: three library calls (like numpy: E = D + (A + B) * C)
add(n, A, B, tmp1);        // 2 loads, 1 store per math op: intensity 1/3
mul(n, tmp1, C, tmp2);     // 2 loads, 1 store per math op: intensity 1/3
add(n, tmp2, D, E);        // 2 loads, 1 store per math op: intensity 1/3

// fused: one loop
for (int i = 0; i < n; i++)
    E[i] = D[i] + (A[i] + B[i]) * C[i];   // 4 loads, 1 store per 3 math ops: intensity 3/5

The modular code is nicer to write, but every intermediate (tmp1, tmp2) goes out to memory and comes back. Counting whole arrays moved: unfused 3 loops × 3 arrays = 9, fused 5, so the predicted ratio is 9/5 = 1.8× when memory is the limit. 03_locality, Part C:

arraysthreadsunfusedfusedspeedup
64 MiB each (DRAM)15.39 ms2.89 ms1.87×
64 MiB each (DRAM)82.85 ms1.63 ms1.75×
1 MiB each (L2)10.080 ms0.037 ms1.6–2.1× (varies by run)
16 KiB each (L1)1——1.65×

Out of DRAM the traffic model predicts the speedup almost exactly. Fusion also pays inside the caches, where the limit is the number of load and store instructions: 9 per element unfused vs. 5 fused, the same ratio one level closer to the core. This is the whole reason deep learning frameworks fuse operators (Lecture 9). The demo also found the conflict-miss problem again: with all seven 1-MiB arrays starting at the same offset modulo 1 MiB, the fused loop ran ~30% slower than with the arrays shifted by a few hundred bytes.

5.3 Sharing: co-locate tasks that use the same data

Slide 44: exploit sharing. Schedule threads that work on the same data structure at the same time on the same processor, so the data is loaded once and used by both. This reduces inherent communication. Examples: run the tiles of a matrix that read the same rows of A on the cores of one cluster (sharing its L2); in a web server, route requests for the same user to the same machine. The opposite is also worth knowing: two threads that write the same line on different cores create communication (§6.3).


6. Contention

6.1 Office hours

Slide 46 sets up office hours from 3:00 (no appointments): a student walks 5 minutes from the café, waits in line if necessary, and gets a 5-minute answer. The execution resource is the professor. 04_contention.py, Part A, with five students leaving the café a minute apart:

student | leaves | arrives | served    | waits | total cost
      1 |   2:55 |    3:00 | 3:00-3:05 |   0 m |   10 min
      5 |   2:59 |    3:04 | 3:20-3:25 |  16 m |   26 min      (average 18 min)

With appointments (departures staggered by 5 minutes), every student pays exactly 10 minutes. The professor does the same 25 minutes of work either way. Contention (slide 49) occurs when many requests to a resource arrive within a small window of time, making it a hot spot. The resource has a fixed throughput (transactions per unit time), and requests beyond it wait in line. Memory banks, network links, locks, shared counters and receiving processors all behave this way.

6.2 Flat vs. tree-structured communication

Slide 49’s example: many processors update a shared variable, or send a value to one processor.

  • Flat: everyone sends directly to processor 0. One hop, so low latency if there is no contention, but processor 0 must handle P−1 messages one after another.
  • Tree: pairs combine, then pairs of pairs, … log₂P rounds, and no receiver handles more than one message per round. Higher latency under no contention, much less contention.

04_contention.py, Part B models it with latency L = 1 and a receive overhead o = 0.25 per message: flat costs L + (P−1)·o, the tree log₂P·(L + o). The tree wins from P = 32 on; at P = 4,096 it is 68× faster (15 vs. 1,025 time units). Below P = 16 the flat gather is as fast or faster. This is why MPI’s reductions use trees at scale and why our 4-thread solver of §2 used a flat gather.

Slide 50 recalls Lecture 5’s other cure for a contended resource: distributed work queues, where each worker pushes to and pops from its own queue and steals only when idle. Lecture 5 measured a central queue at 270 ms against 30 ms for per-worker deques.

6.3 A shared histogram, measured

05_histogram_contention has 8 threads count 8M random values into bins. Each version is checked against the serial count (times are wall time per value; smaller is better):

data, binsserialatomic, 1 threadshared atomic, 8 threadsshared, 1 bin per lineprivate, packedprivate, own lines
uniform, 10.32 ns1.7833.030.50.260.08
uniform, 160.440.8331.013.70.150.10
uniform, 2560.350.7217.68.50.080.08
uniform, 4,0960.350.729.37.10.080.09
uniform, 65,5360.551.186.85.60.130.13
90% in one bin, 4,0961.841.8335.135.60.260.28

What the table says:

  1. One hot counter: 8 threads sharing it are 103× slower than one thread. Private copies merged at the end are 4.1× faster. Same work, same answer; the difference is contention.
  2. The atomic instruction is cheap; sharing the line is not. One thread doing atomic increments costs 0.72 ns per value, about twice a plain increment. Even with 65,536 bins, which two threads rarely touch at the same moment, the shared version costs 6.8 ns per value (≈ 54 ns per update per thread). To update a counter, a core must own its cache line, and with 8 threads updating every bin, the line is usually in another core’s cache. That is communication between caches (Lecture 14 explains the protocol).
  3. The unit of contention is the cache line. 16 four-byte bins fill half of one 128-byte line and cost about as much as 1 bin; giving each its own line cuts the cost to 13.7 ns. This is false sharing (伪共享): no two threads touch the same bin, but they fight over the same line.
  4. Replication (slide 51) is the cure, and it has to respect lines too. Private histograms packed back to back in one array share lines when they are small. With 1 bin, all 8 counters sit in one line and the “private” version reaches only 1.2× (0.26 ns). On lines of their own: 4.1×.
  5. Contention depends on the data. The same 4,096-bin program is fine on uniform values (9.3 ns) and as bad as one bin (35 ns) when 90% of the values fall in one bin.

6.4 Summary: reducing communication costs

Slide 51 collects the techniques:

  • Reduce overhead at sender and receiver: send fewer, larger messages; coalesce small messages (our solver sends whole rows).
  • Reduce latency: restructure code for locality (application writer); improve the communication architecture (hardware designer).
  • Reduce contention: replicate contended resources (local copies, fine-grained locks); stagger access to them.
  • Increase overlap of communication and computation: asynchronous messages (application writer); pipelining, multi-threading, prefetching, out-of-order execution (hardware). Overlap requires additional concurrency in the application: more independent work than execution units.

7. Understanding the performance of parallel software

7.1 Simplest first, then measure

Slide 53, in bold: always, always, always try the simplest parallel solution first, then measure performance to see where you stand. Slide 54’s strategy: determine whether performance is limited by computation, memory bandwidth (or latency), or synchronization, and establish high watermarks: the best you can do in practice, and how close your implementation is.

7.2 The roofline model

Slide 55 (Williams, Waterman and Patterson, 2009) draws a program as a point: its arithmetic intensity I on the x-axis, its achieved throughput on the y-axis, both on log scales. The machine is a roof:

attainable throughput = min( peak compute, memory bandwidth × I )

The diagonal part is the bandwidth limit: a program there is memory-bound, and its throughput grows with its intensity. The flat part is the compute limit. They meet at the ridge point I* = peak / bandwidth. Slide 56 adds ceilings below the roof: the best throughput without some optimization, such as without SIMD instructions, or without enough parallelism to hide latency. A program under a ceiling must remove that limitation before it can approach the roof.

06_roofline measures the author’s machine and places a family of kernels on it. Kernel intense<K> reads a[i] and b[i], computes x = a·b, does K multiply-adds, and writes c[i]: 12 bytes per element and 1 + 2K (+ a few adds) FLOPs, so K sweeps the intensity from 1/12 to ~43 FLOP/byte. With 8 threads:

peak compute, NEON FMAs  :  672 GFLOP/s       bandwidth, DRAM (64 MiB arrays)  : 206 GB/s
peak compute, scalar FMAs:  194 GFLOP/s       bandwidth, L2 (4 MiB arrays)     : 711 GB/s
ridge point: DRAM 3.3 FLOP/byte, L2 0.95 FLOP/byte
KFLOP/byteNEON, DRAM: GFLOP/s (% of roof)NEON, in L2scalar, DRAM (% of scalar roof)
00.08317.4 (102%)59 (100%)17.5 (102%)
20.50102 (99%)335 (94%)86 (84%)
81.83373 (99%)552 (82%)117 (60%)
163.17509 (78%)620 (92%)136 (70%)
6411.2604 (90%)642 (95%)194 (100%)
25643.2647 (96%)653 (97%)203 (105%)

(Values a few % above 100 reflect run-to-run noise in the measured roofs.)

How to read it:

  • Left of the ridge the kernels sit on the bandwidth roof, and extra arithmetic is free: K = 0 through 8 take about the same time per element. C = A × B (K = 0) has intensity 1/12, about 40× too little for the cores to matter.
  • Near the ridge (K = 16) the kernel reaches 78%: the roofline’s rounded corner, where neither limit is fully hidden behind the other.
  • The roof depends on which memory you count from. With the data in L2 the bandwidth roof is 3.5× higher and the ridge moves to ~1 FLOP/byte. The same kernel can be memory-bound from DRAM and compute-bound from cache. “Bandwidth-bound” is always relative to a level of the hierarchy, which is why blocking (§5.1) works: it moves a kernel’s traffic to a higher roof.
  • Scalar code hits a ceiling 3.5× lower for compute-heavy kernels (slide 56). Memory-bound kernels do not care: at K = 0, scalar and NEON code run at the same speed. Vectorizing a memory-bound loop does not help.

Plan vs reality. The roofline took three attempts, each a lesson in benchmarking:

  1. The “scalar” kernel ran at NEON speed: the compiler’s SLP vectorizer packed 12 independent scalar chains into vectors even with loop vectorization disabled.
  2. Extra accumulators that all started at 0 did identical work, so the compiler computed one and reused it, and K = 32 “ran” at 1.7× the chip’s peak.
  3. Unrolling past 128 bytes per array per iteration cut streaming bandwidth from ~220 to ~170 GB/s, for reasons we could not determine.

A point above the roof means the measurement is wrong. The README has the details.

7.3 Establishing high watermarks

Profilers often cannot say why a program is slow. Slide 57 suggests experiments that each change one thing:

  1. Add math (non-memory instructions). If the time grows linearly with the added operations, the code is instruction-rate limited.
  2. Change all array accesses to A[0]. The speedup is an upper bound on the benefit of improving locality.
  3. Remove all atomic operations or locks (keeping roughly the same work). The speedup is an upper bound on the benefit of reducing synchronization.
  4. Remove almost all math but load the same data. If the time barely decreases, suspect a memory bottleneck.

The footnote matters: computation, memory access and synchronization are almost never perfectly overlapped, so performance is rarely dictated entirely by one of them. The sensitivity to each change still indicates the dominant cost.

07_high_watermarks applies tests 1–3 to a Jacobi stencil (a barrier per sweep, 6 threads) at two sizes:

modificationBIG grid 4096² (DRAM)SMALL grid 256² (in cache)
original910 µs per sweep2.9 µs per sweep
+ 2 multiply-adds per cell1.01× time1.05×
+ 8 multiply-adds per cell1.25×1.63×
+ 32 multiply-adds per cell3.80×5.37×
data kept in cache (each thread reuses 4 of its rows)0.46×0.80×
no barrier between sweeps0.87×0.59×

Same code, opposite diagnoses:

  • Big grid: bandwidth-bound. A little extra math is free, and keeping the data in cache would be 2.2× faster, which is the upper bound on what better locality could buy (e.g. tiling several sweeps together). The barrier matters little.
  • Small grid: synchronization-bound, then compute. Locality has little left to give; removing the barrier gives 1.7×, because a sweep is only 2.9 µs and a barrier among 6 threads costs microseconds.
  • On the big grid, removing the barrier still saves 13%, more than a barrier costs. Without barriers, a thread that falls behind (on the busy core) no longer stalls the others every sweep. Test 3 measures synchronization plus the load imbalance that synchronization exposes.

The tests produce wrong answers. They are measurements, not fixes. Plan vs reality: the literal “change all accesses to A[0]” made the program 2× slower. All threads then wrote the same 16 KiB, fighting over its lines (§6.3), and the masked indices stopped the compiler from vectorizing. A watermark test must change only the thing it tests.

7.4 Profilers and performance counters

Slide 58: an OS “CPU usage” graph only shows whether a thread was scheduled, not whether it was doing useful work; a core stalled on memory looks 100% busy. All modern processors have performance counters: registers that count instructions completed, clock cycles, cache hits and misses at each level, bytes read from the memory controller, and so on. Tools read them: Intel’s Performance Counter Monitor (getIPC, getL3CacheHitRatio, getBytesReadFromMC), VTune, PAPI, Linux perf, and on macOS Instruments’ “CPU Counters”. They turn guesses such as “probably memory-bound” into numbers such as “IPC 0.3, 40 bytes of DRAM traffic per element”.


8. Problem size and scaling

8.1 What makes a design good?

The bonus slides (59–61) put you in charge of designing a company’s next parallel processor. How do you know the design is good? By absolute performance (wall-clock time, operations per second), by speedup due to parallelism, and by efficiency: performance per unit resource, such as per chip area, per dollar or per watt.

Slide 62 warns about the baseline. The grid solver changed the algorithm to allow parallelism (red-black instead of row-order Gauss-Seidel), and the new algorithm may need more iterations. Should speedup be measured against the parallel program on one processor, or against the best sequential program? The common pitfall is to compare with the parallel algorithm on one core, which makes you look good. (Lecture 4 found the opposite surprise on our machine: red-black was 5× faster per sweep than row-order Gauss-Seidel even on one core, because its updates are independent and vectorize.)

8.2 Fixed problem size: strong scaling

Slides 63–65 show the solver on a 32-processor SGI Origin 2000. A 258 × 258 grid gets no benefit beyond a few processors (even a slight slowdown): only ~310 cells per processor at P = 32, so each processor’s work is tiny compared with its communication (slide 64: for 2D blocks the intensity ∝ N/√P, which shrinks as P grows). The 1K × 1K grid (~32K cells per processor) scales well. “The problem size is just too small for the machine.” And perhaps it does not matter: a small problem may already run fast enough on one core.

08_scaling, Part A, on the author’s machine (speedup over 1 thread, same grid):

gridworking set1 thread2468
128 × 1282 × 66 KiB (L1)2.2 µs/sweep1.73×1.73×1.84×0.79×
1024 × 10242 × 4 MiB (one L2)137 µs1.98×3.74×5.27×2.12×
4096 × 40962 × 64 MiB (DRAM)3,157 µs1.89×3.16×3.71×3.32×

The small grid’s sweep takes 2.2 µs on one thread, so barriers and hand-offs dominate. The cache-sized grid scales well. The DRAM-sized grid saturates memory bandwidth (Lecture 3). On 8 threads every grid does worse than on 6, for the reason given in §0.4.

8.3 Super-linear speedup

Slide 66: with enough processors, the chunk of the problem assigned to each processor begins to fit in cache, so each processor’s work gets cheaper and the speedup can exceed P. In the other direction, if the problem does not fit in a small machine’s memory and thrashes to disk, a bigger machine looks amazing.

The stencil did not show it on our machine: a streaming core reads from DRAM almost as fast as from L2 (~42 vs. ~62 GB/s for one thread). Latency-bound work does show it. 08_scaling, Part B does 4M dependent lookups in a 24 MiB table, where thread t chases only through its own 1/P of the table, like a processor that owns 1/P of the data:

Pslice per threadns per lookupspeedup
124 MiB511.00×
212 MiB382.68×
46 MiB1711.8×
64 MiB1422.5×
83 MiB1428.6×

One thread misses its caches on almost every lookup. Once each thread’s slice fits within its cluster’s 16 MiB L2 (and needs fewer address translations), every lookup becomes 3–4× cheaper. Eight cores bring 8 × the work rate and twice the L2 capacity: more processors brought more cache, not just more cores.

8.4 Scaling the problem with the machine: weak scaling

Slide 67 summarizes the interactions between problem size and machine size. Load balance, overhead, arithmetic intensity and locality all change, often dramatically and in application-dependent ways. Evaluating a machine with a fixed problem size can mislead in both directions:

  • too small a problem: parallel overheads dominate and may even cause slowdowns; a size appropriate for small machines does not reflect realistic use of a large one;
  • too large a problem (chosen for the large machine): the key working set may not fit in the small machine (thrashing, or not running at all), and super-linear speedups appear.

So it can be desirable to scale the problem size as machines grow: buy a bigger machine to compute more, not to compute the same problem faster. The two standard measurements:

  • Strong scaling: fixed total problem; time vs. P (§8.2).
  • Weak scaling: fixed problem per processor, total size ∝ P; ideally the time stays constant.

08_scaling, Part C grows the grid with P (~P × 768² cells):

Pgridµs per sweepefficiency T(1)/T(P)
1768²761.00
21086²780.98
41536²1550.49
61881²950.80
82172²2460.31

On one chip, weak scaling is not free. Each thread brings 4.7 MiB of data but no new cache and no new memory bandwidth, so the total working set outgrows the caches (4 threads: 19 MiB, more than one cluster’s 16 MiB L2) and all threads share one memory system. Four threads doing worse than six suggests the OS placed all four in one cluster (16 MiB of L2 for 19 MiB of data) and spread six over both. We cannot observe thread placement, so this is a guess that fits the numbers. On a cluster of machines each node brings its own memory and bandwidth, which is why weak scaling is the natural yardstick there.

Slide 68’s summary of tips: measure, measure, measure; establish high watermarks (compute-, synchronization- or bandwidth-bound?); and be aware of scaling issues: is the problem well sized for the machine?


Summary

  • A shared address space is an abstraction built from caches, interconnects (rings, crossbars) and memory controllers. Its cost is non-uniform: where data lives decides how fast you get it (NUMA, even on one chip).
  • Message passing makes communication explicit: private address spaces, ghost rows, bulk messages. Synchronous sends can deadlock through cycles of waits; order the operations (even/odd) or use asynchronous sends, which also let you overlap communication with independent computation (20-µs network: 0.394 → 0.213 ms per sweep).
  • Think of the whole system as an extended memory hierarchy: communication is any data movement, at every level.
  • Arithmetic intensity (computation per byte communicated) decides whether a program is bandwidth- or compute-bound. On the author’s machine the DRAM ridge point is ~3.3 FLOP per byte.
  • Inherent communication depends on the algorithm and the assignment (2D blocks beat 1D rows: perimeter vs. area). Artifactual communication comes from the system: whole-line transfers (29× wasted at one float per line), capacity misses (3 lines per 4 outputs), write-allocate (absent on the M4) and conflict misses (power-of-two strides).
  • Cures: better assignment; blocking/tiling (a transpose 11× faster with tiling + padding); loop fusion (1.8×, as the traffic model predicts); co-locating tasks that share data.
  • Contention comes from requests arriving at one resource within a short window. Replicate (private histograms 4.1× faster vs. 103× slower shared), stagger, or use trees. The unit of contention in a cache-coherent machine is the cache line.
  • Roofline: attainable = min(peak, bandwidth × intensity), with ceilings for missing optimizations. High watermarks: add math, localize data, remove sync, and see what changes.
  • Problem size changes everything: small problems do not scale (strong scaling); per-processor working sets that fit in cache give super-linear speedup (28.6× on 8 threads); weak scaling asks whether a bigger machine solves a bigger problem in the same time.

Common pitfalls

  • Relying on MPI buffering to escape a send/send cycle. It works for small messages and deadlocks when they grow.
  • Expecting overlap without independent work. Asynchronous sends hide latency only behind computation that does not need the incoming data (the diff reduction stayed exposed).
  • Counting only the bytes a program “uses”. Memory moves whole lines; an access pattern that uses 4 bytes per line pays for 128.
  • Choosing tile sizes by arithmetic on capacities alone. Partial lines at tile edges, set conflicts and power-of-two strides decide as much as capacity. Measure.
  • Writing a waiting loop that hammers the lock its partner needs (our message library), or packing “private” per-thread data into one cache line (our histogram). Both create contention where none was intended.
  • Reading a high CPU-usage graph as “busy computing”. A core stalled on memory is 100% “busy”.
  • A benchmark point above the roofline. It means the compiler removed work or the roofs were mismeasured, not that you beat the hardware.
  • Quoting speedups for one problem size. Small problems understate a machine; problems that fit in many caches but not one overstate it.

Exercises

  1. Deadlock. Four threads in a ring: thread t sends to (t+1) mod 4 and receives from (t−1) mod 4, all with synchronous sends. Does even/odd ordering fix the deadlock? What about 5 threads?

    AnswerWith 4 threads, yes. Each even thread sends to an odd thread that is already receiving, and then the roles swap. With 5 threads, threads 4 and 0 are both even, so thread 4's send waits for thread 0, which is busy sending to thread 1. But thread 1 is odd and receiving, so thread 0's send completes; thread 0 then receives from thread 4, and everything unwinds: no deadlock either. A deadlock needs a cycle in which *every* thread waits for one that is also waiting, and the odd threads, which receive first, break every such cycle. Reasoning like this gets fragile as patterns grow, which is why libraries offer a combined send-receive (MPI_Sendrecv) or asynchronous sends.
  2. Overlap budget. In demo 01’s overlap version, a sweep takes ~0.18 ms on 4 threads. Up to roughly what network latency can overlap hide the ghost-row exchange completely?

    AnswerA sweep has two phases, so one phase takes ~90 µs per thread, almost all of it in the interior rows. The boundary rows are sent at the start of the phase, so they arrive in time if the latency is below ≈ 90 µs. Our 20-µs network was well inside that budget, which is why overlap hid it completely and only the reduction's two latencies remained. The budget shrinks as P grows (less interior work per thread), which is one more reason small problems scale badly (§8).
  3. Assignment arithmetic. An N × N grid with N = 4,096 on P = 64 processors. Compute cells per processor, cells received per sweep and intensity for 1D blocked rows and for 2D blocks.

    AnswerCells per processor: 4096² / 64 = 262,144 in both cases. 1D blocked: receives 2 rows = 8,192 cells, intensity 32. 2D blocks: an 8 × 8 arrangement of 512 × 512 blocks; an interior block receives 4 × 512 = 2,048 cells, intensity 128. The 2D assignment communicates 4× less.
  4. Fusion. A chain of k element-wise operations on arrays of n floats, each reading two arrays and writing one, unfused vs. fused into one loop that reads k + 1 inputs and writes one output. What is the predicted speedup for large k when memory-bound?

    AnswerUnfused: k loops × 3 arrays = 3k arrays moved. Fused: (k + 1) + 1 = k + 2. The ratio 3k / (k + 2) approaches 3 as k grows (for k = 3: 9/5 = 1.8, as in slide 43). If the intermediate values were reused by later operations instead of each loop reading a fresh input, fusion could save even more: the fused loop would read only the original inputs.
  5. Roofline. A GPU has 60 TFLOP/s and 3 TB/s of memory bandwidth. Where is its ridge point? What fraction of peak can a kernel with intensity 1/4 FLOP/byte reach, and how much intensity does a kernel need to reach 90% of peak?

    AnswerRidge = 60 / 3 = 20 FLOP/byte. At I = 1/4 the bound is 3 TB/s × 0.25 = 0.75 TFLOP/s, 1.25% of peak. Reaching 90% of peak requires bandwidth × I ≥ 54 TFLOP/s, i.e. I ≥ 18 FLOP/byte; in practice somewhat more, because of the rounded corner.
  6. Contention. In demo 05’s 65,536-bin case, 8 threads take 6.8 ns per value. Assume each update needs the line to move from another core with probability 7/8 and that such a transfer takes T ns, while other updates are free. Estimate T.

    AnswerPer thread, an update takes 6.8 × 8 ≈ 54 ns of wall time. With 7/8 of updates paying T: T ≈ 54 / (7/8) ≈ 62 ns. That is the order of a cross-core (and often cross-cluster) cache-to-cache transfer. Lecture 14 shows what the protocol does during that time.
  7. Weak vs. strong. A program has a serial part of 1 s and a parallel part of 99 s on one processor. Compute the speedup on 100 processors under strong scaling, and under weak scaling where the parallel part grows to 99 × 100 s (Gustafson’s view) while the serial part stays 1 s.

    AnswerStrong (Amdahl): 100 / (1 + 0.99) ≈ 50×. Weak: the scaled problem would take 1 + 9,900 = 9,901 s on one processor and 1 + 99 = 100 s on 100 processors, a "scaled speedup" of 99×. The serial part matters much less when the problem grows with the machine, which is the argument for weak scaling.

Programming Assignment 1 (Lectures 1–5) already contains a bandwidth-bound program: you are asked to explain why one of its kernels hardly speeds up with more cores. Its explanation is §3.3 and §7.2 of this lecture. PA3 (CUDA, Lectures 7–8) and PA4 (Trainium, Lectures 9–11) are largely exercises in this lecture’s ideas: tiling into on-chip memories, fusing operations to avoid round trips to DRAM, and reasoning about arithmetic intensity. These notes do not give assignment solutions; the demos use different workloads.

Further reading

  • The Fall 2025 slides for this lecture and the 2023 lecture video.
  • D. Culler, J. P. Singh and A. Gupta, Parallel Computer Architecture: A Hardware/Software Approach, Morgan Kaufmann, 1999. Chapters 2–3: the grid solver in three programming models; inherent vs. artifactual communication; the Origin 2000 measurements of slides 63–66.
  • S. Williams, A. Waterman and D. Patterson, “Roofline: An Insightful Visual Performance Model for Multicore Architectures”, CACM 52(4), 2009.
  • J. L. Gustafson, “Reevaluating Amdahl’s Law”, CACM 31(5), 1988. The case for scaled (weak) speedup.
  • U. Drepper, “What Every Programmer Should Know About Memory”, 2007. Cache organization, associativity and conflict misses, prefetching, write-combining.
  • The MPI standard (mpi-forum.org), especially the communication modes (standard, buffered, synchronous, ready) and non-blocking operations.

Preview of Lecture 7 — GPU architecture and CUDA

Next lecture moves to the machine that is built around today’s ideas. A GPU has thousands of execution contexts to hide latency, very high memory bandwidth, and a small, fast, programmer-managed shared memory in each core for exactly the kind of data reuse that blocking creates. The demos will run CUDA-style kernels on a simulator that counts memory traffic and on the author’s Apple GPU through Metal. The first kernel, a 1D convolution, gets faster for the reason §5 gave: it loads its inputs into shared memory once instead of three times.


术语表 (Glossary, English → 中文)

English中文
communication通信(任何数据搬运)
shared address space共享地址空间
interconnect: ring / crossbar互连:环 / 交叉开关
NUMA (non-uniform memory access)非一致内存访问
message passing消息传递
private address space私有地址空间
send / receive, message tag发送 / 接收,消息标签
ghost cells / ghost rows幽灵单元 / 幽灵行(从他处复制的边界数据)
data replication数据复制
synchronous (blocking) send同步(阻塞)发送
asynchronous (non-blocking) send异步(非阻塞)发送
acknowledgement确认
deadlock / cycle of waits死锁 / 循环等待
overlap of communication and computation通信与计算重叠
extended memory hierarchy扩展的存储层次
arithmetic intensity算术强度
communication-to-computation ratio通信计算比
inherent communication固有通信
artifactual communication人为通信(由系统实现细节引起)
minimum transfer granularity最小传输粒度
write-allocate写分配
capacity miss / conflict miss容量不命中 / 冲突不命中
set-associative cache组相联缓存
padding (leading dimension)填充(行跨度)
blocking / tiling分块
loop fusion循环融合
temporal / spatial locality时间 / 空间局部性
contention / hot spot争用 / 热点
replication / staggering复制 / 错开访问
flat vs. tree-structured communication扁平通信 vs. 树形通信
false sharing伪共享
roofline model / ridge point / ceiling屋顶线模型 / 拐点 / 天花板(上限)
compute-bound / bandwidth-bound计算受限 / 带宽受限
high watermark高水位线(性能上限估计)
performance counters性能计数器
strong scaling / weak scaling强扩展 / 弱扩展
super-linear speedup超线性加速
working set工作集
← 返回课程目录