Rookie HPC

Scheduling

FORTRAN

omp_sched_kind

Definition

omp_sched_kind is the kind of integer that can contain a schedule that can be passed to omp_set_schedule, or retrieved from omp_get_schedule, as well as the modifier that can be applied to that schedule. Its possible values are omp_sched_static, omp_sched_dynamic, omp_sched_auto, omp_sched_guided and omp_sched_monotonic. The first four correspond go the static, dynamic, auto and guided schedules respectively. The last one corresponds to the monotonic modifier.

Example

Copy

Feedback

!> @brief Illustrates the use of the omp_sched_kind.
!> @details A do loop is parallelised across 4 threads using the runtime
!> schedule policy. The schedule to apply is defined by omp_set_schedule as 
!> being a dynamic scheduling with chunks made of 4 iterations.
PROGRAM main
    USE omp_lib

    IMPLICIT NONE

    INTEGER(KIND=omp_sched_kind) :: kind
    INTEGER :: i

    ! Use 4 threads when creating OpenMP parallel regions
    CALL omp_set_num_threads(4)

    ! Tell OpenMP which scheduling policy and chunk size use do runtime schedule clauses
    kind = omp_sched_dynamic
    CALL omp_set_schedule(kind, 2)

    ! Parallelise the do loop using the runtime schedule
    !$omp parallel do schedule(runtime)
    DO i = 0, 9
        WRITE(*,'(A,I0,A,I0,A)') 'Thread ', omp_get_thread_num(), ' processes iteration ', i, '.'
    END DO
    !$omp end parallel do
END PROGRAM main