REDUCTION variable used after OpenMP* NOWAIT clause

A REDUCTION variable set in a NOWAIT worksharing construct is used before a BARRIER, thus creating a race condition.

The NOWAIT clause allows threads to continue to execute past the end of a worksharing construct without waiting for all the other threads to complete the construct. In other words, the implicit barrier at the end of the construct is omitted. The REDUCTION clause causes an outer variable to be updated on exit, using a value from a private copy belonging to the thread that executes an iteration of the loop.

A data race occurs if the variable assigned via the REDUCTION clause is used before the next BARRIER. There is no guarantee that the thread that performs the last loop iteration will perform the assignment to that variable before the reference occurs.

ID

Observation

Description

1

OpenMP usage error

The place the variable was referenced

Example


    integer, parameter :: N=10
    integer sum
    sum = 0
!$OMP PARALLEL SHARED(a, b, c, sum) NUM_THREADS(4)
!$OMP DO REDUCTION(+:sum)
    do i = 1, N
        sum = sum + i
    end do
!$OMP END DO NOWAIT
!$OMP SINGLE
    print *, sum
!$OMP END SINGLE
!$OMP END PARALLEL
    end
        

Copyright © 2010, Intel Corporation. All rights reserved.