Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
29285 Discussions

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

Raghu_Reddy
Beginner
1,237 Views

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!

0 Kudos
1 Reply
TimP
Honored Contributor III
1,237 Views

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.

0 Kudos
Reply