← Back to examples

The Fork-Join Model

This is how OpenMP works. Your program runs on one master thread. When it hits a #pragma omp parallel region it forks into a team of threads that all run at once. At the end of the region they join back into one, and the program continues serially. Pick a thread count and press play.

Ready. One master thread.
master thread (serial) worker threads (parallel region)

The takeaway: you did not create, schedule, or destroy a single thread by hand. You wrote #pragma omp parallel and the compiler did all of it — fork on the way in, join on the way out. That is why OpenMP is the gentlest way into parallel programming.