scheduling-openmp
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| scheduling-openmp [June 11, 2026 at 07:42] – created - external edit 127.0.0.1 | scheduling-openmp [Unknown date] (current) – removed - external edit (Unknown date) 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | # Scheduling (OpenMP) | ||
| - | **Scheduling** in OpenMP controls how loop iterations are divided among threads. By default, `parallel for` splits iterations into roughly equal static chunks assigned to threads upfront. This works well when each iteration takes the same time. When iteration cost varies, static assignment leaves some threads idle while others are still running. A loop where some values of `i` trigger much more work than others is a common example. The `schedule` clause selects the assignment strategy. | ||
| - | |||
| - | ```c | ||
| - | #pragma omp parallel for schedule(dynamic, | ||
| - | for (int i = 0; i < N; i++) { | ||
| - | process(i); | ||
| - | } | ||
| - | ``` | ||
| - | |||
| - | The main schedule kinds are: | ||
| - | |||
| - | - `static` — divide iterations into equal chunks upfront; lowest overhead, best when work is uniform | ||
| - | - `dynamic[, chunk]` — threads pull the next chunk from a queue when they finish; good for uneven work | ||
| - | - `guided[, chunk]` — like dynamic but chunks start large and shrink as the loop progresses | ||
| - | - `runtime` — defer the decision to the `OMP_SCHEDULE` environment variable | ||
| - | - `auto` — let the compiler or runtime choose | ||
| - | |||
| - | The optional chunk size (e.g. `dynamic, 4`) controls how many iterations a thread grabs at once. Smaller chunks improve load balance but increase scheduler overhead. | ||
scheduling-openmp.1781163761.md.gz · Last modified: by 127.0.0.1
