LASTPRIVATE variable used after OpenMP* NOWAIT clause

A LASTPRIVATE variable in 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 LASTPRIVATE clause causes an outer variable to be assigned the value of an inner private variable, using the value belonging to the thread that executes the last iteration of the loop.

A data race occurs if the variable assigned via the LASTPRIVATE 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 last, i
    real, dimension(N) :: a, b, c
    b = 10.0
    c = 50.0
$OMP PARALLEL SHARED(a, b, c, last)
$OMP DO LASTPRIVATE(last)
    do i = 1, N
        a(i) = b(i) + c(i)
        last = i
    end do
$OMP END DO NOWAIT
$OMP SINGLE
    call sub(last)
$OMP END SINGLE
$OMP END PARALLEL
    end

    subroutine sub(last)
    integer last
    print *, last
    end subroutine sub
        

Copyright © 2010, Intel Corporation. All rights reserved.