un-allocation of variables
Posted: Fri Dec 04, 2009 11:41 am
Hello bazaareers,
I am using ifort 11 on abinit 6 (same things happened with 5.9).
If you activate bounds checking with -C _all_ of the tests fail, because a large number of arrays are passed without being allocated. What we do is:
--------------------------------------------------------
real(dp), allocatable :: truc(:,:)
<we do not allocate truc because it will not be used>
call sub(truc)
--------------------------------------------------------
and then:
--------------------------------------------------------
subroutine sub(truc)
real(dp) :: truc(0,0)
--------------------------------------------------------
In principle this does not create an error because truc should never be accessed, but in practice it is quite ugly, and the ifort -C detects it. I think it has an assertion that, in subroutine sub, truc's dimensions are really the ones declared (whereas actually it is unallocated).
I get errors like:
forrtl: severe (408): fort: (8): Attempt to fetch from allocatable variable TRUC when it is not allocated
If I allocate truc to size 0, everything is fine. If I just declare real(dp) :: truc(:,:) in sub, it still fails - ifort is still checking for dimensions of a real array.
Could we think about getting rid of this practice? If an object is not allocated and then passed, it should be in a datastructure someplace. The declaration line in the subroutine is rigorously false, ifort sees that, and this practice is also very error prone. I am not advocating allocating these arrays, as this would take up space, but either use a structure of some type, with an associated module, or eventually a pointer (don't like this much in fortran).
Matthieu
I am using ifort 11 on abinit 6 (same things happened with 5.9).
If you activate bounds checking with -C _all_ of the tests fail, because a large number of arrays are passed without being allocated. What we do is:
--------------------------------------------------------
real(dp), allocatable :: truc(:,:)
<we do not allocate truc because it will not be used>
call sub(truc)
--------------------------------------------------------
and then:
--------------------------------------------------------
subroutine sub(truc)
real(dp) :: truc(0,0)
--------------------------------------------------------
In principle this does not create an error because truc should never be accessed, but in practice it is quite ugly, and the ifort -C detects it. I think it has an assertion that, in subroutine sub, truc's dimensions are really the ones declared (whereas actually it is unallocated).
I get errors like:
forrtl: severe (408): fort: (8): Attempt to fetch from allocatable variable TRUC when it is not allocated
If I allocate truc to size 0, everything is fine. If I just declare real(dp) :: truc(:,:) in sub, it still fails - ifort is still checking for dimensions of a real array.
Could we think about getting rid of this practice? If an object is not allocated and then passed, it should be in a datastructure someplace. The declaration line in the subroutine is rigorously false, ifort sees that, and this practice is also very error prone. I am not advocating allocating these arrays, as this would take up space, but either use a structure of some type, with an associated module, or eventually a pointer (don't like this much in fortran).
Matthieu