Scheduling

C | Fortran-90

auto

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;
}