Table of Contents

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.

#pragma omp parallel for schedule(dynamic, 4)
for (int i = 0; i < N; i++) {
    process(i);  // variable cost per iteration
}

The main schedule kinds are:

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.