Intel® Moderncode for Parallel Architectures
Support for developing parallel programming applications on Intel® Architecture.
1696 Discussions

OpenMP and allocatable fields of shared derived types

Massimiliano_Culpo
400 Views
Hi,

I was wondering why this simple program:

[fortran]program allocatable

  type pippo
     real(8), allocatable :: vec(:)
  end type pippo

  type(pippo) :: a

  !$omp parallel 
  !$omp single
  allocate(a%vec(10))
  !$omp end single
  !$omp end parallel

end program allocatable[/fortran]
crashes when compiled with:

  • ifort -openmp

Notice that the same program works fine when compiled with gfortran and PGI compiler. If anybody has a clue I would be really glad to hear that.

M.
0 Kudos
6 Replies
TimP
Honored Contributor III
400 Views
Not with any version of ifort I have installed here (up to 14 weeks old, none older).
Maybe you found a buggy version of the compiler, or got the environment PATH settings fouled?
Are you certain, if you tried every past version of those other compilers, you would never find a bug?

0 Kudos
Massimiliano_Culpo
400 Views
The version of ifort I am using is:

  • ifort (IFORT) 11.1 20091130
    Copyright (C) 1985-2009 Intel Corporation. All rights reserved.
so it's more than 14weeks old. The problem I encountered seems to be due to an automatic allocation of the allocatable field as soon as one enters the parallel region. Notice that the serial program works just fine. What I get on stdout is the following:

forrtl: severe (151): allocatable array is already allocated
Image PC Routine Line Source
a.out 0809129D Unknown Unknown Unknown
a.out 08090095 Unknown Unknown Unknown
a.out 08072938 Unknown Unknown Unknown
a.out 0806516D Unknown Unknown Unknown
a.out 080557CD Unknown Unknown Unknown
a.out 0804A548 Unknown Unknown Unknown
libiomp5.so B776AA6D Unknown Unknown Unknown
libiomp5.so B774A56C Unknown Unknown Unknown
libiomp5.so B774D020 Unknown Unknown Unknown
libiomp5.so B77328B7 Unknown Unknown Unknown
a.out 0804A477 Unknown Unknown Unknown
a.out 0804A391 Unknown Unknown Unknown
libc.so.6 B75ABB56 Unknown Unknown Unknown
a.out 0804A2A1 Unknown Unknown Unknown

If "pointer" is used instead of "allocatable" or the option "-O0" is passed to the compiler, then no fail is encountered.

I know that FORTRAN 90/95 standards do not admit allocatable fields as part of a derived data-type, but I am quite curious to understand what the compiler does when it compiles that simple program and why it fails with ifort and not with other compilers. Possibly this will give me a better understanding of the differences between pointers and allocatables types.

M.

0 Kudos
jimdempseyatthecove
Honored Contributor III
400 Views

!$ompparallel
if(.not. allocated(a%vec) then
!$ompcritical
if (.not. allocated(a%vec)
allocate(a%vec(10))

!$ompendcritical
endif
(assume other code here)
!$ompendparallel

Your program was in error.

Jim Dempsey

0 Kudos
Massimiliano_Culpo
400 Views
Dear Jim,

I am sorry, but I can't get your point. Could you be more specific and tell me where is the error and why is it an error?

M.
0 Kudos
jimdempseyatthecove
Honored Contributor III
400 Views
Your code may accidentally work, then unexpectedly fail, should you insert additional code following the !$OMP SINGLE and preceeding the !$OMP END PARALLEL.

[bash]!$omp parallel    
!$omp single   
allocate(a%vec(10))   
!$omp end single  
{any code here can experience problems} 
!$omp end parallel
{ code here should be OK}
 
Often postings on this forum are in "sketch" format (meaning missing details).


Jim Dempsey


[/bash]
0 Kudos
jimdempseyatthecove
Honored Contributor III
400 Views

Try adding shared(a)

!$ompparallelshared(a)
!$ompsingle
allocate(a%vec(10))
!$ompendsingle
!$ompendparallel

0 Kudos
Reply