C | Fortran-90



The function omp_set_schedule is one of the two ways to specify the schedule to apply when a runtime clause is encountered during execution. The other one is the environment variable OMP_SCHEDULE. The expected format for the schedule is: the kind of scheduling (static, dynamic, auto or guided). Optionally, the kind can also be succeeded by a comma and the chunk size. To summarise, it can be represented as follows: "[modifier:]kind[,chunksize]". Please note that if this format is not respected, the behaviour is implementation defined. It is also worth mentioning that implementation specific schedules can be used in the omp_set_schedule function, but they cannot be used in the environment variable OMP_SCHEDULE. If none of the environment variable OMP_SCHEDULE or the function omp_set_schedule is used, the schedule to apply when a runtime clause is encountered during execution is implementation defined. To see the schedule to apply when the runtime clause is encountered, one can call omp_get_schedule.



void omp_set_schedule(omp_sched_t kind,
                      int chunk_size);




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

 * @brief Illustrates the use of the omp_set_schedule function.
 * @details A for loop is parallelised across 4 threads using the runtime
 * schedule kind. The schedule to apply is defined by omp_set_schedule as 
 * being a dynamic scheduling with chunks made of 2 iterations.
int main(int argc, char* argv[])
    // Use 4 threads when creating OpenMP parallel regions

    // Tell OpenMP which scheduling kind and chunk size use for runtime schedule clauses
    omp_set_schedule(omp_sched_dynamic, 2);

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

    return EXIT_SUCCESS;