One Node, Four Ways to Cut It
A node has 96 cores. You can run them as 96 MPI ranks, as one rank with 96 threads, or as something in between. Which one? One method, four steps, one example all the way through: a halo sweep on one Cardinal node. You will run the steps on it, then on cases of your own.
Concept map
One idea, one worked example, then your turn. Every solid box is a section of this page.
Four layouts of the same 96 cores
A Cardinal node has two sockets of 48 usable cores each. A layout is a choice of how many ranks and how many threads per rank: ranks × threads = 96.
| Word | What it means here |
|---|---|
| rank | one MPI process. It has its own private memory; its threads share that memory. |
| thread | one OpenMP worker inside a rank. It runs on one core at a time. |
| socket | one processor chip and the memory attached to it. A node has two, 48 cores each. |
On one node the four layouts are 96 × 1 (pure MPI: every core is a rank), 8 × 12 (four ranks on each socket, OSC's own hybrid example), 2 × 48 (one rank per socket) and 1 × 96 (pure OpenMP: one process, threads on both sockets). Nobody in the course has run the middle two yet.
Pick a layout. One square is one core; one colour is one rank. For 96 × 1 the eight colours repeat. The bars under each socket show where the 6.4 GB the sweep reads and writes would live (model; the arithmetic is in the Step 3 section).
The method: how should one node be cut?
Four steps. A sweep is one update of every interior cell of the grid from its four neighbours.
List the layouts.
Ranks × threads = cores. On one node: 96 × 1, 8 × 12, 2 × 48, 1 × 96.
Count what each one pays.
Copies of shared data, messages per sweep, and where the memory lives.
Put numbers on it.
Bytes moved ÷ memory speed. Messages × cost per message.
Check.
Print where every thread is running. Then time it.
Same shape as the GPU lecture (count, time, add up, check), with a different road.
Steps 1 and 2: messages and memory
The example from here to the end of step 4: a Jacobi sweep on a 20,000 × 20,000 grid of doubles (8-byte numbers), 100 sweeps, one Cardinal node. The program call is ./Hybrid halo 20000 100. In the code, n is the grid's side, 20,000, so there are 4 × 108 cells.
The grid is cut into strips of whole rows, one strip per rank (Week 7). Each rank's rows are then shared out across its threads (Week 9). A halo row is a copy of the neighbour's edge row, which a strip needs to update its own edge row. Each boundary between two strips costs two messages, one halo row each way: 2 × (ranks − 1) messages per sweep.
| Layout | Strips, one per rank | Halo messages per sweep | Where the memory lives |
|---|---|---|---|
| 96 × 1 | 96 | 190 | each rank's own pages, on its own socket |
| 8 × 12 | 8 | 14 | on its own socket, if each rank stays on one socket |
| 2 × 48 | 2 | 2 | one rank per socket: on its own socket by construction |
| 1 × 96 | 1 | 0 | on whichever socket the first thread to write each page sat on |
Eight strips have 7 boundaries between neighbours. Each boundary carries a row each way: 2 × (8 − 1) = 14. The same formula gives 190 for 96 ranks, 2 for two ranks and 0 for one rank.
First touch is the rule behind the last column. Memory is handed out in pages (4 KB blocks). Linux puts a page on the socket of the thread that wrote it first. A rank that stays on one socket and fills its own rows keeps them local. A single process spanning both sockets (1 × 96) gets whatever the filling threads' sockets decide.
A page goes to the socket of the thread that wrote it first. Reading does not move it. That is why who fills the arrays matters, and why the next section looks at the fill loop.
How many memory domains a Cardinal dense node shows is not documented, so the job script records lscpu and numactl -H into results/node_numa.txt. On the node the Nov 23 run used, it lists two sockets and 16 NUMA nodes (a NUMA node is one memory domain): 8 of them have cores attached, 4 per socket, and 8 have none. The model above treats each socket as one domain.
Strips across ranks, rows across threads
Branch lecture14, hybrid/src/main.cpp, method halo. Abridged with "..." only. L is the number of rows this rank holds: its own rows plus one halo row above and one below. rows is the rows it updates.
MPI_Init_thread(&argc, &argv, MPI_THREAD_FUNNELED, &provided); ... #pragma omp parallel for schedule(static) // same schedule as the sweep below for (long k = 0; k < L; k++) { initRow(a, k); initRow(b, k); } ... for (int it = 0; it < iters; it++) { // Master thread only, outside any parallel region: FUNNELED is enough. MPI_Sendrecv(&a[1 * n], (int)n, MPI_DOUBLE, up, 0, &a[(L - 1) * n], (int)n, MPI_DOUBLE, down, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); MPI_Sendrecv(&a[(L - 2) * n], (int)n, MPI_DOUBLE, down, 1, &a[0], (int)n, MPI_DOUBLE, up, 1, MPI_COMM_WORLD, MPI_STATUS_IGNORE); #pragma omp parallel for schedule(static) for (long k = 1; k <= rows; k++) { for (long j = 1; j < n - 1; j++) { b[k * n + j] = 0.25 * (a[(k - 1) * n + j] + a[(k + 1) * n + j] + a[k * n + j - 1] + a[k * n + j + 1]); } } ... }
| Piece | What it does |
|---|---|
the two MPI_Sendrecv calls | my first row goes up while my bottom halo row fills from below; then the mirror image. up and down are MPI_PROC_NULL at the two ends, so there is no special edge code (Week 7) |
the parallel for sweep | the master thread forks the team and the rank's rows are split across the threads |
MPI_THREAD_FUNNELED | tells MPI that threads exist and only the master thread will call it. The two Sendrecv calls sit outside the parallel region, so that is enough |
| the fill loop at the top | sets first touch: each thread fills the rows it will later update |
FUNNELED promises exactly this: threads exist, and only the master thread calls MPI. main.cpp asks for it and aborts if the library offers less. The cost: while the master thread exchanges halos, the other threads wait, a short serial section inside every sweep.
The fill loop and first touch
--serial-touch runs the same fill from one thread, with no pragma. The array comes from new[], which leaves the pages untouched; the first write decides which socket holds each page. Here 16 pages stand for the array (the real array has far more); pages 0 to 7 are filled by threads on socket 0 and pages 8 to 15 by threads on socket 1.
#pragma omp parallel for from the fill loop in a 1 × 96 run and change nothing else. What changes?The answer is the same and the sweep is still parallel. Only the page placement changed: the one filling thread sat on one socket, so every page is behind that socket. This is the most common way 1 × 96 is written, because the natural initialisation loop is serial. The Step 3 section puts a number on it (a model).
The program checks itself: every rank compares its rows bit for bit against a serial Jacobi when n is at most 2,048, and prints CHECK halo ok. It prints T_COMM and T_COMP (the largest over all ranks): the time spent in messages and the time spent computing.
Predict: which layout loses?
Before step 3. Numbers to use: one sweep reads one array and writes another, 6.4 GB. One socket's memory delivered 247 GB/s when we measured it on Cardinal, Nov 23. A halo message is one row: 160,000 bytes. A message costs 2 µs, plus 0.05 ns for every byte. 1 × 96 has two versions: every thread fills its own rows first, or one thread fills every array first.
In the model, the four layouts whose pages sit on their own sockets tie at about 13 ms per sweep, and the serial-fill 1 × 96 takes 26 ms or worse. Messages are about 20 µs per sweep, a tiny share of either. Most people rank by message count: 96 × 1 slowest (190 messages), 1 × 96 fastest (none). The next section is the arithmetic that breaks that intuition.
Step 3: memory decides
A model, from one measured speed. A sweep reads array a and writes array b: 8 + 8 = 16 bytes per cell, the four neighbours coming from cache. 16 B × 4 × 108 cells = 6.4 GB.
| Case | Bytes | At this speed | Time per sweep (model) |
|---|---|---|---|
| Memory, every thread's pages on its own socket: 96 × 1, 8 × 12, 2 × 48, and 1 × 96 filled in parallel | 16 B × 4 × 108 cells = 6.4 GB | 494 GB/s (two sockets) | 13 ms |
| Memory, 1 × 96 filled by one thread: every page behind socket 0 | 6.4 GB | 247 GB/s (one socket) | 26 ms, or worse |
| Messages: two per sweep, one row each | 8 B × 20,000 = 160,000 B per message | 2 µs + 160,000 B × 0.05 ns = 10 µs each | 20 µs, which is 0.15% of 13 ms |
The one measured input: 247 GB/s is one socket's memory speed, measured on Cardinal on Mon Nov 23 (1.2 GB in 4.85 ms, 48 threads, minimum of five), on the CPU of a GPU node (Xeon Platinum 8470), not on the dense node this lecture uses (Xeon CPU Max 9470), whose memory mode is not documented. Doubling it to 494 GB/s for two sockets is the model's assumption, not a measurement. The hybrid run on Cardinal (the "time all five" section) tests that assumption. "Or worse" because the 48 threads on socket 1 also reach across the link to socket 0's memory.
2 × 10 µs = 20 µs. 13 ms = 13,000 µs. 20 ÷ 12,960 = 0.15%. The ranks exchange at the same time, so a node pays about 20 µs per sweep wherever there are at least two ranks. The real T_COMM also includes waiting for a slower neighbour, so expect more than 20 µs.
What does one message cost, and how does it compare with the sweep? Change the grid side n. One halo message is one row of n doubles (8 bytes each); a sweep moves 16 × n × n bytes at 494 GB/s. All of it is the model.
Step 4: check where every thread runs
Before any stopwatch. For hybrid, the first check is not a time: it is the core each thread is on. The layout method prints it (it calls sched_getcpu in every thread). Real output from the course's test machine: 2 cores, Open MPI 4.1.6. It is not a Cardinal timing.
$ export OMP_NUM_THREADS=2 $ mpiexec -n 1 ./Hybrid layout rank 0 vm 2 threads cores 0 0 $ mpiexec -n 1 --bind-to none ./Hybrid layout rank 0 vm 2 threads cores 0 1 ./Hybrid pi 4e7, min of 5: default binding 1.47 s --bind-to none 0.91 s
The last numbers on a layout line are the core each thread runs on.
cores 0 0. The program printed no error and pi gave the right answer. What does it mean? Open MPI pins a rank to one core by default at small rank counts, and its threads inherit the pin. Both threads share core 0. With --bind-to none they get cores 0 and 1, and the same pi 4e7 run drops from 1.47 s to 0.91 s. This is the most common hybrid bug, and it prints no error.
One caveat from rerunning it: with --bind-to none alone, threads may migrate, so a single snapshot can still show 0 0. Adding OMP_PROC_BIND=close OMP_PLACES=cores showed 0 1 every time, which is why the Cardinal job script sets both. A rerun of the timing on the same machine gave about 1.0 s against 0.5 s: the ratio, not the seconds, is the point.
The same check on Cardinal
Real output, Cardinal, Mon Nov 23 (job 17107700, one exclusive node, MVAPICH 4.1, srun -c … --cpu-bind=cores). The first lines of each layout file, with the long core lists cut off by the program itself:
--- layout_8x12 rank 0 c0249.ten.osc.edu 12 threads cores 0 24 72 8 32 48 16 56 80 40 64 88 rank 1 c0249.ten.osc.edu 12 threads cores 74 18 2 50 34 10 82 58 26 90 66 42 --- layout_2x48 rank 0 c0249.ten.osc.edu 48 threads cores 0 24 72 8 32 48 16 56 80 40 64 88 44 68 92 28 ... rank 1 c0249.ten.osc.edu 48 threads cores 1 25 73 9 33 49 17 57 81 41 65 89 45 69 93 29 ... --- layout_1x96 rank 0 c0249.ten.osc.edu 96 threads cores 0 24 72 8 32 48 16 56 80 40 64 88 44 68 92 28 ...
In all four layouts every thread was on its own core, so the numbers in the next section are not the two-threads-one-core bug. The 2 × 48 lines show something else worth reading: rank 0 sits on even-numbered cores and rank 1 on odd-numbered cores. On this node socket 0 is numbered even and socket 1 odd, so that is one rank per socket, as intended.
srun places and binds: pass -c (srun does not inherit --cpus-per-task from sbatch) and --cpu-bind=cores. Run layout before you time anything. The test machine above is the example of what this check catches; it is not Cardinal.Step 4: time all five
The model meets the run. Five timings on one exclusive Cardinal node: the four layouts with every thread filling its own rows, and 1 × 96 with one-thread fill. The program prints ELAPSED for the 100 sweeps; divide by 100 for the per-sweep time (minimum of five trials).
The numbers on Step 2 were 190, 14, 2 and 0 messages, and in the model every one of them cost the node about 20 µs, 0.15% of a sweep. A tie is a result. If they do not tie, the disagreement names a broken assumption: the doubling to 494 GB/s, the memory mode, the thread binding, the 24 bytes per cell if the cache reads before it writes, or page migration. Read results/node_numa.txt before explaining any surprise. The table below shows which way the Cardinal run came out.
One more number the program prints: the time in messages
The model said the two halo exchanges cost about 20 µs per sweep, counting the copy alone. The program prints T_COMM: the slowest rank's time in the two exchanges per sweep, which includes waiting for a neighbour that is not ready. Real values from the Nov 23 run, in microseconds per sweep:
| Layout | T_COMM per sweep, five trials | Total time per sweep |
|---|---|---|
| 96 × 1 | about 2,400 µs (2,380 to 2,450) | 14.68 ms |
| 8 × 12 | 475 to 517 µs in four trials; one trial 11,300 µs | 14.55 ms |
| 2 × 48 | 122 to 250 µs | 14.63 ms |
| 1 × 96 | about 0.4 µs (no exchange) | 14.51 ms |
The 11,300 µs trial is the same 8 × 12 trial that took 2.53 s for 100 sweeps instead of about 1.46 s; the minimum of five ignores it, which is the reason for taking the minimum.
The layout is a few Slurm lines
For the record, and for later. This is the 8 × 12 job. The rest of the page does not depend on it, so nobody needs to copy it now.
#SBATCH --nodes=1 #SBATCH --ntasks-per-node=8 # ranks #SBATCH --cpus-per-task=12 # threads per rank module load mvapich/4.1 export OMP_NUM_THREADS=$SLURM_CPUS_PER_TASK export OMP_PROC_BIND=close export OMP_PLACES=cores srun -c $SLURM_CPUS_PER_TASK --cpu-bind=cores \ ./Hybrid halo 20000 100
| Layout | ntasks-per-node | cpus-per-task |
|---|---|---|
| 96 × 1 | 96 | 1 |
| 8 × 12 | 8 | 12 |
| 2 × 48 | 2 | 48 |
| 1 × 96 | 1 | 96 |
Ranks × threads = 96 on every row. OMP_PROC_BIND=close with OMP_PLACES=cores pins each thread to one of its rank's cores. --cpu-bind=cores pins each rank to its cores. 2 × 48 lands one rank per socket only if the cores are numbered socket by socket and tasks are placed in blocks; check it with ./Hybrid layout, where rank 0 should report cores 0 to 47.
OMP_NUM_THREADS be set? Never type the thread count twice. Take it from --cpus-per-task and the two cannot disagree. Typing 96 here would put 96 threads in each of 8 ranks: 768 threads on 96 cores.
The real hybrid/jobScript.slurm differs from this in one way: it holds one exclusive allocation and runs all four layouts as separate srun steps, with OMP_NUM_THREADS set to that step's thread count. Use the form above for a job that is only one layout. The -c is repeated on every srun for the reason above.
Which layout, and why?
You try it. Each case changes one thing. All numbers are the model. Pick a layout, name the cost it avoids, and put a number on it. Work each one out on paper before you choose. Cases A and B are beyond one node and have not been run on Cardinal: they stay models. Case C was run on one node, and its reveal says what came out.
Each rank has its own private memory, so each rank holds its own copy. 96 × 1: 1,536 copies × 1 GB = 1,536 GB, which is 96 GB on each node. 2 × 48: 32 copies = 32 GB, which is 2 GB on each node. The 48 threads in a rank share one copy. Verdict: fewer ranks, 2 × 48.
20,000 ÷ 1,536 = 13 rows each (the program splits the 19,998 interior rows, so some strips have 13 and some 14): 2 borrowed rows for every 13 of work, about 15%. 20,000 ÷ 32 = 625 rows each: 2 for every 625, 0.3%. The message is one row either way, so the time per message is the same 10 µs. What changes is how much borrowing sits behind each unit of work, and how many ranks there are. A thin strip borrows a lot, a thick one barely notices. Blocks instead of strips (each rank owns a square piece) shorten the borrowed edge, which is why the Week 7 answer for many ranks is blocks.
Cases A and B as a calculator (model). Choose a number of nodes and a layout per node. The defaults are the deck's: 16 nodes, a 1 GB table, n = 20,000.
Serial fill: 6.4 GB ÷ 247 GB/s = 26 ms. Parallel fill: 6.4 GB ÷ 494 GB/s = 13 ms. The layout is fixed; the memory is in the wrong place, not the layout. Use the same parallel for with the same schedule(static) as the sweep, so each thread fills the rows it will update. It is the same idea as false sharing and first touch on Nov 9.
On Cardinal (Nov 23, measured): one-thread fill took 27.37 ms per sweep against 14.51 ms for parallel fill, 1.9 times slower. The model said 26 and 13.
Threads share an address space, and an address space lives in one node's memory. A second node is a second memory, with its own sockets and its own pages. The only way a byte gets from one node to the other is a message, so there must be at least one rank on each node. The fewest-ranks layout for 192 cores on two nodes is 2 × 96. On the list too: 4 × 48 (two ranks per node) and 8 × 24 (four per node). Not on the list: 1 × 192.
This is the case where the method's answer is "it does not apply". Step 1 lists layouts inside one memory. Step 2's counts (copies, messages, where the memory lives) have nothing to say about a layout that cannot be built. Across nodes, MPI is not a choice.
Try it: 192 cores on two nodes. Choose how many ranks in total.
Seven ideas, three machines
The payoff table, complete. Do not read it down. Cover the last column and say the idea underneath for two rows of your choice.
| Concept | Threads | Ranks | GPU | The idea underneath |
|---|---|---|---|---|
| Decomposition | schedule clause | Scatter | grid / block / thread | someone decides who owns which data |
| Granularity | task cutoff | message size (where the per-message cost stops mattering) | work per launch | overhead per unit sets a floor on unit size |
| Dependence | loop-carried; races | send/recv order | blocks never wait for each other | A must precede B: silent or loud |
| Synchronization | critical, atomic | barrier | __syncthreads (one block) | serialization you pay for |
| Locality | false sharing; first touch | pack / derived types | neighbours touch neighbours; data kept on the GPU | make the bytes you move contiguous |
| Communication | coherence traffic | messages | the trip between memories | data movement you did not write still costs |
| Load balance | schedule(dynamic) | manager–worker | the last wave of blocks | an idle processor is the same waste |
Every layout on this page moved cost from one column to another. 96 × 1 pays in the Ranks column: messages, copies, borrowed rows. 1 × 96 pays in the Threads column: first touch, coherence. Hybrid is choosing, row by row, which column pays.
Locality, Threads column: first touch. The same parallel for and the same schedule(static) sweep ran on both versions. What differed was where the bytes lived, and the idea underneath is to keep the bytes where the code that uses them runs. It sent no messages at all.
Keep this
What you can ask of any parallel program you meet after this course:
- Where do the bytes live?
- What does it cost to move them?
- Who is idle, and why?
- Would the mechanism you named actually produce these numbers?
Run it on Cardinal
Run the hybrid job yourself. Branch lecture14, folder hybrid/. One exclusive node for up to 20 minutes; most of it is waiting in the queue. The instructor ran it on Mon Nov 23 (job 17107700, MVAPICH 4.1); the "What you should see" blocks below are that run. Predict first, then compare with yours.
-
The lecture branch
git clone -o class git@gitlab.com:cs4540-spring-2019/cs-4170-5170-fall-2026/openmp.git openmpif you have not cloned yet, then:ssh <your-username>@cardinal.osc.edu cd openmp git fetch class git checkout -b lecture14 class/fa2026-openmp/lecture14
-
Predict first
Write down, before you submit: the time per sweep for each of the five runs, and which one loses. Say whether you used the model's 13 ms and 26 ms or your own reasoning.
Experiments
A · Build and run all five
The job script loads mvapich/4.1, builds, records the node's memory layout, and runs layout, a small checked halo and five trials of halo 20000 100 for each layout, then five trials of the serial-fill run.
cd ~/openmp/hybrid module load mvapich/4.1 make sbatch jobScript.slurm squeue -u $USER
When the job has left the queue, read the layout files first. Do not trust any time until every thread of a rank reports its own core:
cd ~/openmp/hybrid grep -H "cores" results/layout_*.txt | head cat results/node_numa.txt
What you should see
One line per rank, with a different core number for each thread of that rank. Nov 23, first lines of layout_2x48.txt:
rank 0 c0249.ten.osc.edu 48 threads cores 0 24 72 8 32 48 16 56 80 40 64 88 44 68 92 28 ... rank 1 c0249.ten.osc.edu 48 threads cores 1 25 73 9 33 49 17 57 81 41 65 89 45 69 93 29 ...
Every thread on its own core, in all four layouts. Rank 0 on even cores, rank 1 on odd: on that node, one socket each. If every thread of a rank reports the same core, the binding is wrong and the times mean nothing about threads; the job script has a line to uncomment and rerun (MVP_ENABLE_AFFINITY=0). node_numa.txt on Nov 23 listed two sockets and 16 NUMA nodes, 8 with cores and 8 without. Read it before explaining any surprise.
B · Correctness, then the five times
cd ~/openmp/hybrid
grep -H CHECK results/*.txt | sort | uniq -c
for f in results/halo*.txt; do echo $f $(grep ELAPSED $f | awk '{print $2}' | sort -g | head -1); done
grep -m1 T_COMM results/halo_*.txtWhat you should see
Every CHECK line says ok (the small run is bit-for-bit checked against a serial one; the n = 20,000 runs print CHECK halo skipped, because there is no serial reference that large). The ELAPSED value is seconds for 100 sweeps: divide by 100 for the per-sweep time. Nov 23, five trials each:
halo_96x1: 1.46779 1.4677 1.46777 1.46768 1.46757 halo_8x12: 1.45612 1.45829 1.45921 1.45473 2.53379 halo_2x48: 1.47136 1.4634 1.46402 1.4715 1.47095 halo_1x96: 1.45143 1.45354 1.45574 1.45058 1.45438 halo_serialtouch_1x96: 2.73793 2.74261 2.73675 2.74787 2.73884
Minimum of five, divided by 100: 14.68, 14.55, 14.63 and 14.51 ms for the four parallel-fill layouts, and 27.37 ms for one-thread fill (1.9 times slower). The model said 13 ms and 26 ms or worse. One 8 × 12 trial took 2.53 s: that is why you take the minimum. T_COMM (the slowest rank's time in the two exchanges, waiting included) was about 0.4 µs for 1 × 96, 122 to 250 µs for 2 × 48, about 500 µs for 8 × 12 and about 2,400 µs for 96 × 1 per sweep, against the model's 20 µs for the copy alone. Yours will differ a little. If the layouts do not tie for you, name the assumption that broke.
C · Two threads, one core, on a machine of your own
On a laptop with Open MPI, not on a Cardinal login node. Do not time anything on a login node.
cd hybrid && make export OMP_NUM_THREADS=2 mpiexec -n 1 ./Hybrid layout mpiexec -n 1 --bind-to none ./Hybrid layout for i in 1 2 3 4 5; do mpiexec -n 1 ./Hybrid pi 4e7 | grep ELAPSED; done for i in 1 2 3 4 5; do mpiexec -n 1 --bind-to none ./Hybrid pi 4e7 | grep ELAPSED; done
What you should see
On the course's test machine (2 cores, Open MPI 4.1.6): the first layout reports cores 0 0, the second cores 0 1, and the minimum of five pi 4e7 runs is 1.47 s against 0.91 s. Yours will differ with your machine; on a machine with more cores and a different launcher the first run may not show 0 0. That is a result to explain.
layout output. Hybrid is not faster by nature: it changes which rows of the payoff table you pay for.Check yourself
Six questions, instant feedback, nothing recorded.
./Hybrid layout reports cores 0 0 for a rank with two threads. What should you do?layout before you time.