Usenet comp.unix.osf.osf1 (1992-2004)
 help / color / mirror / Atom feed
From: Craig Burley <burley@tweedledumb.cygnus.com>
Subject: Re: fortran error?
Date: 1998/03/23	[thread overview]
Message-ID: <y667l58b9x.fsf@tweedledumb.cygnus.com> (raw)
In-Reply-To: 3512FE4B.2781@still3.chem.columbia.edu


Peter Shenkin <shenkin@still3.chem.columbia.edu> writes:

> So I would stand by my assertion that *stack* resources were not and
> are not precomputed in F77 implementations that use a stack.  But I'm
> far from an expert on this and am willing to be corrected.  I agree with
> what you say, but do not think it contradicts this assertion.

I have to say I'm unaware of any F77 implementation that both used
the stack for Fortran code *and* precomputed the maximum stack
usage to ensure the program would not run out of memory.

It's worth remembering, though, that anyone wanting that behavior
would probably just compile with an option that meant "don't use
the stack", or use a compiler that didn't use the stack.  And,
for situations where the stack does get used, it is easy to
precompute a useful maximum for F77 programs.

> > There's no reason it has to be put on the stack.  There might not
> > even *be* a stack.
> 
> No, of course not.  In many compilers the user can even control whether
> stack or heap is used at compile time.  I'm just saying that when a
> stack is used, F77 implementations don't compute stack requirements
> and compare them at startup with available stack resources even when
> it would be easy to do so.

Okay, but how often do you think such implementations actually
overflowed the stack?  Remember the origins of this discussion --
I was pointing out that, while automatic arrays and the like make
stack overflow much more likely, they do *not* make it 100% likely
that any such overflow will occur while allocating *just* those
kinds of objects.  (But programmers might *think* they're getting
a 100% guarantee.)

So, my guess is that stack-overflow was a very rare problem for
F77 in the past, and easily fixable on a case-by-case or
comprehensive basis.  If nobody did the comprehensive version,
that suggests the problem was very rare indeed, since the
comprehensive version is technically straightforward.

> > I just don't think many people care about this sort of thing
> > these days.  When they run into a problem, it's fixed either
> > by adding memory (real cheap), fixing a memory leak in the
> > program, or adding specialized code to the program to detect
> > when *likely* candidates for running out of memory do so.
> 
> Well, in my case some were fixed by (1) going to dynamic allocation
> in the first place -- which is a standard-conforming way to minimize
> storage requirements -- and (2) replacing large automatics by
> ALLOCATABLEs where necessary.  There is nothing in the standard
> which makes it likely that (2) would be a good thing to do.  Doing
> it just constitutes an educated guess about what one's compiler is
> likely to do to an automatic, as opposed to an ALLOCATABLE.  Another
> compiler could do it differently.  This is why the lack of robust
> handling of automatics is problematic to me. 

Yes, in the 99% or so of cases where it's the automatic array that
overflows the stack, it'd be nice to have the language mandate
better handling of that.

Proper exception handling would presumably cover 100% of the cases,
though.

> ...
> . [[ As Sergio said, one ]]
> > answer is that Fortran needs a (IMO very robust) exception mechanism.
> 
> Yeah, but very general solutions are hard to devise, and it's hard
> to convince oneself ahead of time that any given proposal would (1)
> work, and (2) also accommodate future needs.

I'd be more worried about that if Fortran was to be the first language
to have general, robust exception handling, but I'm fairly reliable
informed that it won't be.

> > One trick, for example, before entering a region of code that might
> > crash due to implicitly allocated temporaries, is to allocate and
> > then deallocate a "guard" array of sufficient size to ensure that,
> > if it succeeds, then the implicit allocations will....
> 
> Well, since ALLOCATABLEs are usually allocated on the heap and
> automatics on the stack, the success of the explicit ALLOCATE() 
> doesn't guarantee the succuss of the subsequent implicit automatic
> allocation.

Yes, though I did mean using an automatic allocation (by calling
a specialized procedure), but, even there, the implementation
is free to choose different "pools" out of which to allocate
the "guard" region and the arrays you wish to guard against
overflowing on!  :)

> I do have to say that in C code, I have sometimes done this kind
> of thing;  what I've generally ended up with is early allocation
> of as much storage as I know I'll need before entering a time-consuming
> part of the program;  then I'll die right away, rather than a day
> later, as I would if I deferred my last request to just before
> the moment of actual use.

Absolutely agreed.  With C, you've got at least a practical, if
not iron-clad, guarantee that the compiler won't play around
with your calls to malloc() and free().
-- 

"Practice random senselessness and act kind of beautiful."
James Craig Burley, Software Craftsperson    burley@gnu.org



  reply	other threads:[~1998-03-23  5:00 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-03-12  5:00 fortran error? Armin Leuprecht
1998-03-12  5:00 ` robin
1998-03-16  5:00 ` Steve Lionel
1998-03-17  5:00   ` Peter Shenkin
1998-03-17  5:00     ` Craig Burley
1998-03-17  5:00       ` Peter Shenkin
1998-03-18  5:00         ` Toon Moene
1998-03-18  5:00           ` Jeff Drummond
1998-03-19  5:00           ` Peter Shenkin
1998-03-18  5:00         ` Craig Burley
1998-03-19  5:00           ` Peter Shenkin
1998-03-19  5:00             ` Craig Burley
1998-03-20  5:00               ` Nick Maclaren
1998-03-20  5:00               ` Peter Shenkin
1998-03-20  5:00                 ` Richard Maine
1998-03-20  5:00                 ` Craig Burley
1998-03-20  5:00                   ` Nick Maclaren
1998-03-20  5:00                     ` Richard Maine
1998-03-20  5:00                   ` Peter Shenkin
1998-03-23  5:00                     ` Craig Burley [this message]
1998-03-23  5:00                       ` Summary (I hope) failure of automatic allocation; was, " Peter Shenkin
1998-03-24  5:00                         ` Craig Burley
1998-03-23  5:00                       ` Craig Burley
1998-03-23  5:00                         ` Peter Shenkin
1998-03-24  5:00                           ` Craig Burley
1998-03-24  5:00                             ` Nick Maclaren
1998-03-20  5:00             ` Dick Hendrickson
1998-03-20  5:00               ` Craig Burley
1998-03-20  5:00                 ` Peter Shenkin
1998-03-23  5:00                   ` Craig Burley
1998-03-20  5:00               ` Peter Shenkin
1998-03-18  5:00     ` Steve Lionel
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox