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

            Bug ID: 60928
           Summary: gfortran issue with allocatable components and OpenMP
           Product: gcc
           Version: 4.8.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: quantheory at gmail dot com

Just as a disclaimer up front, this is probably an OpenMP 4.0 issue. OpenMP 3.1
sort of glossed over this use case, but OpenMP 4.0 quietly added language about
it. Still, it would be nice to get right, and it doesn't involve any of the new
constructs.

The following test case works with nagfor, xlf, and newer versions of
pgfortran, but not gfortran or ifort:


use omp_lib, only: omp_get_thread_num
implicit none

type :: foo
   integer, allocatable :: a(:)
end type foo

type(foo) :: bar

integer :: i, sum_arr(5)

!$omp parallel private (i, bar)

allocate(bar%a(3))

!$omp do
do i = 1, 5
   bar%a = [1, 2, 3] + omp_get_thread_num()
   sum_arr(i) = sum(bar%a)
end do

!$omp barrier
print *, sum(bar%a)
!$omp barrier

!$omp single
print *, sum(sum_arr)
!$omp end single

deallocate(bar%a)

!$omp end parallel

end


This is the runtime's error message:

Fortran runtime error: Attempting to allocate already allocated variable 'bar'

I think this signifies that the private version of "bar" is not being set up
correctly, so the threads end up sharing the allocatable component.

Reply via email to