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

openmp problem

J__C_
Beginner
277 Views


Hi,

I'm having problems with a derived type variable containing
allocatable components declared shared in an openmp parallel
section. I've attached a minimal code to reproduce the problem
below. It executes when compiled with Ifort versions 11.0, 11.1, 12.0,
12.1, but crashes with 13.0, 13.1, 14.0, partially depending on
optimization flags. I typically get the error message:

forrtl: severe (151): allocatable array is already allocated

even though the print statement tells me it's not. I'm not completely
sure the code complies with the openmp specification, but at least I
cannot see an obvious problem. Any feedback would be appreciated.

All the best,
   John

 

MODULE DERIVED_TYPE

  IMPLICIT NONE

  TYPE ALLOCATABLE_TYPE
     REAL, DIMENSION(:), ALLOCATABLE :: vector
  END TYPE ALLOCATABLE_TYPE

CONTAINS

  SUBROUTINE INIT(var, len)

    INTEGER,                INTENT(IN)    :: len
    TYPE(ALLOCATABLE_TYPE), INTENT(INOUT) :: var

    PRINT *, ALLOCATED(var%vector)
    ALLOCATE(var%vector(1:len))

  END SUBROUTINE INIT

END MODULE DERIVED_TYPE

 

PROGRAM TEST

  USE DERIVED_TYPE
  IMPLICIT NONE

  TYPE(ALLOCATABLE_TYPE) :: var

CALL OMP_SET_NUM_THREADS(1)

!$OMP PARALLEL PRIVATE(var)

  CALL INIT(var, 1)

!$OMP END PARALLEL

END PROGRAM TEST

 

0 Kudos
2 Replies
jimdempseyatthecove
Honored Contributor III
277 Views

Try changing PRIVATE(var) to FIRSTPRIVATE(var).

Reason, you want to copy in the "not allocated" state of var into the parallel region

Jim Dempsey

0 Kudos
J__C_
Beginner
277 Views

 

Thanks, Jim, that did the trick!

Best, John

0 Kudos
Reply