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

OpenMP program crashes when compiled in Release mode

Matuszyk__Pawel
Beginner
1,283 Views

Hi, I wrote the following code:

program omp_err

implicit none

!

type :: mytype

integer :: n

real(8), allocatable :: x(:)

end type

!

type(mytype) :: a

!

!$OMP PARALLEL PRIVATE(a)

WRITE(*,*) 'parallel'

!$OMP END PARALLEL

!

WRITE(*,*) 'after parallel'

!

end program omp_err

When I compile it in Debug mode, it works fine. However, compiled in Release mode, it crashes enetering parallel region. I also noticed, that replacing clause PRIVATE with FIRSTPRIVATE causes it works fine. It indicated that there is a problem with initialization of allocatable component x.

Could you explain me, why it happens and what is wrong wiith my code?

Regards,

Pawel

0 Kudos
4 Replies
Steven_L_Intel1
Employee
1,283 Views

I don't pretend to be an OpenMP expert but I don't see anything that's wrong with your program. I can see the error even when built as a debug configuration. If I take off the PRIVATE clause, it works. I have escalated this to the developers as issue DPD200361282 and will let you know what we discover.

0 Kudos
jimdempseyatthecove
Honored Contributor III
1,283 Views

Consider:

subroutine foo()
real :: A ! A is undefined at this point
!$OMP PARALLEL PRIVATE(A)
write(*,*) A
!$OMP END PARALLEL
A = 123.456
!$OMP PARALLEL PRIVATE(A)
write(*,*) A ! A is only defined for Thread Team member 0, undefined for others
!$OMP END PARALLEL

The PRIVATE(A) does not copy in the initial value from outside the scope of the parallel regon.

The master thread of the parallel region uses the (PRIVATE) variables of the scope outside the parallel region.

In the case of an array, the array descriptor is undefined for the PRIVATE entities of the non-master threads.

Making it FIRSTPRIVATE performs a copy-in of the empty array descriptor.

The compiler could figure out that the variable in the private list is an array descriptor and clean it up (for non-master threads), or a user defined type with a default constructor and execute that (for non-master threads), ... or POINTER that should get NULLIFIED (for non-master threads). This has been an old problem since F90/F95 and may have been addressed by newer OpenMP specifications.

Jim Dempsey

0 Kudos
Steven_L_Intel1
Employee
1,283 Views

It should work, I think. A new variable is created, and it's fine if the original was not allocated. The text I read talks about allocatable arrays, doesn't really discuss allocatable components (which were new in F2003 and older OpenMP didn't address that.)

0 Kudos
TimP
Honored Contributor III
1,283 Views

As Jim pointed out, you have created undefined arrays.  It's a bit strange that this would cause problems when you don't actually use them, but the vagaries of compiler dead code elimination may be inscrutable.

0 Kudos
Reply