Re: Fortran memory allocation (stack/heap) issues

From: Richard Maine (nospam_at_see.signature)
Date: 04/27/04


Date: 27 Apr 2004 13:35:16 -0700

Andy Nelson <andy@kant.maths.ed.ac.uk> writes:

> -Under what circumstances would one expect that the call
> might trigger a quantity to have a copyin/copyout sort of
> arrangement and what might trigger a call by reference sort
> of arrangement?

Compilers are free to vary, but as a general guide, the only
time you'll see copying is when the actual array might be
discontiguous. Namely, that's when the actual argument is a
pointer or an assumed shape dummy. From your description, you
don't have that (those are very much f90 features). There are
other conditions, but it all seems irrelevant to you if you
have described things correctly.

Basically, you rarely see array copying in f77. (It can happen,
but it is rare). You also don't tend to see it in what I would
call "pure" f90 style. You do get it from some attempts to
mix f77 and f90 styles.

> -There are also occasions when a routine might be called with
> one or the other npart=0 (see code below). As a completely
> separate question, my copy of M&R says zero length arrays are
> allowed, but I've run across compilers (can't remember which)
> where the code crashed on trying to enter a subroutine with such
> a situation, and worked when I changed the array declaration
> to a fixed parameter value. Did I do something weird
> or should I report a bug? (Maybe this description isn't
> specific enough for anyone to say for sure though...)

Zero-sized arrays are allowed in f90, but not in f77. I bet the
compilers in question were f77 ones.

  [code elided]

> The claim is that the phrasing above will lead to the
> variables getting defined on a stack,

Seems highly unlikely. I also don't see the suggested change
as likely to change anything.

One thing you might be running into has nothing to do with
argument passing. Non-saved local arrays might plausibly be
allocated on the stack. That includes "local" arrays in the main
program. Many compilers have options to change that behavior.

P.S. When do you get the stack overflow? Imediately on loading
the program or later? You should be able to get a hint from
when it happens.

-- 
Richard Maine                       |  Good judgment comes from experience;
email: my first.last at org.domain  |  experience comes from bad judgment.
org: nasa, domain: gov              |        -- Mark Twain


Relevant Pages

  • Re: Fortran memory allocation (stack/heap) issues
    ... you rarely see array copying in f77. ... so you can't be passing one that is ... GH>someone has set a small stack size. ... GH>subroutine) arrays that might be causing stack overflow. ...
    (comp.lang.fortran)
  • Re: the efficiency of STRUCTURE on SGI IRIX
    ... data on a IRIX machine with f77. ... since there are a large amount of groups ... here, about 10**6, and the number of sub groups diversifies between 0 ... arrays, I believe. ...
    (comp.lang.fortran)
  • Re: Copying Worksheets from one workbook to another
    ... the worksheets I'm planning on copying from a centralized file ... Rather than using arrays as arrays are kinda a generic form with ... references within VBA as data from our main database is brought into Excel ...
    (microsoft.public.excel.programming)
  • Re: Matlab to modify a text file?
    ... > looking at f95 as well and I think your point on arrays might get me out ... Today, w/ upto GBs of memory, is there any ... The two texts I have on f77 and f90 both failed to mention the ... There are compiler-specific compiler ...
    (comp.soft-sys.matlab)
  • Re: Fortran pros and cons (was Re: Coding style article with interesting section on white space)
    ... > than in f77, but it is not obviously more expressive or less complex. ... here are some simple examples of the greater expressiveness of ... Fortran 95 compared to F77 or C for calculations involving arrays. ... The ufunc of Numeric Python and the map of basic Python offer similar ...
    (comp.lang.python)