Mike Bauer writes:
> module test
> implicit none
> save
> real*4 :: x=1.
> real*4, dimension(1000000) :: thebigarray
> end module test
>
> produces an object file of size 4000724 bytes, which is about the size
> ofthebigarray. The object file is seemingly full of initial values
> forthebigarray, even though no initialization is being done. The
> problemgoes away if x is declared as a parameter. The save statement
> has noeffect. Is this behavior part of the FORTRAN 90 standard?
This kind of thing is outside of the scope of the standard. The
standard neither requires nor forbids it. I will note that I have
seen similar behaviors in many implementations, including f77
ones; this isn't particular to modules. Try the same thing in
a subroutine with the trivial syntactic changes needed to make
it conform to f77 style.
What happens is that the presence of even a single initialization
(the x=1. here) triggers the compiler to put the variables for
this scoping unit into initialized memory. Some compilers might
split the variables into two sets - some in initialized memory and
some not. Note that parameters are very different - they are
compile-time constants and don't necessarily occupy any memory
at all.
I have seen compilers crash machines with code like this - running
the machine out of memory, disk space, or other resources. This
is far from unique to the Absoft compiler.
Some compilers might do this even if you don't explicitly initialize
anything, so making your X a parameter is not a guaranteed fix; that
one just happens to work with the current release of your current
compiler.
My usual recommendation is to avoid such large explicit
size declarations. Instead, make thebigarray allocatable and
allocate it as needed (right at the beginning of execution if
necessary). That pretty much guarantees that the object file
won't have initialized data for the array - the compiler won't
know how big the array is at compile time, so it just can't
realistically do that.
--
Richard Maine | Good judgment comes from experience;
[log in to unmask] | experience comes from bad judgment.
| -- Mark Twain
|