Test Case:

!  derived from OpenMP test omp3f/F03_2_9_1_1_4a.f90
!  REFERENCES : OpenMP 3.0, p. 79, lines 11-14
program F03_2_9_1_1_4a
   use omp_lib
   implicit none
   integer, parameter :: NT = 4
   integer, parameter :: EXPECTED_i = -1 ! expected value of i at end
   integer, parameter :: EXPECTED_sum_i = (NT+1)*NT/2 ! 1 + 2 + ... + NT
   integer :: i = EXPECTED_i
   integer :: sum_i = 0 ! initialize to an "invalid" value

   call omp_set_dynamic(.false.)
   call omp_set_num_threads(NT)

!$omp parallel shared(sum_i)
   !$omp single
   !$omp task
      ! "private(i)" legal per OMP 3.0, p. 79, lines 11-14
      !$omp task private(i)
      do i = 1,NT ! sequential loop
         ! "firstprivate(i)" legal per OMP 3.0, p. 79, lines 11-14
         ! ("...and on enclosed constructs...")
         !$omp task firstprivate(i)
         !$omp atomic
         sum_i = sum_i + i ! shared per OMP 3.0, p. 79, lines 27-28,  31-33
         !$omp end task
      end do
      !$omp end task

      !$omp taskwait ! wait for the explicit task to finish

      ! i should be shared in this task region (OMP 3.0, p. 79, lines 31-33)
      if (i /= EXPECTED_i) then
         print *, 'FAIL (in task construct) - i == ', i , ' (expected ', &
                  EXPECTED_i, ')'
      end if
   !$omp end task
   !$omp end single ! implicit barrier ensures all tasks have finished

   ! i should be shared in this parallel region (OMP 3.0, p. 79, lines 27-28)
   if (i /= EXPECTED_i) then
      print *, 'FAIL (in parallel construct) - i == ', i , ' (expected ', &
               EXPECTED_i, ')'
   end if
!$omp end parallel

   ! verify that sum_i is shared
   if (sum_i /= EXPECTED_sum_i) then
      print *, 'FAIL - sum_i == ', i , ' (expected ', EXPECTED_sum_i, ')'
   end if

end program F03_2_9_1_1_4a
> gfortran -fopenmp test.f90
> ./a.out
 FAIL (in task construct) - i ==        32767  (expected           -1 )
 FAIL (in parallel construct) - i ==            0  (expected           -1 )
 FAIL (in parallel construct) - i ==            0  (expected           -1 )
 FAIL (in parallel construct) - i ==            0  (expected           -1 )
 FAIL (in parallel construct) - i ==            0  (expected           -1 )

Explanation from OpenMP testers:

This test case is derived from OpenMP test omp3f/F03_2_9_1_1_4a.f90 .
The variable i is initialized as part of the declaration, and should 
be implicitly shared in the regions of interest.  However, the values
checked seem to have lost the initialization when checked near the
ends of the constructs.  The result is incorrect output.

The OpenMP API version 3.0 (May 2008) states the following on p. 79:

" * Variables used as loop iteration variables in sequential loops in ...
    a task construct may be listed in private, ... clauses on the ...
    task construct, and on enclosed constructs, subject to other
    restrictions."  (lines 11-14)

" * In a task construct, if no default clause is present, a variable that
    is determined to be shared in all enclosing constructs, up to and
    including the innermost enclosing parallel construct, is shared."
    (lines 31-33)


[Expected output is no output, e.g. from Intel compiler.]


-- 
           Summary: OpenMP - case involving tasks with implicit shared i -
                    incorrect output
           Product: gcc
           Version: 4.4.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: longb at cray dot com
 GCC build triplet: x86_64-suse-linux
  GCC host triplet: x86_64-suse-linux
GCC target triplet: x86_64-suse-linux


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44084

Reply via email to