Re: Really wierd bug

From: Rich Townsend (rhdt_at_barVOIDtol.udel.edu)
Date: 08/18/04


Date: Wed, 18 Aug 2004 11:32:21 -0400

justabeginner wrote:
> Hi. I've written a simple program that optimises mathematical
> functions based on the principles of a genetic algorithm.
>
> The variables are population size, mutation rate, generations to
> create, etc.
>
> It works 99% of the time, and only fails once the population size is
> set to 70. Otherwise, it works for population sizes of 15, 69, 71,
> 100, 150, etc. I don't know what so special about 70 but I'm thinking
> it has to be a compiler bug because it works fine for other population
> sizes as indicated above.
>
> The error I get is:
> "forrtl: severe (161): Program Exception - Array Bounds Exceeded".
>
> My compiler is Compaq Visual Fortran 1997-1999. It has nothing to do
> with allocating the array sizes because I've defined the arrays as
> allocatable in size and the program allocates space depending on the
> population size.
>
> I've attached the program below for those who are interested in taking
> a look. I've located the offending line causing the error; just search
> for and jump to keyword 'ERROR'. It is between 2 print statements.

<snip program>

Hi --

I've tried compiling your code using the Lahey lf95 compiler. Firstly,
you have a bug on line 326 -- an extra comma after '(1,*)'.

Secondly, your program does indeed contain an array bounds error -- this
is not a compiler bug. Running with a population size of 70, I get the
following error (with array-bounds checking enabled):

The subscript or substring population is out of the specified range
(reference value: 2,0,1, specification value: 1:13,1:70,1:2).
  Error occurs at or near line 222 of MAIN__

You have correctly identified the offending line as:

population(i+1,j,2) = population(i+1,select2,1)

The problem is occuring because, for some reason, your subscript select2
has the value zero. I suggest you find out what is causing this.

Other points worth noting: the variables gencount, generations and
prev_fit are not declared anywhere in the code. This may well be a
mistake, since implicit typing rules will mean that both gencount and
generations are declared as REAL rather than INTEGER. To avoid making
mistakes like this, you should put an 'implicit none' at the top of each
program/subroutine/function.

Finally, I've tried running your code using undefined variable checking.
This produces the runtime error:

The variable (population(10,1,1)) has an undefined value.
  Error occurs at or near line 90 of MAIN__

I suggest that you make sure the population array is properly
initialized before you reference it.

cheers,

Rich

-- 
Dr Richard H D Townsend
Bartol Research Institute
University of Delaware
[ Delete VOID for valid email address ]


Relevant Pages

  • Re: new algorithm
    ... > Is this compiler specific or defined by the standard?? ... are using the allocating new rather than the placement new) followed by ... array, a constructor is called for each element of the array as ...
    (comp.lang.cpp)
  • Re: ALLOCATABLE arrays
    ... If try to create a very large array on the stack and you do not have enough ... stack (set up in the linking step of the compiler i think) then you program ... Allocating on the heap gives you access to a hell of a lot more memory (well ...
    (comp.lang.fortran)
  • Re: VS .NET 2003 hangs while "Generating Code..."
    ... it certainly smells like a serious compiler bug. ... elements do you put them in an array, and you know how many elements you need in the ... But it appears that a very large function is tweaking some sort of compiler bug. ... >builds fine and release with no optimizations builds fine. ...
    (microsoft.public.vc.mfc)
  • Re: Array reinitialize
    ... |>> considered to be nul terminated, when initialising ... |>> when providing an array size to boot. ... | thought it might be a C++ compiler bug until I looked it up in the ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Allocating arrays inside a subroutine.
    ... [on allocating an array in a subroutine] ... get the job done (my compiler doesn't support "extended allocatables", ... To the extent that the subroutine always deals with the same array, ...
    (comp.lang.fortran)