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
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
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
%