Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

OpenMP crash with derived type

Roman1
New Contributor I
227 Views


I am using Fortran Compiler XE 15.0.1.148 .

When I compile and run the following simple program in Debug mode, it runs fine without any errors or warnings.  However, it crashes if I compile it in optimized Release mode.  I can prevent it from crashing if I disable the /Qopenmp option.  My guess is that the problem has something to do with having a derived type variable declared as private in OpenMP loop.

program test_derived_type
implicit none

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

type(T):: b
integer i, s

s = 0

!$OMP parallel do default(none), schedule(dynamic), &
!$OMP&         private(i,b), reduction(+:s)
do i = 1, 100
   print*, i
   
   allocate( b%a(i) )
   b%a = 1
   
   s = s + sum(b%a)
   
   deallocate(b%a)
end do  ! i
!$OMP end parallel do

write(*,*) 's =', s
stop
end program test_derived_type

 

0 Kudos
2 Replies
Mark_Lewy
Valued Contributor I
227 Views

My reading of the OpenMP 4.0 standard (Section 1.6 Normative References, page 22, line 25) suggests that allocatable components of derived types are not supported in OpenMP regions.

0 Kudos
jimdempseyatthecove
Honored Contributor III
227 Views

Add COPYIN(b) next to the private(i,b).

Outside the scope of the parallel region b%a surprisingly is defined as an un-allocated array. Meaning the array descriptor is initialized to represent an unallocated array (in this case of rank 1).

Without the COPYIN, the variables in the PRIVATE are undefined. Meaning not set or initialized. Therefore b%a will be undefined, which is not the same as unallocated.

Jim Dempsey

0 Kudos
Reply