Allocatable structure with PGF90

Hello,

I am trying to make an allocatable array structure that itself contains allocatable arrays:

TYPE :: objstruc
     REAL(KIND=RP),DIMENSION(:),ALLOCATABLE :: par   = 0._RP 
     REAL(KIND=RP),DIMENSION(:),ALLOCATABLE :: prior = 0._RP 
END TYPE objstruc
...
TYPE (objstruc),DIMENSION(:),ALLOCATABLE :: obj  
...
N=10
ALLOCATE( obj(N))
NFP=10
ALLOCATE( obj(:)%par(NFP), obj(:)%prior(NFP) )

Is this possible?
I am getting this error:

mpif90 -fast  -c -o ./obj/nest_disp.o nest_disp.f90
PGF90-S-0198-Array-valued derived-type parent in ALLOCATE/DEALLOCATE (nest_disp.f90: 188)
  0 inform,   0 warnings,   1 severes, 0 fatal for nested_plane
Lowering Error: DATA repeat count ast not constant: 110
Lowering Error: DATA repeat count ast not constant: 118
PGF90-F-0000-Internal compiler error. Errors in Lowering       2 (nest_disp.f90: 707)
PGF90/x86-64 Linux 10.0-0: compilation aborted
make: *** [obj/nest_disp.o] Error 2

Am I missing something obvious?

Thanks very much, Jan Dettmer

Hi Jan,

Two errors. You can’t initialize the allocatable arrays (par and prior) and you need to allocate each “obj” separately.

TYPE :: objstruc
     REAL(KIND=RP),DIMENSION(:),ALLOCATABLE :: par
     REAL(KIND=RP),DIMENSION(:),ALLOCATABLE :: prior
END TYPE objstruc
TYPE (objstruc),DIMENSION(:),ALLOCATABLE :: obj
N=10
ALLOCATE( obj(N))
NFP=10
do i=1,N
   ALLOCATE( obj(i)%par(NFP), obj(i)%prior(NFP) )
enddo
end

Hope this helps,
Mat

Thanks Mat worked perfectly.

-Jan

Hi,
I encountered another problem with the above code sniplet. If I set N to something large (N=2000) and NFP is of the order of 15, the code crashes with a segmentation fault. If I don’t dynamically allocate the NFP dimension, all works. Any idea why this is the case?

Thanks, Jan



TYPE :: objstruc
     REAL(KIND=RP),DIMENSION(:),ALLOCATABLE :: par
     REAL(KIND=RP),DIMENSION(:),ALLOCATABLE :: prior
END TYPE objstruc
TYPE (objstruc),DIMENSION(:),ALLOCATABLE :: obj
N=10
ALLOCATE( obj(N))
NFP=10
do i=1,N
   ALLOCATE( obj(i)%par(NFP), obj(i)%prior(NFP) )
enddo
end

Hi jand,

I just tried it and it works fine for me. What flags are you using? Which OS? Which compiler version? Am I missing any parts of the code? Also, what’s the value of “RP”? (I set it to 8).

  • Mat
% cat test.f90
program test
TYPE :: objstruc
     REAL(KIND=8),DIMENSION(:),ALLOCATABLE :: par
     REAL(KIND=8),DIMENSION(:),ALLOCATABLE :: prior
END TYPE objstruc
TYPE (objstruc),DIMENSION(:),ALLOCATABLE :: obj
N=2000
ALLOCATE( obj(N))
NFP=15
do i=1,N
   ALLOCATE( obj(i)%par(NFP), obj(i)%prior(NFP) )
   obj(i)%par = 1.0
   obj(i)%prior = 1.0
enddo

do i=1,N
   print *, i, ' ', obj(i)%par(1:2)
enddo

end
% pgf90 -fast test.f90
% a.out 
... cut ...
         1997      1.000000000000000         1.000000000000000
         1998      1.000000000000000         1.000000000000000
         1999      1.000000000000000         1.000000000000000
         2000      1.000000000000000         1.000000000000000
%