[Omp] Help on the Barrier case

Eugene Loh Eugene.Loh at Sun.COM
Thu Mar 8 15:49:55 PST 2007


eduncan wrote:

>Actually your program is non-compliant. If you look at the OpenMP V2.5 specification, section 2.9 Nesting of Regions:
>
>This section describes a set of restrictions on the nesting of regions.  The restrictions on nesting are as follows:
>...
>• A barrier region may not be closely nested inside a work-sharing, 
>critical, ordered, or master region.
>  
>
Just to follow up on that, at least with the Sun Studio compilers you 
get an error. E.g.,

% cat z.f
subroutine sub(n)

c$omp parallel do shared(n) private(k)
do k = 1, n
c$omp barrier
end do

end
% f90 -fast -xarch=v9b -xopenmp z.f

c$omp barrier
^
"z.f", Line = 5, Column = 7: ERROR: The C$OMP BARRIER directive cannot 
be specified within a C$OMP PARALLEL DO region.

f90comp: 8 SOURCE LINES
f90comp: 1 ERRORS, 0 WARNINGS, 0 OTHER MESSAGES, 0 ANSI
%

Or, if the barrier is within a called routine, you can get a run-time check:

% cat z2.f
c$omp parallel do
do k = 1, 1000000
call sub2()
end do

end

subroutine sub2()
c$omp barrier
end
% f90 -fast -xarch=v9b -xopenmp z2.f
% setenv SUNW_MP_WARN true
% ./a.out
WARNING (libmtsk): at z2.f:9. Barrier is not permitted in dynamic extent 
of for / DO.
%

The Sun Studio compilers are available for free download from 
http://developers.sun.com/sunstudio/ for SPARC Solaris or for Solaris or 
Linux on x86/x64.

As Eric points out, this doesn't direct address your question, but it 
does help to start with compliant programs.

>Shengyan Hong wrote:
>  
>
>>      !$omp parallel do default(shared) private(i,j,k)
>>      do k = 1, d3
>>         do j = 1, d2
>>            do i = 1, d1
>>               u1(i,j,k) = u0(i,j,k)*ex(t*indexmap(i,j,k))
>>            end do
>>         end do
>>       TID = OMP_GET_THREAD_NUM()
>>       PRINT *, 'thread = ', TID
>>       print *, "March 6 night"
>>       print *, "Before barrier"
>>       CALL MAGIC_BRK_SIM_START()
>>       !$OMP BARRIER
>>       print *, "After barrier"
>>       CALL MAGIC_BRK_SIM_START()
>>       end do
>>
>>      return
>>      end
>>



More information about the Omp mailing list