informational question: compile time of large DATA arrays

Richard E Maine Richard.Maine@nasa.gov
Mon Sep 11 15:40:00 GMT 2006


On Sep 7, 2006, at 3:05 AM, Daniel Franke wrote:

> MODULE foo
> REAL :: grid(0:          50 , 0:       10000 )
> DATA grid(           0 ,           0 ) /    1.000000      /
> DATA grid(           0 ,           1 ) /   0.9999750      /
> DATA grid(           0 ,           2 ) /   0.9999000      /
> [ ... ]
> CONTAINS
>  [a simple function working on the grid]
> END MODULE
>
> Could someone enlighten my why it takes more than 20 minutes
> (3.2GHz P4, 2GB RAM) to compile a module like this?

A bit belated reply. I wasn't here Thurs or Fri (and I won't even be  
skimming most of the 100+ messages on the list since I last looked,  
but this one caught my eye).

I can't comment on gfortran specifically, but be aware that code like  
this causes problems with many compilers. I have seen code like this  
literally crash what was a fairly large server for the time (well  
over a decade ago, so we wouldn't think it so large today) by running  
the server out of disk space. Even if you initialize only a few  
elements of an array, that tends to force the whole array to be  
treated as initialized space, and some compilers have issues with  
large amounts of initialized space, particularly if it is not all  
initialized to 0 or perhaps at least to all the same value. I think  
it ends up looking much like a separate initialization for each  
element; that is, in some sense the above can be as hard on the  
compiler as having half a million lines of code (one for each element).

Because this issue shows up in many compilers, I tend to recommend  
against that coding practice. Yes, it is standard conforming and yes,  
it would certainly be nice if any particular compiler, such as  
gfortran, handled it well. So if the gfortran folk can make it work  
well, that would be dandy. But I wouldn't code that way anyway, as  
I'd probably hit the same issue again with some other compiler.

I've been known to do workarounds such as initializing a small array  
with the non-zero values and then copy that small array to the right  
places in the big one with executable code that is executed only on  
the first call. Yes, it adds a little complication (though not much),  
but it makes the code run well on pretty much any compiler.

-- 
Richard Maine                |  Good judgment comes from experience;
Richard.Maine@nasa.gov       |  experience comes from bad judgment.
                             |        -- Mark Twain



More information about the Fortran mailing list