BARRIER (TU*X only)

OpenMP Parallel Compiler Directive: Synchronizes all the threads in a team. It causes each thread to wait until all of the other threads in the team have reached the barrier.

Syntax

c$OMP BARRIER

c
Is one of the following: C (or c), !, or * (see Syntax Rules for Parallel Directives).

The BARRIER directive must be encountered by all threads in a team or by none at all. It must also be encountered in the same order by all threads in a team.

See Also: Parallel Directives for Tru64 UNIX Systems, OpenMP Fortran API Compiler Directives (TU*X only), Compaq Fortran Parallel Compiler Directives (TU*X only), Nesting and Binding Rules

Examples

The directive binding rules call for a BARRIER directive to bind to the closest enclosing PARALLEL directive. In the following example, the BARRIER directive ensures that all threads have executed the first loop and that it is safe to execute the second loop:

  c$OMP PARALLEL
  c$OMP DO PRIVATE(i)
        DO i = 1, 100
          b(i) = i
        END DO
  c$OMP BARRIER
  c$OMP DO PRIVATE(i)
        DO i = 1, 100
          a(i) = b(101-i)
        END DO
  c$OMP END PARALLEL