Rookie HPC

Scheduling

C | FORTRAN

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 optional argument passed to schedule tells how many iterations at least each chujnk must contain (except the last chunk to assign, which may have fewer iterations that asked). If this optional argument is not present, the chunk size defaults to 1. 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;
}