[Omp] Predetermination of Fortran loop iteration variables

Jakub Jelinek jakub at redhat.com
Mon Oct 24 03:24:27 PDT 2005


Hi!

The standard in 2.8.1.1 says that:
"Variables used as loop iteration variables in sequential loops in
 a parallel construct are private in the parallel construct."

Unfortunately, it is not very clear to me what exactly is this
supposed to mean.
1) does the "parallel construct" above mean just !$omp parallel,
or also the combined worksharing constructs
!$omp parallel {do,sections,workshare} ?
2) what means "in the construct"?  Are iteration variables of
sequential loops in nested parallel constructs also predetermined
in the outer loop?  Similarly for the various worksharing directives.

I have looked at what Intel Fortran compiler does and it apparently
for each loop iteration variable scans all parallel {,do,sections,workshare}
directives the loop is contained in and makes the variable predetermined
in them (i.e. privatizes them unless they were already mentioned in
data sharing clauses).  Also, it handles even loop iteration variables
of OpenMP do and parallel do constructs that way.

This contradicts OpenMP 2.5 test A.24.1f example though, where
is (simplified):
  INTEGER I, Y, Z(1000)
!$OMP PARALLEL DEFAULT (NONE) SHARED (Z)
  Z(I) = Y ! Error - cannot reference I or Y here
!$OMP DO firstprivate (y)
  DO I = 1, 10	! O.K. - I is the loop iteration variable
    Z(I) = Y	! Y is listed in FIRSTPRIVATE clause
  END DO
!$OMP END PARALLEL

In ifort I is predetermined and therefore it doesn't emit error on the ! Error
marked line.

I'm attaching a testcase that shows the various cases I'm interested
in.  Is the ! Error marked line the only one where diagnostic should be
emitted (that's what ifort does, but would mean there is a bug in A.24.1f),
or should just OMP DO and OMP PARALLEL DO iteration variables be excluded
from propagation to the enclosing parallels, or something else?

Thanks.

  integer :: i, j, k, l
  integer, dimension (10, 10) :: a
!$omp parallel do default (none) shared (a)
  do i = 1, 10
    j = 4
    do j = 1, 10
      a(i, j) = i + j
    end do
    j = 8
  end do
!$omp end parallel do
!$omp parallel default (none) shared (a)
  i = 1
  j = 1
  k = 1
  l = 1		! Error - l is not predetermined here
  do i = 1, 10
    a(i, 1) = 1
  end do
!$omp critical
  do j = 1, 10
    a(1, j) = j
  end do
!$omp end critical
!$omp single
  do k = 1, 10
    a(k, k) = k
  end do
!$omp end single
!$omp end parallel
!$omp parallel default (none) shared (a)
  i = 1
  j = 1
  k = 1
!$omp parallel default (none) shared (a)
  i = 1
  j = 1
  k = 1
  do i = 1, 10
    a(i, 1) = 1
  end do
!$omp critical
  do j = 1, 10
    a(1, j) = j
  end do
!$omp end critical
!$omp single
  do k = 1, 10
    a(k, k) = k
  end do
!$omp end single
!$omp end parallel
  i = 1
  j = 1
  k = 1
!$omp end parallel
!$omp parallel default (none) shared (a)
  i = 1
!$omp do
  do i = 1, 10
    a(i, 1) = i + 1
  end do
!$omp end parallel
!$omp parallel default (none) shared (a)
  i = 1
!$omp parallel default (none) shared (a, i)
  i = 2
!$omp parallel default (none) shared (a)
  do i = 1, 10
    a(i, 1) = i
  end do
!$omp end parallel
  i = 3
!$omp end parallel
  i = 4
!$omp end parallel
end

	Jakub




More information about the Omp mailing list