informational question: compile time of large DATA arrays

Richard E Maine Richard.Maine@nasa.gov
Mon Sep 11 16:36:00 GMT 2006


On Sep 11, 2006, at 8:56 AM, Daniel Franke wrote:
> 2006/9/11, Richard E Maine <Richard.Maine@nasa.gov>:
>> I can't comment on gfortran specifically, but be aware that code like
>> this causes problems with many compilers.
> the only one I could give a try was ifort - I had to abort the
> compilation after six hours , gfortran finished in four and a half
> hours ...

I haven't tried code like that with either of those two compilers,  
but that sounds like you just verified that my comment, which had  
been based on older compilers, still applies.

> Here, I tried to fill the grid completely with precomputed values, the
> (generated) source file had 500.000+ lines. I am all ears (or eyes) if
> you or someone else could suggest a better way to initialize such an
> array?!

Ah. I had been thinking of the case where the number of elements that  
needed explicit values was small. If you really have half a million  
values, then I'd strongly advocate putting them in a data file  
instead of in the source code. Have code that executes one time only  
(lots of ways to arrange that) to read the data file into the array.

For the execute-once code, the 2 basic ways to do it are either

1. Explicitly call it once somewhere early in the main program, or in  
some other appropriate place.

2. Something like

    logical, save :: initialized = .false.
    ...
    if (.not. initialized) then
      ... do it
     initialized = .true.
   end if

   Or any of many variations on that theme. I often have the  
"initialized" variable at module scope and then have the single  
statement

   if (.not. initialized) call do_initialization

in each routine where it might be needed. That statement doesn't add  
enough overhead to measure unless you are really in the very  
innermost and very tight loop of something (in which case, you'd want  
to have made sure to do it earlier).

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