Our first real code. These are C + OpenMP programs plus one browser demo. The
.c files can't run inside a browser — open them to view the code,
then run them via OnlineGDB or a local compiler (see "How to run" below).
Watch one master thread fork into a team of workers during a parallel region, then join back to one. The mental model behind every OpenMP program. Runs in-browser — show it live.
Your first parallel program. Add one #pragma and every thread says hello. The print order is non-deterministic — the first "aha".
Sum a 100-million-element array with parallel for reduction(+:sum). Correct and fast, every single run.
The same sum with the reduction removed. Run it several times and watch the wrong answer change — a live data race. Fixed by example 2.
The .c files need an OpenMP compiler. Easiest in class: paste into OnlineGDB (language C) and press Run — OpenMP is already on, zero install.
Locally: gcc -fopenmp 01-hello-openmp.c -o hello && ./hello. Set threads with OMP_NUM_THREADS=4 ./hello. On Compiler Explorer (godbolt.org) add -fopenmp. Full instructions and the macOS note are in README.md.
This is the last session of Unit I. MPI and CUDA join OpenMP in Unit IV.