Chunk_size in OpenMP* SCHEDULE clause has side-effects

The chunk_size expression used in an OpenMP schedule clause should not have side-effects.

When a worksharing loop is executed, the loop iterations must be distributed among a team of threads. Iterations can be handed out one at a time, or they can be handed out in consecutive subsets called chunks. The chunk_size clause in a SCHEDULE clause determine the size of the chunks. The chunk size can be a constant or it can be an expression.

The chunk_size expression is evaluated using the original list items of any variables that are made private in the loop construct. It is unspecified whether, in what order, or how many times, any side-effects of the evaluation of this expression occur. Therefore the presence of side-effects in a chunk_size expression results in undefined behavior.

ID

Observation

Description

1

OpenMP usage error

The place the bad chunk size expression was specified

Example

          
    integer OMP_GET_THREAD_NUM
    j = 1
    call OMP_SET_NUM_THREADS(4)
!$OMP PARALLEL DO ORDERED SCHEDULE(static, j + mysub())
    do i = 1, 10
!$OMP ORDERED
      print *, OMP_GET_THREAD_NUM()
!$OMP END ORDERED
    end do
!$OMP END PARALLEL DO
    
    contains

    integer function mysub()
        j = 2
        mysub = 1
    end function mysub
    end
        

Copyright © 2010, Intel Corporation. All rights reserved.