Scheduling

C | Fortran-90

guided

Definition

guided is an OpenMP schedule policy. The set of iterations is split in blocks of consecutive iterations called chunks, which are distributed to the threads in the team. Each thread executes a chunk, then requests another chunk, until no chunks remain to be distributed. The singularity of guided is that the chunk size starts as large and gradually decreases, in order to progressively improve load balancing. These decreasing chunk sizes will eventually fall to 1 by default, unless a minimum chunk size is passed via the optional argument (except the last chunk to assign, which may have fewer iterations that asked). Other OpenMP schedule policies are static, dynamic, auto and runtime.

Example

Copy

Feedback

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

/**
 * @brief Illustrates the guided scheduling policy.
 * @details A for loop is parallelised across 2 threads using the guided
 * scheduling policy.
 **/
int main(int argc, char* argv[])
{
    // Use 2 threads when creating OpenMP parallel regions
    omp_set_num_threads(2);

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

    return EXIT_SUCCESS;
}