C | Fortran-90



The schedule clause tells OpenMP how to distribute the loop iterations to the threads.



schedule([modifier[, modifier]:] kind [, chunk_size])


modifier [Optional]

The modifier to apply.
Possible values:

  • monotonic: each thread executes the chunks that it is assigned in increasing logical iteration order.
  • non-monotonic: each thread may execute the chunks that it is assigned in any order. The behavior of an application that depends on any execution order of the chunks is unspecified.
  • simd: if the loop is associated with a simd construct, the chunk_size for all chunks except the first and last chunks is new_chunk_size = ⌈chunk_size/simd_width⌉ * simd_width, where simd_width is an implementation-defined value. The first chunk will have at least new_chunk_size iterations except if it is also the last chunk. The last chunk may have fewer iterations than new_chunk_size. If the simd modifier is specified and the loop is not associated with a simd construct, the modifier is ignored.

The OpenMP scheduling kind to use.
Possible values:

chunk_size [Optional]

Optional argument that specifies how many iterations make a chunk. OpenMP schedules distribute chunks of iterations, this parameter therefore defines the scheduling "granularity".




#include <stdio.h>
#include <stdlib.h>
#include <omp.h>

 * @brief Illustrates how to tell OpenMP which schedule to apply.
 * @details A static schedule strategy is explicitly specified, as well as the chunksize.
int main(int argc, char* argv[])
    // Use 2 threads when creating OpenMP parallel regions

    // Parallelise the for loop using the static schedule with chunks made of 2 iterations
    #pragma omp parallel for schedule(static, 2)
    for(int i = 0; i < 10; i++)
        printf("Thread %d processes iteration %d.\n", omp_get_thread_num(), i);

    return EXIT_SUCCESS;