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


Craig Burley wrote:
> 
> Peter Shenkin <shenkin@still3.chem.columbia.edu> writes:
...
> > But the even simpler analysis of determining the stack resources
> > required for each subroutine, and refusing to start if the stack was
> > too small, was never, as far as I know, done.
> 
> Oh, sure it was, in *effect* if not explicitly.
> 
> On some now-ancient machines, you compiled your Fortran modules,
> you linked them together, and you got an executable.  If it was
> too big, you couldn't run it in a given amount of memory

First, I mostly agree with you.  In F77 this wasn't nearly as much
of a problem.  But regarding the above quotations:  yes, what you
say is true, and still is true on many machines.  But this behavior
did *not* take stack growth into account.  Many Fortran compilers
allocated everything -- including local variables -- statically on
the heap.  It was still possible, in principle, in many cases to
die because of a stack overflow if the call tree was too deep.  Of
course, this would rarely happen.
  
Further, other compilers, which allocated locals on the stack, would
still fail to start up if the globals on the heap exceeded available
storage, but would then die if some local variable allocated on the
stack blew that stack.

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.

...
> > For instance, if
> > some subroutine declared a local as "REAL A(100000000)", and if
> > locals are allocated on the stack, and if there is not enough stack
> > space for 10^8 reals, it should be possible, in principle for the
> > run-time system to refuse to start up the program, rather than to
> > incur a SEGV when the subroutine is entered.
> 
> 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.

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

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.

	-P.

-- 
************** In memoriam, Grandpa Jones, 1913-1998, R.I.P.
**************
* Peter S. Shenkin; Chemistry, Columbia U.; 3000 Broadway, Mail Code
3153 *
** NY, NY  10027;  shenkin@columbia.edu;  (212)854-5143;  FAX: 678-9039
***
*MacroModel WWW page:
http://www.columbia.edu/cu/chemistry/mmod/mmod.html *



  parent reply	other threads:[~1998-03-20  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         ` Craig Burley
1998-03-19  5:00           ` Peter Shenkin
1998-03-19  5:00             ` Craig Burley
1998-03-20  5:00               ` Peter Shenkin
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 [this message]
1998-03-23  5:00                     ` Craig Burley
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                 ` Richard Maine
1998-03-20  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         ` Toon Moene
1998-03-18  5:00           ` Jeff Drummond
1998-03-19  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