Hi,
I've come to notice a very strange behaviour with the intel compiler on Linux. It's a bit difficult to explain, since I'm not able to make a minimal example (for reasons which will become apparent). What I'm doing is basically calling a set of subroutines which kind of look like that:
SUBROUTINE WHATEVER (a, b, table)
IMPLICIT NONE
DOUBLE PRECISION, POINTER, DIMENSION(:), INTENT(IN) :: a
DOUBLE PRECISION, POINTER, DIMENSION(:), INTENT(IN) :: b
DOUBLE PRECISION, POINTER, DIMENSION(:,:,:,:), INTENT(OUT) :: table
ALLOCATE(table( ... ) )
table= ...
END SUBROUTINE WHATEVER
I have 6 of such routines which all allocate and define multidimensional arrays of up to six dimensions. Now, before I started implementing calculations with those tables I just tried to set them up and deallocate them to see if the compiler complains:
SUBROUTINE SOMETHING (a,b)
DOUBLE PRECISION, POINTER, DIMENSION(:), INTENT(IN) :: a
DOUBLE PRECISION, POINTER, DIMENSION(:), INTENT(IN) :: b
DOUBLE PRECISION, POINTER, DIMENSION(:,:,:,:) :: table_a
DOUBLE PRECISION, POINTER, DIMENSION(:,:,:,:) :: table_b
DOUBLE PRECISION, POINTER, DIMENSION(:,:,:,:) :: table_c
DOUBLE PRECISION, POINTER, DIMENSION(:,:,:,:) :: table_d
DOUBLE PRECISION, POINTER, DIMENSION(:,:,:,:,:,:) :: table_e
CALL WHATEVER_a (a, b, table_a)
CALL WHATEVER_b (a, b, table_b)
CALL WHATEVER_c (a, b, table_c)
CALL WHATEVER_d (a, b, table_d)
CALL WHATEVER_e (a, b, table_e)
CALL WHATEVER_f (a, b, table_f)
DEALLOCATE(table_a, table_b, table_c, table_d, table_e, table_f)
!Do something TOTALLY UNRELATED to those arrays
.......
END SUBROUTINE SOMETHING
My program compiled without issues. But during runtime I get an inconsistent result (I have my own routines that check for any unexpected results). There is no runtime error, it's just that something has changed in another calculation in an entirely unrelated subroutine. And that's the point which confuses me the most: The other subroutine which suffers a weird change in it's values has nothing in common with the subroutine where I allocate and deallocate the arrays. I mean, seriously, nothing. No Module, no arguments, nothing. If I remove the DEALLOCATE statement, it works just fine, also if I deallocate only one of those arrays, everything is fine...
It appears something is wrong with the deallocation. When I move the deallocation into the WHATEVER_x subroutines, everything is ok as well.
Since I don't have any particular knowledge about the inner workings of the compiler or how the DEALLOCATE statement is implemented, I'm kind of left with a questionmark hovering above my head. But if I'd have to guess, I'd say that the results of anything shouldn't depend on whether I deallocate at the end of a subroutine or immediately after the return to the main routine. Also, it should be entirely impossible for two completely disjoint routines to have side-effects on each other. Except that the deallocation statement messes something up in the memory...
Am I doing something wrong here? Any suggestions how I could test what's going on?
Thanks
Dino