OpenMP: Do loop index variables need to be scoped explicityly?

OpenMP: Do loop index variables need to be scoped explicityly?

The following is a simplified test case:

      subroutine addv(M, N, a, b, c)
      implicit none

      integer :: M, N
      REAL:: a(M,N), b(M,N), c(M,N)

      integer :: i, j

!$OMP PARALLEL DO PRIVATE(j)
        DO j=1,N
           DO i=1,M

              c(i,j) = a(i,j) + b(i,j)
           end do
        end do
        return
        end

I understand that loop index j which is the parallel loop will be automatically scoped to be private (of course there may be exceptions).

But what about loop index I?

In the current example, will the compiler treat it as private or shared?

What if there was a scalar temporary inside the parallel loop (that is used only inside the loop) that is not a loop index variable?  Would that be treated by the compiler as a private or shared variable?

Is there a way to get a listing from the compiler that indicates whether a particular variable is treated as private or shared?

As far as I know there is no way to get such a listing.  Does anyone think it should be possible to get such a listing?

Thanks!

2 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

OpenMP Fortran makes all the loop indices in the parallel region private by default. That can be a little confusing as it's different from the rule for C.   All other variables are shared by default.  It's possible when a local scalar is optimized to register variable that it won't matter that you forgot to specify private, but there's no point in taking the chance. 

The usual way to diagnose problems with private declaration is to set default(none).  Then the compiler will flag and quit on any variables not specified as private or shared.

Leave a Comment

Please sign in to add a comment. Not a member? Join today