Conditional OpenMP* BARRIER

A BARRIER may not be executed by all the threads in the team.

The BARRIER construct is used to synchronize threads. Its presence ensures that all the actions before the BARRIER are completed before the actions after the BARRIER are executed. To do this, the OpenMP runtime holds threads at the BARRIER until the last thread in the team arrives, at which point all the threads are released together.

Obviously, if any thread in the team fails to reach the BARRIER then any threads that did will never be released and thus are effectively deadlocked. This is why a BARRIER must be executed by every thread in the team or by none at all. This error indicates that a BARRIER was placed within a conditional statement (such as an "if" statement) in such a way that deadlocks appear to be possible.

It is safe to put a BARRIER in a conditional statement if all threads in the team would execute the same path through that statement. This would be true if the expression(s) that control the flow path (such as the boolean expressions in containing "if" statements) are invariant, that is, if they do not change their value within the parallel region. If analysis determines that the controlling expressions are invariant then the diagnostic is not emitted. The "possible" form of the diagnostic indicates that analysis could not determine with certainty whether the controlling expressions were or were not invariant. If your analysis reveals that the controlling expressions are in fact invariant then this diagnostic can be safely ignored.

ID

Observation

Description

1

OpenMP usage error

The location of the barrier region

2

Definition

The location of the enclosing conditional statement

Example


!**************************************************
!*                                                *
!*              OpenMP Assertion 04               *
!*                                                *
!* work-sharing constructs and BARRIER directives *
!* must be encountered by all threads in a team   *
!* or by none at all                              *
!*                                                *
!**************************************************

program barrier
    dimension A(1000)
!$OMP PARALLEL
    do I = 1, 1000
        if (i .GT. 500) then
! Bad - if expression is not loop invariant so
! BARRIER may not be encountered by all threads
!$OMP BARRIER
        end if
        A(i) = i
    end do
!$OMP END PARALLEL
end
        

Copyright © 2010, Intel Corporation. All rights reserved.