Rookie HPC

Scheduling

C | FORTRAN

auto

Definition

auto is an OpenMP schedule policy, where the programmer gives total freedom to the compiler to decide how to map iterations to threads. Other OpenMP schedule policies are static, dynamic, guided and runtime.

Example

Copy

Feedback

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

/**
 * @brief Illustrates the use the auto schedule.
 * @details A for loop is parallelised across 2 threads using the auto schedule 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 auto schedule
    #pragma omp parallel for schedule(auto)
    for(int i = 0; i < 10; i++)
    {
        printf("Thread %d processes iteration %d.\n", omp_get_thread_num(), i);
    }

    return EXIT_SUCCESS;
}