* fortran error?
@ 1998-03-12 5:00 Armin Leuprecht
1998-03-12 5:00 ` robin
1998-03-16 5:00 ` Steve Lionel
0 siblings, 2 replies; 32+ messages in thread
From: Armin Leuprecht @ 1998-03-12 5:00 UTC (permalink / raw)
Dynamic allocation using DEC Fortran is working in general.
For some strange reason sometimes a programm like the following
will crash with a segmentation fault while allocating the memory
in line 3 of the subroutine.
Though I couldn't reproduce the error with this little program
(not even for large values, i.e. more than physical installed
memory) I cannot locate another source of failure in my application.
SUBROUTINE sub(n)
INTEGER n
REAL*4 a(n)
END
PROGRAM test
INTEGER n
n = 1234
CALL sub(n)
END
My application is of course more complex so that I can't post it
as whole. The subroutine looks like this:
SUBROUTINE name (n, a, x, b)
INTEGER n
REAL a(*), x(*), b(*)
c *** local variables
REAL p(n)
REAL r(n)
REAL s(n)
REAL t(n)
REAL z(n)
...
in fact there are 10 such arrays dimensioned with n, and regardless of
the order of variables, the program crashes while allocating memory for
the sixth array.
So it seems to depend on the amount of requested memory.
We had no problem with that subroutine before the operating system
upgrade from V2.1 to V3.2
My OS: OSF1 V3.2 148 alpha
My Compiler: DEC Fortran for OSF/1 AXP Systems version T3.6
thanks for any advice
Armin
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: fortran error?
1998-03-12 5:00 fortran error? Armin Leuprecht
@ 1998-03-12 5:00 ` robin
1998-03-16 5:00 ` Steve Lionel
1 sibling, 0 replies; 32+ messages in thread
From: robin @ 1998-03-12 5:00 UTC (permalink / raw)
Armin Leuprecht <leu@matd.tu-graz.ac.at> writes:
>Dynamic allocation using DEC Fortran is working in general.
>For some strange reason sometimes a programm like the following
>will crash with a segmentation fault while allocating the memory
>in line 3 of the subroutine.
>Though I couldn't reproduce the error with this little program
>(not even for large values, i.e. more than physical installed
>memory) I cannot locate another source of failure in my application.
> SUBROUTINE sub(n)
> INTEGER n
> REAL*4 a(n)
> END
> PROGRAM test
> INTEGER n
> n = 1234
> CALL sub(n)
> END
>My application is of course more complex so that I can't post it
>as whole. The subroutine looks like this:
> SUBROUTINE name (n, a, x, b)
> INTEGER n
> REAL a(*), x(*), b(*)
>c *** local variables
> REAL p(n)
> REAL r(n)
> REAL s(n)
> REAL t(n)
> REAL z(n)
>...
>in fact there are 10 such arrays dimensioned with n, and regardless of
>the order of variables, the program crashes while allocating memory for
>the sixth array.
>So it seems to depend on the amount of requested memory.
>We had no problem with that subroutine before the operating system
>upgrade from V2.1 to V3.2
>My OS: OSF1 V3.2 148 alpha
>My Compiler: DEC Fortran for OSF/1 AXP Systems version T3.6
>thanks for any advice
>Armin
Programs that exhibit erratic behaviour are more likely to have
a subscript error.
The request for automatic storage for 6 arrays of
size 1234 each cannot be considered to be demanding.
Your program uses assumed size dummy arrays for subroutine
"name" (x, a, b)
rather than assumed shape arrays. Subscript checking is
not generally carried our for assumed size arrays, whereas
it usully can be requested and applied for assumed shape.
Have you considered substituting assumed shape
arrays and turning on subscript checking?
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: fortran error?
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
1 sibling, 1 reply; 32+ messages in thread
From: Steve Lionel @ 1998-03-16 5:00 UTC (permalink / raw)
In article <3507A4A5.F8A7DDC2@matd.tu-graz.ac.at>, Armin Leuprecht <leu@matd.tu-graz.ac.at> writes:
|>Dynamic allocation using DEC Fortran is working in general.
|>For some strange reason sometimes a programm like the following
|>will crash with a segmentation fault while allocating the memory
|>in line 3 of the subroutine.
|>Though I couldn't reproduce the error with this little program
|>(not even for large values, i.e. more than physical installed
|>memory) I cannot locate another source of failure in my application.
|>
|> SUBROUTINE sub(n)
|> INTEGER n
|> REAL*4 a(n)
|> END
|>
|> PROGRAM test
|> INTEGER n
|> n = 1234
|> CALL sub(n)
|> END
This is not really "dynamic allocation" - a term usually reserved for
variables allocated with ALLOCATE (or malloc). What you have instead
are "automatic arrays", which get allocated on the stack on routine
entry. This requires sufficient stack space. Unfortunately, the default
stacksize limit on DIGITAL UNIX (OSF/1) tends to be on the small side and
it is easy to exceed it with modest programs. Usually, the shell command:
limit stacksize unlimited
(or "ulimit", depending on what your shell is), will take care of this. This
does not actually set the size to be "unlimited", but rather raises it to
the system configuration maximum.
While I'm here, I'll mention that you can see the same problem using
DIGITAL Visual Fortran, since the MS linker allocates the stack at a fixed
size. You can set the stack size in a linker option. It tends NOT to be
a problem on OpenVMS which has done automatic stack expansion since 1980.
--
Steve Lionel mailto:Steve.Lionel@digital.com
Fortran Development http://www.digital.com/info/slionel.html
Digital Equipment Corporation
110 Spit Brook Road, ZKO2-3/N30
Nashua, NH 03062-2698 "Free advice is worth every cent"
For information on DIGITAL Fortran, see http://www.digital.com/fortran
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: fortran error?
1998-03-16 5:00 ` Steve Lionel
@ 1998-03-17 5:00 ` Peter Shenkin
1998-03-17 5:00 ` Craig Burley
1998-03-18 5:00 ` Steve Lionel
0 siblings, 2 replies; 32+ messages in thread
From: Peter Shenkin @ 1998-03-17 5:00 UTC (permalink / raw)
Steve Lionel wrote:
>
> In article <3507A4A5.F8A7DDC2@matd.tu-graz.ac.at>, Armin Leuprecht <leu@matd.tu-graz.ac.at> writes:
...
> |>For some strange reason sometimes a programm like the following
> |>will crash with a segmentation fault...
> |> SUBROUTINE sub(n)
> |> INTEGER n
> |> REAL*4 a(n)
> |> END
...
> ... What you have
> are "automatic arrays", which get allocated on the stack on routine
> entry. This requires sufficient stack space. Unfortunately, the default
> stacksize limit on DIGITAL UNIX (OSF/1) tends to be on the small side and
> it is easy to exceed it with modest programs. Usually, the shell command:
>
> limit stacksize unlimited
>
> (or "ulimit", depending on what your shell is), will take care of this.
...
I would really like to see an addition to the standard which requires
inability to "allocate" an automatic to be treated similarly to
the treatment of inability to ALLOCATE an ALLOCATABLE when no STATUS
variable is supplied: namely, stop the program with a descriptive
error message. I believe the Absoft compilers do this (at least
the LINUX one.)
Quality of implementation should demand even more than this: if
an automatic cannot be "allocated" on the stack, the run-time system
should allocate it on the heap. Even a compile-time option that
allows a size threshold to be specified for heap, rather than stack,
allocation of automatics would be a step in the right direction.
Cray gives us this feature for the Cray (not the SGI) platform.
Thus, there would seem to be precedent for several solutions that
are better than the one supplied by DEC and most other F90 systems.
DEC is no worse than average here; I have the same problem with SGI.
But all these implementations are sadly lacking in this regard, IMHO.
To add to the problem, the SEGV that is generated by this sort of
error is generally untrappable, since signals are handled on the
stack (at least in UNIX). Once the stack has been blown, a signal
handler can't trap the SEGV. The net effect is that if your customer
is running with a small stack size -- and he may even be unaware he
is doing so, as Armin was -- he gets a SEGV and a core dump, and
thinks your program has a bug. Feh.
-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 *
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: fortran error?
1998-03-17 5:00 ` Craig Burley
@ 1998-03-17 5:00 ` Peter Shenkin
1998-03-18 5:00 ` Craig Burley
1998-03-18 5:00 ` Toon Moene
0 siblings, 2 replies; 32+ messages in thread
From: Peter Shenkin @ 1998-03-17 5:00 UTC (permalink / raw)
Craig Burley wrote:
>
> Peter Shenkin <shenkin@still3.chem.columbia.edu> writes:
>
> > I would really like to see an addition to the standard which requires
> > inability to "allocate" an automatic to be treated similarly to
> > the treatment of inability to ALLOCATE an ALLOCATABLE when no STATUS
> > variable is supplied: namely, stop the program with a descriptive
> > error message. I believe the Absoft compilers do this (at least
> > the LINUX one.)
...
> Yes, like you might, I can certainly expound on many reasons I
> know of, having expertise in *those* topics, that your suggestions
> are infeasible or, at least, would be unpopular among Fortran
> implementors of most any stripe.
>
> However, as someone whose seen this issue come up over and over
> again for, well, decades, in various guises, I can really only
> say "Hallelujah!" and, then, "...we'll figure out later how
> to make it work reliably *and* fast".
As I pointed out, there is precedence in existing compilers for
several of the proposed solutions.
One of these was a compile-time flag for a size threshold to force
allocation of large automatics on the heap. In this scenario, the
program writer knowingly and explicitly chooses to trade speed
for reliablility. Yes, this requires a runtime test, but the
Cray isn't exactly a slouch when it comes to execution speed, and
it is Cray who implements this feature.
I suspect it's not less efficient, or not much less efficient, or
even more efficient, to test whether the unused part of the stack
is large enough to hold the automatics that needs to fit there, and
abort the program with a descriptive message if there's not.
Furthermore, the Fortran standard does not have the concept of
"stack" and "heap", and from the point of view of the language
definition, the absence of a mechanism for handling errors
due to too-large automatics is a glaring omission.
VMS has always been known to run Fortran codes "fast", and Steve
Lionel mentioned that VMS has had a dynamically growable stack
since 1980. Certainly, some of the precedents I cited would be
be more efficient than that.
...
> In the meantime, maybe someone can look into fixing Linux so its
> default behavior for handling SEGV that seems to involve a
> stack overflow includes printing some message like "stack
> overflow".
I don't know where this comment comes from; it's certainly not
properly in response to anything I said -- but perhaps it was
not intended to be.
The Absoft compiler under LINUX is the only one I know that
terminates the program gracefully with a descriptive message
when allocation of an automatic fails. In fact, no UNIX system
I've ever encountered delivers the message you propose. Can
you cite one that does?
Finally, if this can be done, then your proposal is not too bad
a match for the suggestion of mine that you deprecate: namely,
that a descriptive message be printed if allocation of an automatic
fails due to unavailability of resources. In fact, I suppose
I would settle for your less precise diagnostic; it would be
better than what we have now. But if your suggestion can be
carried out efficiently, I suspect mine can be carried out nearly
as efficiently. To UNIX, however, all SEGVs are created equal.
> (As far as systems that cannot handle invoking user-defined
> signal handlers when the stack overflow...well, I don't think
> I'm used to that, guess there's not as much call for that
> sort of thing as there was long ago.
Perhaps it would be slower. This, following your line of
reasoning, would be a good reason for not doing it.
With automatic arrays likely to become a feature of ANSI C (under
the name "variable-length arrays"), I suspect that omission of a
more user-friendly mechanism than we now have to handle stack
overruns will be seen as as a severe quality-of-implementation
deficit. People who need to supply reliable code to customers
will demand it, and will be willing to pay for it with a small
amount of execution time. This price, while not nill, is likely
to be less than the robust alternative of using local ALLOCATABLEs
instead of automatics.
For those who want maximum speed for their in-house research
applications, perhaps this sort of "feature" could be turned off.
I suspect, however, that one or two runtime tests per procedure
call are not going to kill the performance of a typical program.
-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 *
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: fortran error?
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 ` Steve Lionel
1 sibling, 1 reply; 32+ messages in thread
From: Craig Burley @ 1998-03-17 5:00 UTC (permalink / raw)
Peter Shenkin <shenkin@still3.chem.columbia.edu> writes:
> I would really like to see an addition to the standard which requires
> inability to "allocate" an automatic to be treated similarly to
> the treatment of inability to ALLOCATE an ALLOCATABLE when no STATUS
> variable is supplied: namely, stop the program with a descriptive
> error message. I believe the Absoft compilers do this (at least
> the LINUX one.)
>
> Quality of implementation should demand even more than this: if
> an automatic cannot be "allocated" on the stack, the run-time system
> should allocate it on the heap.
Ah, a voice of sanity, clearly unfettered by any in-depth knowledge
of popular computer architectures, operating systems, or compiler
code-generation techniques. ;-)
Yes, like you might, I can certainly expound on many reasons I
know of, having expertise in *those* topics, that your suggestions
are infeasible or, at least, would be unpopular among Fortran
implementors of most any stripe.
However, as someone whose seen this issue come up over and over
again for, well, decades, in various guises, I can really only
say "Hallelujah!" and, then, "...we'll figure out later how
to make it work reliably *and* fast".
(In short, the problem is this: on most systems, dynamically
allocating and later deallocating space on the stack is very fast,
*especially* if you don't care about elegantly catching the
situation where there isn't enough space on the stack. Mandating
that Fortran implementations provide a more-elegant diagnostic for
this requires either a somewhat slower mechanism, or more, perhaps
much more, cooperation from some combination of the linker,
operating system, or CPU and its architecture.)
In the meantime, maybe someone can look into fixing Linux so its
default behavior for handling SEGV that seems to involve a
stack overflow includes printing some message like "stack
overflow".
(As far as systems that cannot handle invoking user-defined
signal handlers when the stack overflow...well, I don't think
I'm used to that, guess there's not as much call for that
sort of thing as there was long ago. Certainly there's no
real technical impediment to it I can think of.)
--
"Practice random senselessness and act kind of beautiful."
James Craig Burley, Software Craftsperson burley@gnu.org
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: fortran error?
1998-03-17 5:00 ` Peter Shenkin
1998-03-18 5:00 ` Craig Burley
@ 1998-03-18 5:00 ` Toon Moene
1998-03-18 5:00 ` Jeff Drummond
1998-03-19 5:00 ` Peter Shenkin
1 sibling, 2 replies; 32+ messages in thread
From: Toon Moene @ 1998-03-18 5:00 UTC (permalink / raw)
[ I hope I can add some bits to this discussion, but might
raise more questions instead ... ]
Peter Shenkin <shenkin@still3.chem.columbia.edu> wrote:
[ ... about the allocation of automatic arrays ... ]
> One of these was a compile-time flag for a size threshold to force
> allocation of large automatics on the heap. In this scenario, the
> program writer knowingly and explicitly chooses to trade speed
> for reliablility. Yes, this requires a runtime test, but the
> Cray isn't exactly a slouch when it comes to execution speed, and
> it is Cray who implements this feature.
It's not suprising Cray implemented such a feature, because, AFAIK, Cray PVP
systems do not have a stack as such - the "stack" is also managed as a heap.
Perhaps Jeff Drummond or one of the other Crayons listening in can elaborate
on this point.
> I suspect it's not less efficient, or not much less efficient, or
> even more efficient, to test whether the unused part of the stack
> is large enough to hold the automatics that needs to fit there, and
> abort the program with a descriptive message if there's not.
The point often is not that the stack isn't large enough, but that the system
(either by default or because the user set a limit) doesn't "allow" the stack
to grow beyond a certain limit.
Note that:
> VMS has always been known to run Fortran codes "fast", and Steve
> Lionel mentioned that VMS has had a dynamically growable stack
> since 1980. Certainly, some of the precedents I cited would be
> be more efficient than that.
and most Unices do it that way too: Have a "guard page" (with no access
rights) at the end of the stack area to get the OS in charge when you overrun
the stack and let it decide whether to enlarge stack or give you an "access
violation". Note how this hints that such an error should be given a more
descriptive name, as the OS itself knows what's wrong.
> The Absoft compiler under LINUX is the only one I know that
> terminates the program gracefully with a descriptive message
> when allocation of an automatic fails. In fact, no UNIX system
> I've ever encountered delivers the message you propose. Can
> you cite one that does?
That's neat, it means they either allocate on a heap (were they can trace the
amount of memory allocated), or they translate the "segmentation violation"
that results from overrunning stack limits in the appropriate message: that
means they have to have a sure fire means to discriminate between this
failure and a "generic" segmentation violation.
--
Toon Moene (mailto:toon@moene.indiv.nluug.nl)
Saturnushof 14, 3738 XG Maartensdijk, The Netherlands
Phone: +31 346 214290; Fax: +31 346 214286
g77 Support: mailto:fortran@gnu.org; NWP: http://www.knmi.nl/hirlam
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: fortran error?
1998-03-18 5:00 ` Toon Moene
@ 1998-03-18 5:00 ` Jeff Drummond
1998-03-19 5:00 ` Peter Shenkin
1 sibling, 0 replies; 32+ messages in thread
From: Jeff Drummond @ 1998-03-18 5:00 UTC (permalink / raw)
In article <6eopju$pfi$2@news.utrecht.NL.net>, Toon Moene <toon@moene.indiv.nluug.nl> writes:
|> [ I hope I can add some bits to this discussion, but might
|> raise more questions instead ... ]
|>
|> Peter Shenkin <shenkin@still3.chem.columbia.edu> wrote:
|>
|> [ ... about the allocation of automatic arrays ... ]
|>
|> > One of these was a compile-time flag for a size threshold to force
|> > allocation of large automatics on the heap. In this scenario, the
|> > program writer knowingly and explicitly chooses to trade speed
|> > for reliablility. Yes, this requires a runtime test, but the
|> > Cray isn't exactly a slouch when it comes to execution speed, and
|> > it is Cray who implements this feature.
|>
|> It's not suprising Cray implemented such a feature, because, AFAIK, Cray PVP
|> systems do not have a stack as such - the "stack" is also managed as a heap.
|> Perhaps Jeff Drummond or one of the other Crayons listening in can elaborate
|> on this point.
Yes, that is correct. On Cray PVP systems the stack is just a flock of
heap segments that have been wrestled to the ground and lashed together
with a bunch of #8 pointers. The process of pushing anything on the
stack requires a not insignificant amount of code to (a) check if there's
room in the current segment and, if not, (b) allocate a new segment and
link it to the existing segment(s). [This is, incidently, what makes
implementing alloca() on Cray PVP systems an ultimate exercise in
futility.]
One consequence of all this is that as the size of your allocatable
object increases, it actually becomes easier (i.e., faster) to allocate
it directly from the heap rather than on the stack (which is not the
case on most architectures). Thus, the option to force allocation of
large automatics on the heap is not quite the trade of speed for
reliability that Mr. Shenkin supposes. Rather, it was probably created
as a performance enhancement (the error message you get is the same in
either case).
But regardless of all these behind-the-scenes machinations, the basic
plea for getting a descriptive error message when something goes
wrong is certainly understandable. Two points:
1) Doing graceful error recovery when you run out of memory (especially
stack space) can be problematic.
2) Most newer architectures allow the actual mechanics of memory
allocation to be hidden in the operating system. They have
segmented memory mapping which permits the OS to expand memory
"invisibly" by trapping segment violations and making additional
memory segments available. This means that expanding the stack
typically reduces to a simple register increment, and makes stack
pushes/pops trivial for the implementor (compare and contrast
with the Cray PVP method I outlined above).
Thus, allocating memory in this fashion doesn't really do anything
(that is, nothing is actually allocated--and won't be unless/until
it is actually referenced). This is fine as long as the memory
will be available when needed, but otherwise the program will
likely be far, far away from the point of allocation when the
error finally comes home to roost. Hence, the ubiquitous
'segmentation fault' error message you see on so many systems.
Of course, there's no reason why a library or OS primitive couldn't
be provided to ensure that X amount of memory was actually present
before proceding (or return an error indication if it was not
available). This would at least allow memory allocation "routines"
to issue a descriptive error message.
-Jeff jjd@cray.com
--
"Segmentation fault
Insufficient memory
You lose, plum blossom."
-Haikunix 3.2 error message
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: fortran error?
1998-03-17 5:00 ` Peter Shenkin
@ 1998-03-18 5:00 ` Craig Burley
1998-03-19 5:00 ` Peter Shenkin
1998-03-18 5:00 ` Toon Moene
1 sibling, 1 reply; 32+ messages in thread
From: Craig Burley @ 1998-03-18 5:00 UTC (permalink / raw)
Peter Shenkin <shenkin@still3.chem.columbia.edu> writes:
> Craig Burley wrote:
> >
> > Peter Shenkin <shenkin@still3.chem.columbia.edu> writes:
> >
> > > I would really like to see an addition to the standard which requires
> > > inability to "allocate" an automatic to be treated similarly to
> > > the treatment of inability to ALLOCATE an ALLOCATABLE when no STATUS
> > > variable is supplied: namely, stop the program with a descriptive
> > > error message. I believe the Absoft compilers do this (at least
> > > the LINUX one.)
>
> ...
> > Yes, like you might, I can certainly expound on many reasons I
> > know of, having expertise in *those* topics, that your suggestions
> > are infeasible or, at least, would be unpopular among Fortran
> > implementors of most any stripe.
> >
> > However, as someone whose seen this issue come up over and over
> > again for, well, decades, in various guises, I can really only
> > say "Hallelujah!" and, then, "...we'll figure out later how
> > to make it work reliably *and* fast".
I gather from Pete's reply that my paragraph (above) wasn't clear
enough. I agree 100% with what Pete proposes regarding the
Fortran language/standard, IMO it's just a matter of the
implementors making it work. If whatever results is too slow for
some users in some situations, they can use directives to disable
the facilities in question. But also IMO better compiler and
linker technology can optimize away most, maybe all, of the run-time
checking that would otherwise done.
The way I look at it, stack allocation is almost *never* a
bottleneck in any real application, but *heap* allocation often
is. If Fortran users wanted straight-out speed at the cost of
inadequate detection of running code, there'd be no reason to
mandate elegant detection of any kind for detecting *heap*
overflows! (In practice, few applications where heap allocation
are likely to be written in Fortran -- maybe C, C++, Lisp, etc.,
but not usually Fortran, but that's just IMO.)
So, the only reason I can think of that stack allocation isn't
required to be as robust as heap allocation in Fortran is that
implementors knew how they wanted to implement stack allocation
(which, as Peter correctly points out, isn't really called that
in the Fortran standard, so it *can* be done on the heap in
practice), so it didn't occur to them, or they didn't want to
think, to require that *all* dynamic allocation behave the same
way when the allocation cannot be carried out.
E.g. it might even have made some sense to provide a facility like
REAL, STATUS=ISTAT:: A(N)
to specify "if you can't dynamically allocate an N-element array
named A, instead of bombing with a nice diagnostic, set ISTAT to
some non-zero value, else allocate A and set ISTAT to zero".
That wouldn't be used real often (maybe less often than ALLOCATE's
STATUS arg), but it would be a bit more consistent perhaps. Even
without this facility, the nice diagnostic would be the key thing!
> I suspect it's not less efficient, or not much less efficient, or
> even more efficient, to test whether the unused part of the stack
> is large enough to hold the automatics that needs to fit there, and
> abort the program with a descriptive message if there's not.
I agree, and, to me, the point is that the *standard* (or default)
behavior should be to incur a bit less extra overhead, if necessary,
to produce a nice diagnostic. If that last little bit of performance
really needs to be squeezed out, compiler/linker technology can be
improved generally, and the user can be given a compiler/linker
option to dismiss the detection facilities for use in specific
instances.
> Furthermore, the Fortran standard does not have the concept of
> "stack" and "heap", and from the point of view of the language
> definition, the absence of a mechanism for handling errors
> due to too-large automatics is a glaring omission.
Exactly.
> VMS has always been known to run Fortran codes "fast", and Steve
> Lionel mentioned that VMS has had a dynamically growable stack
> since 1980. Certainly, some of the precedents I cited would be
> be more efficient than that.
I'm not quite sure I know why you conclude that -- on some
architectures and OSes, the dynamically growable stack is
not really at all inefficient, I believe.
> > In the meantime, maybe someone can look into fixing Linux so its
> > default behavior for handling SEGV that seems to involve a
> > stack overflow includes printing some message like "stack
> > overflow".
>
> I don't know where this comment comes from; it's certainly not
> properly in response to anything I said -- but perhaps it was
> not intended to be.
I forget what I was responding to, but don't think it was your
comment about Absoft under Linux. I do know I've run into
this problem myself under Linux, and had to document it
as a non-intuitive thing to consider in the g77 docs, but
I think an earlier post might have made more specific reference
to this issue.
> The Absoft compiler under LINUX is the only one I know that
> terminates the program gracefully with a descriptive message
> when allocation of an automatic fails. In fact, no UNIX system
> I've ever encountered delivers the message you propose. Can
> you cite one that does?
Not offhand, but I'm not a UNIX expert. Maybe the problem is
that SEGV is too widely assumed to be *the* (software-level)
signal for relevant errors, so adding a new one to indicate
stack overflow is impractical. Certainly under PRIMOS, the only
system I really knew extremely well (and that long ago), the
exception-handling mechanism was quite mature (in design, at
least), coming from the Multics background that largely influenced
the hardware and software, so if you got a stack overflow, you
usually knew it (but the stack could *usually* grow dynamically,
so...). And, you *could* catch it and continue running, if you
wanted, and even catch a stack overflow in *that* exception, etc.
(It was a lot of "fun" to write code for, in some ways. ;-)
> Finally, if this can be done, then your proposal is not too bad
> a match for the suggestion of mine that you deprecate: namely,
> that a descriptive message be printed if allocation of an automatic
> fails due to unavailability of resources. In fact, I suppose
> I would settle for your less precise diagnostic; it would be
> better than what we have now. But if your suggestion can be
> carried out efficiently, I suspect mine can be carried out nearly
> as efficiently. To UNIX, however, all SEGVs are created equal.
Again, I was *not* deprecating your suggestion, rather, trying to
find a politick (and somewhat humorous) way to suggest that it
was only us implementors who would tend to brush it off, and that
I, as an implementor, saw no valid reason to do so. I hadn't
wanted to get into a discussion of all the possible implementation
issues, though.
What I don't understand is how your solution of "stop the program
with a descriptive error message" substantially differs from mine
of "have the error message that gets printed when a program stops
(under Linux) due to overflowing the stack be more descriptive".
Any clarification would be welcome. (Of course, I realize that
fixing Linux is *not* the same as fixing the standard! My point
is that, if Linux can be fixed, that's a strong argument *against*
not fixing the standard as you propose on the theory that "it would
be too hard and inefficient".)
> > (As far as systems that cannot handle invoking user-defined
> > signal handlers when the stack overflow...well, I don't think
> > I'm used to that, guess there's not as much call for that
> > sort of thing as there was long ago.
>
> Perhaps it would be slower. This, following your line of
> reasoning, would be a good reason for not doing it.
No, following *my* line of reasoning, it would be a reasonable
*cost* for an important feature...just as catching the case where
*heap* allocation cannot proceed (due to fragmentation or
too little free memory, whatever) has got to cost *some* cycles
in heap-intensive applications. IMO, it's up to the implementors
to improve the technology to make it fast enough.
This *is* a bit different an issue from array bounds checking,
but the same thing applies: the implementors *can* improve the
technology to make enabling the feature faster than when done
the "naive" way, and if users (or the standard, in the case
of your stack-allocation proposal) demand both the feature and
high performance, I think I know enough about the technical
issues involved to say that they can and will get both.
> With automatic arrays likely to become a feature of ANSI C (under
> the name "variable-length arrays"), I suspect that omission of a
> more user-friendly mechanism than we now have to handle stack
> overruns will be seen as as a severe quality-of-implementation
> deficit. People who need to supply reliable code to customers
> will demand it, and will be willing to pay for it with a small
> amount of execution time. This price, while not nill, is likely
> to be less than the robust alternative of using local ALLOCATABLEs
> instead of automatics.
Agreed. Quite a long time ago, when this issue came up, I sent
Steve Lionel some email pointing out pretty much what you're saying
-- though more along the lines that, *internally*, stack allocation
could be viewed as an optimization, and use of that optimization
perhaps should defer to *not* using it if doing so will allow
a program to continue running. I don't think he responded, probably
because it was mostly just speculation as to how Fortran compilers
should work by default (in a quality-of-implementation sense),
but I could dig it out of my archives and post it here (at least
my original material) if desired.
(I have some concerns with any switching from stack to heap
allocation that is based on anything *other* than "stack allocation
of this object is impossible given the current stack situation",
however, which I won't go into here, and since my ideal
basis might be hard or nearly impossible, or too slow, to
determine, I'm not saying this approach is a panacea.)
> For those who want maximum speed for their in-house research
> applications, perhaps this sort of "feature" could be turned off.
Exactly.
> I suspect, however, that one or two runtime tests per procedure
> call are not going to kill the performance of a typical program.
Especially if those tests are only to determine whether to
stop and print a nice diagnosis if "safe" allocation on the
stack cannot be assured. (Other stuff might be quite
expensive to determine in enough cases to be problematic.)
Note that all this is moot if stack allocation happens to fail
on *procedure* invocation, which of course can happen on most
systems, since the stack is not just where local "user" data
goes!
Perhaps that's where the *real* problem is -- verifying that
each and every "call" instruction (or signal, for the day
when we get exceptions) will either succeed or will produce
a clean diagnostic. That might become more than one or two
instructions per stack allocation of a user variable -- it
might become one or two (or more) per *call* (plus any
implementation-chosen stack allocation, e.g. to implement
arbitrary CHARACTER expressions or I/O).
And this is where I begin to wonder if whether even the
behavior of ALLOCATE (with or without STATUS=) is all that
worthwhile. That is, maybe the problem isn't that stack
allocation *doesn't* offer elegant catching of overflow, but
that dynamic (heap) allocation *does*, because, in practice,
it won't always work -- the standard does *not*, AFAIK,
guarantee that exhausting the heap (or stack) results in a
graceful stop or setting some condition code in cases where
the resource is exhausted during *implicit* activities
(like I/O, expression evaluation, etc.).
Basically, we're talking about allocation of fixed resources among
competing entities and how to cope with situations where
the desired resources are not available.
My guess is that, whether we're talking about Fortran 90 or
about Fortran-with-Peter's-feature, we're *still* not talking
about a system that gracefully *and* seamlessly catches
case where insufficient memory is available.
Here are some observations I can come up with offhand that
involve the core issues:
- If user code can trap (or at least get a decent diagnostic)
when some resource *it* wants is unavailable, can it do the
same when some resource any entity it *invokes* is
unavailable?
- Are there any entities that user code can invoke "unawares"
that might compete for finite resources? E.g. can a
statement like "A = B * C + D", where all names are of
complicated arrays, or a statement like "CALL FOO(C//'HI')",
where FOO is CHARACTER*(*), cause the same resources -- like
the heap or stack -- to be drawn down and thus, possibly,
exhausted?
- If the answer to the above is "yes", does it make any
practical or worthwhile difference whether the stack or
heap is exhausted due to an *explicit* user-code allocation
or to an *implicit* one done, perhaps, in the very next
statement? Is that difference sufficient to provide the
facility throughout?
- If the answer was "no", does that mean that partitioning
of resources is employed in a way that might result in
"premature" exhausting of one or the other partition?
- If not, is the dynamic relocation of the partition boundary
expensive -- for code that doesn't need to do it, or for
code that does?
- Etc.
Consider this code:
PROGRAM CRASHME
IMPLICIT NONE
INTEGER N
PRINT *, 'Give me a big number to try and crash on.'
READ *, N
CALL MRBIG(N)
END
SUBROUTINE MRBIG(N)
IMPLICIT NONE
INTEGER I, N
CHARACTER*(N) C
CHARACTER*1 CFUNC
EXTERNAL CFUNC
DO I = 1, N
C(I:I) = 'X'
END DO
PRINT *, 'Success so far... ', CFUNC(C//'FOO')
END
CHARACTER*1 FUNCTION CFUNC(C)
IMPLICIT NONE
CHARACTER*(*) C
CFUNC = C(LEN(C)-2:)
END
I haven't tried this myself, so it might need some fixing up, but
the important aspects are:
1. Dynamic (stack) allocation of C in MRBIG which should be "caught",
but at least is explicit
2. Dynamic (stack? heap? separately partitioned?) allocation for
the temporary C//'FOO' in the call to CFUNC, which is implicit
The question I'm asking is, is it sufficiently useful to have
the Fortran standard, or even an implementation, elegantly catch
stack overflow (or other resource exhaustion) in case #1 but *not*
case #2? If so, why, since the cases are, in practice,
indistinguishable in a running program? How is it useful for
this, or any similar, program to think it's succeeded at
allocating an object and then proceed to do computations that
are "rudely interrupted" by a graceless, uncatchable resource
exhaustion shortly thereafter?
The way to try this out is to repeatedly invoke the program, and
enter numbers (using a binary-search technique) to find the
region of numbers where the program neither runs to completion
*nor* elegantly catches stack/heap full the way it does
when it happens in case #1 above. (I'd love to know what
results someone gets from Absoft under Linux, for example.
Note that the program might need editing to fit the dialect
provided by any given compiler...it won't work under g77 as is,
for example.)
If that region is not empty, then that suggests the implementation
does *not* provide a graceful *and* seamless way to catch stack
or heap exhaustion.
Note that a third element that might factor into the above is:
3. Dynamic (stack? heap? separately partitioned?) allocation for
the PRINT and END statements themselves (that is, the I/O
and other such things).
In summary, there might be *some* utility in elegantly catching
stack/heap exhaustion *only* on explicit *user-code* allocations,
but that utility does not scale up well as the complexity of
applications -- which might mix stack and heap allocation, make
lots of small-stack allocations (making procedure calls more
likely to overflow the stack), and so on -- scales up. And
some implementations that work well in small, simple cases might
actually cause more trouble (other than just run-time performance)
in more complex cases, e.g. always, or even sometimes, allocating
on the heap instead of on the stack (which can lead to fragmentation
that is not apparently going to result by examining the Fortran
code in question).
However, regarding the Fortran standard, little of the above
necessarily matters whether Peter's proposal is included --
because the standard mandates catching problems only with
explicit, *user-triggered* exhaustion of resources, so
implementations that do just that and not anything else can
be standard-conforming, even if they might serve as poor platforms
for large-scale applications due to not being able to catch
problems resulting from implicit exhaustion of resources.
In other words, to *really* address the problem of elegantly
catching exhaustion of resources (like memory), the *entire*
language and its implementations must be designed to do so.
Fortran is not an example of this (yet), but other languages
(like PL/I perhaps, or Ada) probably exist that are.
--
"Practice random senselessness and act kind of beautiful."
James Craig Burley, Software Craftsperson burley@gnu.org
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: fortran error?
1998-03-17 5:00 ` Peter Shenkin
1998-03-17 5:00 ` Craig Burley
@ 1998-03-18 5:00 ` Steve Lionel
1 sibling, 0 replies; 32+ messages in thread
From: Steve Lionel @ 1998-03-18 5:00 UTC (permalink / raw)
In article <350E95A7.41C6@still3.chem.columbia.edu>, Peter Shenkin
<shenkin@still3.chem.columbia.edu> writes:
|>Quality of implementation should demand even more than this: if
|>an automatic cannot be "allocated" on the stack, the run-time system
|>should allocate it on the heap. Even a compile-time option that
|>allows a size threshold to be specified for heap, rather than stack,
|>allocation of automatics would be a step in the right direction.
|>Cray gives us this feature for the Cray (not the SGI) platform.
This is something we're actively looking at. We agree completely that it
would improve the perceived quality of our product.
--
Steve Lionel mailto:Steve.Lionel@digital.com
Fortran Development http://www.digital.com/info/slionel.html
Digital Equipment Corporation
110 Spit Brook Road, ZKO2-3/N30
Nashua, NH 03062-2698 "Free advice is worth every cent"
For information on DIGITAL Fortran, see http://www.digital.com/fortran
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: fortran error?
1998-03-18 5:00 ` Toon Moene
1998-03-18 5:00 ` Jeff Drummond
@ 1998-03-19 5:00 ` Peter Shenkin
1 sibling, 0 replies; 32+ messages in thread
From: Peter Shenkin @ 1998-03-19 5:00 UTC (permalink / raw)
Toon Moene wrote:
>
> [ I hope I can add some bits to this discussion, but might
> raise more questions instead ... ]
>
> Peter Shenkin <shenkin@still3.chem.columbia.edu> wrote:
>
> [ ... about the allocation of automatic arrays ... ]
>
> > One of these was a compile-time flag for a size threshold to force
> > allocation of large automatics on the heap....
> It's not suprising Cray implemented such a feature, because, AFAIK, Cray PVP
> systems do not have a stack as such - the "stack" is also managed as a heap.
> Perhaps Jeff Drummond or one of the other Crayons listening in can elaborate
> on this point.
As I understand it (my interpretation of some email some time ago
from one of the Cray engineers -- if I'm wrong, in other words,
blame me), Cray does have a stack, but the allowed stack allocation
is not easily altered by a user. (An ordinary UNIX user can alter
his own stack allocation (up to the compiled-in kernel value) by
use of the "limit" or "ulimit" command.) So Cray provided an
alternative method by means of which code providers can compile
code containing large automatic variables which is intended to be
run by ordinary users.
>
> > I suspect it's not less efficient, or not much less efficient, or
> > even more efficient, to test whether the unused part of the stack
> > is large enough to hold the automatics that needs to fit there, and
> > abort the program with a descriptive message if there's not.
>
> The point often is not that the stack isn't large enough, but that the system
> (either by default or because the user set a limit) doesn't "allow" the stack
> to grow beyond a certain limit.
Well, the maximum allowable stack size is not large enough. But
on many UNIX systems, the default maximum stacksize provided to a user
is quite low. I suppose this is to provide a means for the system
to kill a program if an infinite recursion should occur.
...
> > The Absoft compiler under LINUX is the only one I know that
> > terminates the program gracefully with a descriptive message
> > when allocation of an automatic fails. In fact, no UNIX system
> > I've ever encountered delivers the message you propose. Can
> > you cite one that does?
>
> That's neat, it means they either allocate on a heap (were they can trace the
> amount of memory allocated), or they translate the "segmentation violation"
> that results from overrunning stack limits in the appropriate message: that
> means they have to have a sure fire means to discriminate between this
> failure and a "generic" segmentation violation.
It did occur to me that they might actually allocate automatics
on the heap, but I don't know whether they do this or not.
-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 *
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: fortran error?
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 ` Dick Hendrickson
0 siblings, 2 replies; 32+ messages in thread
From: Peter Shenkin @ 1998-03-19 5:00 UTC (permalink / raw)
First, I did, in fact, interpret Craig's original response as a
put-down, and much of my last response was an attempt to justify
my suggestions in the light of this. But I see from Craig's
second response that he didn't really mean it this way, so I
apologize, Craig, for misinterpreting you in this way.
At this point, I only want to address one or two issues that Craig
just brought up.
Craig Burley wrote:
>
> Peter Shenkin <shenkin@still3.chem.columbia.edu> writes:
...
> The way I look at it, stack allocation is almost *never* a
> bottleneck in any real application, but *heap* allocation often
> is. ...
> So, the only reason I can think of that stack allocation isn't
> required to be as robust as heap allocation in Fortran is that
> implementors knew how they wanted to implement stack allocation
> (which, as Peter correctly points out, isn't really called that
> in the Fortran standard, so it *can* be done on the heap in
> practice)
Yup. I agree with both of these points.
.
> > I suspect it's not less efficient, or not much less efficient, or
> > even more efficient, to test whether the unused part of the stack
> > is large enough to hold the automatics that needs to fit there, and
> > abort the program with a descriptive message if there's not.
>
> I agree, and, to me, the point is that the *standard* (or default)
> behavior should be to incur a bit less extra overhead, if necessary,
> to produce a nice diagnostic. If that last little bit of performance
> really needs to be squeezed out, compiler/linker technology can be
> improved generally, and the user can be given a compiler/linker
> option to dismiss the detection facilities for use in specific
> instances.
I agree here, too.
...
> > Finally, if this can be done, then your proposal is not too bad
> > a match for the suggestion of mine that you deprecate: namely,
> > that a descriptive message be printed if allocation of an automatic
> > fails due to unavailability of resources. In fact, I suppose
> > I would settle for your less precise diagnostic; it would be
> > better than what we have now. But if your suggestion can be
> > carried out efficiently, I suspect mine can be carried out nearly
> > as efficiently. To UNIX, however, all SEGVs are created equal.
>
> Again, I was *not* deprecating your suggestion, rather, trying to
> find a politick (and somewhat humorous) way to suggest that it
> was only us implementors who would tend to brush it off, and that
> I, as an implementor, saw no valid reason to do so. I hadn't
> wanted to get into a discussion of all the possible implementation
> issues, though.
>
> What I don't understand is how your solution of "stop the program
> with a descriptive error message" substantially differs from mine
> of "have the error message that gets printed when a program stops
> (under Linux) due to overflowing the stack be more descriptive".
There would be two differences. (1) If the compiler/linker actually
used heap allocation for automatics, the descriptive message that
I originally advocated would still tell you that an automatic variable
could not be allocated; (2) if a stack overflow occurred for a
different reason -- for example, too large a non-automatic local
array -- my suggestion would give a different message for this
(perhaps the normal SEGV, for example). It's just a matter of
being more specific, and less dependent on how the implementation
chooses to do it.
...
> Note that all this is moot if stack allocation happens to fail
> on *procedure* invocation, which of course can happen on most
> systems, since the stack is not just where local "user" data
> goes!
>
> Perhaps that's where the *real* problem is -- verifying that
> each and every "call" instruction (or signal, for the day
> when we get exceptions) will either succeed or will produce
> a clean diagnostic....
> And this is where I begin to wonder if whether even the
> behavior of ALLOCATE (with or without STATUS=) is all that
> worthwhile. That is, maybe the problem isn't that stack
> allocation *doesn't* offer elegant catching of overflow, but
> that dynamic (heap) allocation *does*, because, in practice,
> it won't always work -- the standard does *not*, AFAIK,
> guarantee that exhausting the heap (or stack)
You're quite right in that other things can blow the stack
besides automatic variables. But the advent of automatics
makes the ability to handle stack overflow *in their particular
case* especially important in practice. The fact is that a
stack overflow has gone from being very rare to rather likely,
in my experience, when automatics are used. If we handle the
most common cases -- like failure of automatic allocation --
explicitly, then maybe it's not too bad to leave everything
else in the same "miscellaneous" category where they've always
lived, relatively immune from complaint. I agree that an attempt
to handle all causes explicitly leads to a morass.
-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 *
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: fortran error?
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 ` Dick Hendrickson
1 sibling, 2 replies; 32+ messages in thread
From: Craig Burley @ 1998-03-19 5:00 UTC (permalink / raw)
Peter Shenkin <shenkin@still3.chem.columbia.edu> writes:
> > And this is where I begin to wonder if whether even the
> > behavior of ALLOCATE (with or without STATUS=) is all that
> > worthwhile. That is, maybe the problem isn't that stack
> > allocation *doesn't* offer elegant catching of overflow, but
> > that dynamic (heap) allocation *does*, because, in practice,
> > it won't always work -- the standard does *not*, AFAIK,
> > guarantee that exhausting the heap (or stack)
>
> You're quite right in that other things can blow the stack
> besides automatic variables. But the advent of automatics
> makes the ability to handle stack overflow *in their particular
> case* especially important in practice. The fact is that a
> stack overflow has gone from being very rare to rather likely,
> in my experience, when automatics are used. If we handle the
> most common cases -- like failure of automatic allocation --
> explicitly, then maybe it's not too bad to leave everything
> else in the same "miscellaneous" category where they've always
> lived, relatively immune from complaint. I agree that an attempt
> to handle all causes explicitly leads to a morass.
Yes, well, it occurred to me later that the history of this
area in Fortran probably includes the fact that, indeed, for
"classic Fortran", stack overflow was rarely a problem, and
that the introduction of automatic arrays was the *single*
biggest reason why it might become one.
Similarly, heap overflow was rarely a problem for "classic
Fortran". Even if the underlying run-time libraries (provided
with the compiler) used heap (or stack) storage, the demands
of "classic Fortran" applications were probably such that these
wouldn't contribute noticably to exhausting these particular
resources.
In particular, this stems from the lack of powerful facilities
provided by "classic Fortran", by which I should say I mean
FORTRAN 77, or earlier, with "typical" extensions -- ones that
don't demand dynamic allocation, in the various intrinsics,
I/O, and other "implicit" facilities provided by the language.
Essentially, using FORTRAN 77, it is fairly straightforward to
analyze a complete program and determine whether it will run
to completion in a given amount of memory, because there's
no ability to explicitly *or* implicitly demand dynamic
allocation of memory resources (stack or heap).
It stands to reason, then, that, as *explicit* facilities were
added as extensions (or new features in F90), people would assume
that those were suitable places on which to "hang" the ability
to catch memory exhaustion.
After all, if stack/heap overflow wasn't a problem for "classic
Fortran", and it might be for "classic Fortran plus ALLOCATE"
(or whatever), then the "obvious" conclusion is "well, give the
programmer a way to catch a failure to ALLOCATE, because that's
where memory exhaustion will happen".
However, now Fortran (90, 95, F2K, etc.) have significant and
extensive facilities that demand dynamic allocation, both explicit
*and* implicit (e.g. dynamic character allocation, dynamic array
allocation on assignments, etc.).
At this point, then, while I agree there is still some practical
benefit to allowing catching of out-of-memory conditions on
*explicit* allocations, I feel this benefit diminishes as the
application makes more use of F90-and-beyond features.
That is, stick to "classic Fortran plus ALLOCATE" or similar, and
catching out-of-memory still makes sense the way its done now.
But, as more applications make full use of Fortran features that
do *implicit* allocations, the utility of detecting an out-of-memory
condition on only *explicit* allocations decreases, because an
explicit allocation can succeed only to have a subsequent implicit
allocation fail, with no way to catch it using the current
language facilities. And, since that likely means it's the
preceding explicit allocation that "strained" resources such
that the implicit allocation couldn't succeed, the application
does not get the feedback it needs that the explicit allocation
could not, in effect, proceed without the application crashing
unexpectedly.
My concern is that too many programmers will code as if catching
out-of-memory on explicit allocations (even assuming we extended
this, as I think perhaps we should, to automatic arrays and other
stack allocations) is a panacea. That means their applications
might be *coded* so that they'll never truly run out of memory
in a way that they can't catch and handle.
And, what's particularly dangerous about that assumption is that
they'll be correct when their code is the only "fancy" code in
an application, but the assumption's correctness will degrade,
perhaps to the point of being almost certainly incorrect, as
*other* code in the same application is rewritten to take advantage
of newer features.
To look at this problem in a different light, imagine how programmers
would feel if they discovered that, sometimes, the underlying
run-time library would arbitrarily decide to write a large
temporary file, and if it ran out of disk space doing that, it
would just crash the application without any opportunity to catch
the error.
In that context, programmers would justifiably complain that
their *code* was written to assume that, as long as it caught
all possible I/O errors via IOSTAT= or ERR=, it wouldn't be
crashed by a disk-full condition. Yet, their applications
could be randomly crashed by disk-full in a way that was basically
impossible to predict, especially in portable code. In fact,
that sort of thing, while unlikely, would seem to be perfectly
standard-conforming behavior.
However, this illustration points out how troubling it might
become that applications, written to increasingly depend upon
heap and stack allocation to run reliably, find they are
thus increasingly likely to crash because the run-time system
is quietly competing with the explicit code for those resources --
with no way to catch the cases where the resources are exhausted
due to one of these implicit allocations, even though all
explicit allocations might well be coded to catch out-of-memory
conditions and handle them gracefully!
It's not that I've run into this problem in practice with Fortran,
yet, since I don't really deal with F90 and beyond. But, I always
try to do thought-exercises regarding any new language features,
system features, implementation decisions (or hacks ;-), and so
on, thinking through how they might interact, for better or worse,
with each other as they're more accepted and thus become more
thoroughly exploited. And my thought-exercises regarding all
these features suggest that some of them (say, catching out-of-
memory conditions on explicit allocations) become useless
appendages, or worse, when they are exploited along with other
features. That doesn't mean they aren't useful in "smaller
groups" of features being employed by a particular application,
however.
--
"Practice random senselessness and act kind of beautiful."
James Craig Burley, Software Craftsperson burley@gnu.org
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: fortran error?
1998-03-19 5:00 ` Craig Burley
@ 1998-03-20 5:00 ` Nick Maclaren
1998-03-20 5:00 ` Peter Shenkin
1 sibling, 0 replies; 32+ messages in thread
From: Nick Maclaren @ 1998-03-20 5:00 UTC (permalink / raw)
In article <y6n2emoxa6.fsf@tweedledumb.cygnus.com>, Craig Burley <burley@tweedledumb.cygnus.com> writes:
|>
|> Yes, well, it occurred to me later that the history of this
|> area in Fortran probably includes the fact that, indeed, for
|> "classic Fortran", stack overflow was rarely a problem, and
|> that the introduction of automatic arrays was the *single*
|> biggest reason why it might become one.
Yes, that is so. However, for amusement only, people should note
that at least one Fortran II compiler had automatic arrays :-)
The reason that stack overflow is such a problem is because many
systems have assumed the model that it is used only for small
objects, and that other forms of allocation will be used for large
ones. On systems that do NOT make that assumption, there isn't a
problem until you run out of memory entirely.
|> Similarly, heap overflow was rarely a problem for "classic
|> Fortran". Even if the underlying run-time libraries (provided
|> with the compiler) used heap (or stack) storage, the demands
|> of "classic Fortran" applications were probably such that these
|> wouldn't contribute noticably to exhausting these particular
|> resources.
Yes, but remember that Fortran 90 introduced not one but TWO "heap"
concepts. The Unix/C term implies a (more-or-less static) area of
space used for the dynamic allocation of variable sized objects
(i.e. malloc and conspirators). But Fortran 90 also implies a
requirement for this area to be garbage collected (i.e. the Algol 68
use of the term "heap") - and, as with almost all similar languages,
neither requires it nor specifies any properties of the garbage
collector.
I argued this heatedly with some people on X3J3, as I did previously
with some Algol68, Lisp etc. people, and got nowhere. The point is
that you absolutely cannot write portable, robust code if you have
to rely on a garbage collector that may not exist at all or may have
unsuitable properties. And using ALLOCATE for large numbers of short
lifetime objects implies some form of space recovery.
So it would NOT improve matters simply to have large or variable
arrays put on the "heap" - what is critical is to have them put in a
data area that is managed either as a dynamic stack, or as one of
semantic supersets of a dynamic stack. Algol 60 and 68 (and other
languages) proved that dynamic stacks can be implemented efficiently
and easily in several ways.
|> That is, stick to "classic Fortran plus ALLOCATE" or similar, and
|> catching out-of-memory still makes sense the way its done now.
Unfortunately, no it doesn't, for the above reason. You are asking
for trouble simply using ALLOCATE instead of stack allocation as a
way of getting a dynamic stack. It will often work, but you will
then make a minor change or move to a new system, and the memory
will fragment unusably and your program will not run at all.
Nick Maclaren,
University of Cambridge Computing Service,
New Museums Site, Pembroke Street, Cambridge CB2 3QG, England.
Email: nmm1@cam.ac.uk
Tel.: +44 1223 334761 Fax: +44 1223 334679
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: fortran error?
1998-03-19 5:00 ` Peter Shenkin
1998-03-19 5:00 ` Craig Burley
@ 1998-03-20 5:00 ` Dick Hendrickson
1998-03-20 5:00 ` Peter Shenkin
1998-03-20 5:00 ` Craig Burley
1 sibling, 2 replies; 32+ messages in thread
From: Dick Hendrickson @ 1998-03-20 5:00 UTC (permalink / raw)
Peter Shenkin wrote:
>
[snip]
>
> Craig Burley wrote:
> >
> > Peter Shenkin <shenkin@still3.chem.columbia.edu> writes:
> ...
> > The way I look at it, stack allocation is almost *never* a
> > bottleneck in any real application, but *heap* allocation often
> > is. ...
>
[snip]
>
> Yup. I agree with both of these points.
>
[snip]
I'm not so sure it isn't (or won't be) a bottleneck. There are lots
of real codes that call a very small procedure gazillions of times.
Call overhead often dominates the run-time of the small procedure.
Fortran 90 potentially makes this worse with the ideas of
encapsulation and information hiding and user defined operators.
Lots of little routines that effectivelly do a couple of loads, an add,
and a store. Adding several cycles to the entry and exit sequence
can have a big effect.
This doesn't mean compilers shouldn't do it, only that there is a
real cost. Inlining helps, but some library code is only available
in binary form.
Dick Hendrickson
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: fortran error?
1998-03-20 5:00 ` Dick Hendrickson
@ 1998-03-20 5:00 ` Peter Shenkin
1998-03-20 5:00 ` Craig Burley
1 sibling, 0 replies; 32+ messages in thread
From: Peter Shenkin @ 1998-03-20 5:00 UTC (permalink / raw)
Dick Hendrickson wrote:
>
> Peter Shenkin wrote:
> >
> [snip]
> >
> > Craig Burley wrote:
> > >
> > > Peter Shenkin <shenkin@still3.chem.columbia.edu> writes:
> > ...
> > > The way I look at it, stack allocation is almost *never* a
> > > bottleneck in any real application, but *heap* allocation often
> > > is. ...
> >
> [snip]
> >
> > Yup. I agree with both of these points.
> >
> [snip]
>
> I'm not so sure it isn't (or won't be) a bottleneck. There are lots
> of real codes that call a very small procedure gazillions of times.
> Call overhead often dominates the run-time of the small procedure.
Yes, I agree. But stack allocation of *automatics* is not generally
the bottleneck here, and this is what both Craig and I were (I think)
referring to.
Most of us learned, even back in the F77 or earlier days, to
avoid calling functions gazillions of times; in-line expansion, or
the statement function, allows this to be done syntactically, though,
without incurring the cost you refer to, which is a real one.
-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 *
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: fortran error?
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 ` Craig Burley
1998-03-20 5:00 ` Richard Maine
1 sibling, 2 replies; 32+ messages in thread
From: Peter Shenkin @ 1998-03-20 5:00 UTC (permalink / raw)
Craig Burley wrote:
...
> Essentially, using FORTRAN 77, it is fairly straightforward to
> analyze a complete program and determine whether it will run
> to completion in a given amount of memory, because there's
> no ability to explicitly *or* implicitly demand dynamic
> allocation of memory resources (stack or heap).
I think this isn't completely true, but it certainly became a lot
less true, as you point out, with the advent of the new features
of F90.
Even in F77, it would have been difficult to determine the maximum
depth of subroutine calls that would be possible for a given program.
It would have been possible to compute an upper bound, since, in
the absence of recursion, an analyzer could assume that every procedure
was chained together in one single call chain, and compute the stack
requirements of this chain. But this would almost always be a severe
overestimate of what the real program does.
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. 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.
One more thing that you referred to, but that deserves to be
emphasized, is something that Sergio Gelato also mentioned to
me in email. I started this thread by saying that I wished that
the Fortran standard would mandate a program STOP when an automatic
cannot be allocated. Sergio -- and you, but less explicitly, I
think -- pointed out that this also pertains to temporary arrays
that the run-time system allocates.
As we go from ALLOCATABLE arrays to automatic arrays, we are going
from an explicit to an implicit dynamic memory request. When we go
from these to a compiler-requested temporary array, we are going to
a completely hidden memory request. Clearly, these can cause the
same problems as automatics when allocation fails, and the standard
should mandate more graceful error handling for these arrays as
well -- even if the program is merely stopped on failure to allocate.
-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 *
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: fortran error?
1998-03-20 5:00 ` Dick Hendrickson
1998-03-20 5:00 ` Peter Shenkin
@ 1998-03-20 5:00 ` Craig Burley
1998-03-20 5:00 ` Peter Shenkin
1 sibling, 1 reply; 32+ messages in thread
From: Craig Burley @ 1998-03-20 5:00 UTC (permalink / raw)
Dick Hendrickson <dick.hendrickson@worldnet.att.net> writes:
> This doesn't mean compilers shouldn't do it, only that there is a
> real cost. Inlining helps, but some library code is only available
> in binary form.
That's a point in favor of short-term practicality, but I'd
like to point out that restricting language and tool design to
allow library code to be distributed only in binary form
(i.e. proprietary and made hard to reverse engineer), especially
to *existing* such libraries, *severely* restricts the power of
those languages and tools.
For example, I've observed (somewhat casually ;-) the long-term
efforts, and problems, incurred trying to put decent exception
handling into gcc, and it seems that most of the actual problems,
and thus effort resolving them, revolves around catering to
already-compiled binary code, where source is inconvenient or
unavailable.
I think it's not worth catering to these needs at all, or at a
very low priority, in new-language design, and leave it to the
vendors of proprietary libraries and relevant tools to improve
*their* products to meet *their* requirements as well as the
(new) ones of the language environment. (But I'm afraid too
many of them would prefer the language be crippled for non-
proprietary users to make their proprietary tools easier to build.)
--
"Practice random senselessness and act kind of beautiful."
James Craig Burley, Software Craftsperson burley@gnu.org
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: fortran error?
1998-03-20 5:00 ` Peter Shenkin
@ 1998-03-20 5:00 ` Craig Burley
1998-03-20 5:00 ` Peter Shenkin
1998-03-20 5:00 ` Nick Maclaren
1998-03-20 5:00 ` Richard Maine
1 sibling, 2 replies; 32+ messages in thread
From: Craig Burley @ 1998-03-20 5:00 UTC (permalink / raw)
Peter Shenkin <shenkin@still3.chem.columbia.edu> writes:
> Craig Burley wrote:
> ...
> > Essentially, using FORTRAN 77, it is fairly straightforward to
> > analyze a complete program and determine whether it will run
> > to completion in a given amount of memory, because there's
> > no ability to explicitly *or* implicitly demand dynamic
> > allocation of memory resources (stack or heap).
(Note that I corrected myself in private email who misunderstood
what I wrote about. Replace "...will run to completion in a given
amount of memory..." with "...will run without ever exhausting
a given amount of memory...", or some such thing.)
> I think this isn't completely true, but it certainly became a lot
> less true, as you point out, with the advent of the new features
> of F90.
>
> Even in F77, it would have been difficult to determine the maximum
> depth of subroutine calls that would be possible for a given program.
> It would have been possible to compute an upper bound, since, in
> the absence of recursion, an analyzer could assume that every procedure
> was chained together in one single call chain, and compute the stack
> requirements of this chain. But this would almost always be a severe
> overestimate of what the real program does.
It's quite easy to compute a call tree and thus flatten the estimate
of the maximum, though.
What I'm trying to say is probably not what I'm saying, I'm afraid,
but I'll try again: in FORTRAN 77, it is fairly easy and straightforward
to determine that a given program will not only *fit* into a given
amount of memory, but will never ask for any *more* memory while
running.
Some factors make this more difficult, e.g. if the underlying run-time
implementation dynamically allocates memory, but it's not the language
definition or even many typical extensions that require this -- though
practical needs might (e.g. an implementation that wishes to support
1000 simultaneously OPEN'ed files might choose to dynamically
allocate unit info to reduce demands on virtual memory when many
fewer files are open).
> 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 -- heck,
in some cases, that meant you couldn't *link* it in the first
place!
But, if it was *not* too big, then you *could* run it, for as
long as you wanted, with no more memory being requested, guaranteed
by the facts that your code was FORTRAN 77 and that the underlying
implementation didn't dynamically allocate more memory than was
initially requested by the executable.
E.g. the Prime 400 FTN compiler was basically done this way, and
maybe F77 as well (though I think that always generated 64V-mode
or 32I-mode stuff, which means it could have had a code generator
that assumed it could dynamically allocate stack and/or heap).
There might have been some "hiccups" in the underlying libraries
that could cause stack overflow, but I think, in practice, we
just figured out where to set the stack based on some straightforward
analysis of a given application, and could assume, with a reasonable
amount of assurance (and could get more if we really wanted), that,
once successfully invoked, the executable could run "forever" without
exhausting memory.
(I think we're now so spoiled by instant gratification,
resource-wise, that we forget how much time and energy was
spent *designing* systems, not to mention implementing them,
to not only elegantly cope with dynamically discovering a lack
of sufficient resources, but knowing *ahead of time* not to
even *start* a job without first being sure all the resources
that job needed would be available. Sadly, I can only point
to MVS JCL in comparison to, say, UNIX `sh' to illustrate this
offhand, but, though JCL was incredibly hard to read and write,
it did allow, perhaps require, expressing the sum total of resources
needed by a job so the system could know when and whether to
start it up. FORTRAN's memory model fit into this world-view
beautifully. That sort of thing seems like overkill at this
particular point in time, when hardware keeps getting bigger
and faster while also getting cheaper, and when reasonable
responses to "my program crashed with SEGV" include "increase
your stack size" *and* "buy more memory". But if the hardware
trend ever smooths out, our software needs will begin to catch up
and, once again, we'll return to seeing the need for a system
to have a much better idea of whether a given task will actually
run to completion, based on resource needs, *before* having to
start that task...because our tasks will keep growing, I would
assume, even when hardware stops growing so fast. After all,
the answer to "buy more memory" a couple of decades ago might
have been "but that'll cost me $100,000!!".)
> 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. This is FORTRAN 77, after all -- there's no
recursion, no automatic arrays, no allocatable arrays, hence no
need for a stack *or* a heap!
For *efficiency*, I believe it makes a lot of sense to put stuff
on the stack. That can lead to efficiency of CPU time (stack
frames for different procedures more likely to overlay each other
in memory, thus be in cache) and, of course, memory.
But, there's basically no technical impediment for a fairly
vanilla implementation of FORTRAN 77 to produce a pretty decent,
and highly useful, value for maximum amount of memory needed by a
given program even *if* that implementation decides to put some
local variables and arrays on the stack for some procedures.
After all, since the call tree is so easy to produce, so is
the "overlayability" of stack frames. That is, two procedures
that do REAL A(10000) might require a total of 20000 32-bit
words for those arrays *unless* the call tree shows that neither
procedure is called while the other is active, in which case
use of the same static space, or use of the stack frame for
each procedure's implementation, allows both arrays to use a
total of 10000 32-bit words. (And maybe other local variables
for other procedures can be easily combined with this as well.)
To do this today, portably, would require somewhat better
linker/library technology than we have now. The problem is
1% technical, 99% writing and getting agreement on all the
specifications. Okay, maybe I'm exaggerating, but, trust me,
if I devoted myself to making a version of g77 that ran on,
say, only GNU/Linux/Alpha systems, with no regard for portability,
providing a facility whereby the linker can warn if the program
won't certainly run in x bytes of virtual memory would be
fairly straightforward, I believe. And putting its computation
of the lowest x it can safely determine into an executable, so the
OS (Linux) can be sure to reserve that amount of VM for the
duration of the program on invocation, or refuse to invoke,
would be straightforward as well. And I'm not talking about
some wild exaggeration of x either, *except* once features
beyond FORTRAN 77 are discussed. (I'm a bit uncertain how
analyzable the current libraries would be using the techniques
I imagine, but it might be easy enough to replace the more
intricate stuff with simpler implementations that would be
easy to automatically analyze while still meeting the needs
of FORTRAN 77.)
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.
None of these solutions *eliminate* out-of-memory problems
for that application, but they succeed often enough, and system
configurations, applications, and Fortran implementations change
so fast, that it probably seems a waste of resources to make a
bigger effort to get it all "right".
I think this is another example of how the whole "bigger,
faster, cheaper" drive in computer software (and sometimes
hardware) design also has led to "buggier, crashier, feature-creepier"
as well. To wit, others here, with different experiences than
mine, talk about how easy debugging used to seem back when
array bounds checking was *automatically* on, even though
they had to debug via batch jobs!
(For myself, I guess I can defend my choices for g77 only by
saying I've tried to make g77 what it is supposed to be --
a replacement for UNIX f77 at least. I'd like to make it more
like the kind of safe, robust compiler I think would be
really useful, but I'm also quite aware that *most* of what
people want out of it are "bigger, faster, cheaper"-type things.
g77's biggest failings right now are mostly in the arenas of
ease of debugging, support of extensions and F90 features, and
packaging, whereas lots of people do sing praises about its
performance, especially the egcs version. g77 doesn't even
have the array-bounds-checking option that f2c does -- yet.)
> One more thing that you referred to, but that deserves to be
> emphasized, is something that Sergio Gelato also mentioned to
> me in email. I started this thread by saying that I wished that
> the Fortran standard would mandate a program STOP when an automatic
> cannot be allocated. Sergio -- and you, but less explicitly, I
> think -- pointed out that this also pertains to temporary arrays
> that the run-time system allocates.
Yup.
> As we go from ALLOCATABLE arrays to automatic arrays, we are going
> from an explicit to an implicit dynamic memory request. When we go
> from these to a compiler-requested temporary array, we are going to
> a completely hidden memory request. Clearly, these can cause the
> same problems as automatics when allocation fails, and the standard
> should mandate more graceful error handling for these arrays as
> well -- even if the program is merely stopped on failure to allocate.
Right.
As Sergio (I think it was) said in private email, the simple one-line
answer is that Fortran needs a (IMO very robust) exception mechanism.
In the meantime, as long as programmers are made aware of the dangers,
and have at least some of the facilities in question (ALLOCATE's
STATUS=, or whatever), they at least have the ability to avoid
some of the most common problems, especially if they know to avoid
expressions that tend to allocate huge temporaries on various systems.
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. To avoid being
thwarted by a system that does "lazy allocation", i.e. one that
can return "success" for an allocation but later seg-fault a
reference to the allocate area because there turned out to be
insufficient memory after all, the "guard" array would have to
be written to, etc.
The end result is that, if enough programmers find themselves doing
tricks like the above to guard against their applications bombing
out unexpectedly, that'll illustrate the practical need for
something like an exception mechanism to replace these.
But these tricks are haphazard, i.e. it's quite easy to forget
to use them in a crucial place. They are certainly kludges,
so using them "in the meantime" does not mean the problem has been
solved, even in the short term.
--
"Practice random senselessness and act kind of beautiful."
James Craig Burley, Software Craftsperson burley@gnu.org
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: fortran error?
1998-03-20 5:00 ` Craig Burley
@ 1998-03-20 5:00 ` Peter Shenkin
1998-03-23 5:00 ` Craig Burley
0 siblings, 1 reply; 32+ messages in thread
From: Peter Shenkin @ 1998-03-20 5:00 UTC (permalink / raw)
Craig Burley wrote:
>
> Dick Hendrickson <dick.hendrickson@worldnet.att.net> writes:
>
> > This doesn't mean compilers shouldn't do it, only that there is a
> > real cost. Inlining helps, but some library code is only available
> > in binary form.
>
> That's a point in favor of short-term practicality, but I'd
> like to point out that restricting language and tool design to
> allow library code to be distributed only in binary form
> (i.e. proprietary and made hard to reverse engineer), especially
> to *existing* such libraries, *severely* restricts the power of
> those languages and tools.
I've reread Dick's and Craig's comments a few times, and I'm not
sure I understand Craig's harangue in this context. I think Dick
was using as an example ("Inlining helps....") the fact that, if
you have a library only in binary form, you can't insert INLINE
directives; therefore, if a library is slow because of failure
of the writer to INLINE, the user cannot recompile it after making
changes unless he has source.
This in no way constitutes a "[restriction] of language and tool
design to allow library code to be distributed only in binary
form." There's nothing about the INLINE feature that especially
facilitates or restricts binary distribution. It's just a case
in which someone with access to the source code, motivation for
improving that code and time to spend on the project might be
able to produce faster code. Changing an underlying algorithm
is another such way such a person could do this. It has nothing
to do with restricting language features, as far as I can see.
But I also take exception to Craig's overall point of view
on this. I think that if the language definition makes it hard
to distribute libraries as binaries, this also makes it hard
to utilize libraries as re-usable code, even if you do have
the source. In other words, if I have source for a library, and
if I can compile and readily use the binaries for many programs
on my system, then there is no reason the binary can't be used
without source by other people. On the other hand, if I cannot
compile the library code and readily use the binary libraries
for many programs after compilation, then I have lost a major
benefit of libraries in the first place: code reusability.
I feel that the failure of F90 to mandate a mechanism for the
USE facility makes re-use of libraries difficult; even portable
Makefiles become difficult or impossible. I reiterate that this
is a real drag even if one does have source.
Further, any language that fails to make it easy to use a binary-only
distribution is making most users do lots of work they shouldn't have
to do. For instance, if I needed to do something to the source of
the C stdlib or stdio functions (or even have it on my system)
every time I wanted to write a program using malloc() or printf(),
I would certainly never write code in C. The whole purpose of
writing libraries is so that users don't *have* to know anything
about the source, or even about the language the libraries are written
in. Any language that requires the user of a library to know something
about the source language (other than the API) is failing in its
fundamental task: to allow the user to utilize a computational
facility without understanding all the gory details of how it works.
> For example, I've observed (somewhat casually ;-) the long-term
> efforts, and problems, incurred trying to put decent exception
> handling into gcc, and it seems that most of the actual problems,
> and thus effort resolving them, revolves around catering to
> already-compiled binary code, where source is inconvenient or
> unavailable.
This sounds like a back-compatibility problem with existing code
which was developed before the new features were designed. It
doesn't sound like a problem that would affect even proprietary
code developed with the new features in mind.
> I think it's not worth catering to these needs at all, or at a
> very low priority, in new-language design,
Ah, but C is an old language, and gcc an old dialect, by now.
> ... and leave it to the
> vendors of proprietary libraries and relevant tools to improve
> *their* products to meet *their* requirements as well as the
> (new) ones of the language environment. (But I'm afraid too
> many of them would prefer the language be crippled for non-
> proprietary users to make their proprietary tools easier to build.)
I don't doubt that writers of proprietary code would be against
features that prevent them from keeping their code proprietary, but
I do have trouble imagining what such language features would look
like, and I also have trouble imagining useful language improvements
that would have this effect.
-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 *
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: fortran error?
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 ` Nick Maclaren
1 sibling, 1 reply; 32+ messages in thread
From: Peter Shenkin @ 1998-03-20 5:00 UTC (permalink / raw)
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 *
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: fortran error?
1998-03-20 5:00 ` Craig Burley
1998-03-20 5:00 ` Peter Shenkin
@ 1998-03-20 5:00 ` Nick Maclaren
1998-03-20 5:00 ` Richard Maine
1 sibling, 1 reply; 32+ messages in thread
From: Nick Maclaren @ 1998-03-20 5:00 UTC (permalink / raw)
In article <y6u38tay23.fsf@tweedledumb.cygnus.com>,
Craig Burley <burley@tweedledumb.cygnus.com> wrote:
>
>It's quite easy to compute a call tree and thus flatten the estimate
>of the maximum, though.
>
>What I'm trying to say is probably not what I'm saying, I'm afraid,
>but I'll try again: in FORTRAN 77, it is fairly easy and straightforward
>to determine that a given program will not only *fit* into a given
>amount of memory, but will never ask for any *more* memory while
>running.
While this is true, it is a bit deceptive. You are quite correct as
far as most constructions are concerned, and we used to do precisely
that when overlaying large programs into small regions (remember that
fun and games?)
However, one rare construction in Fortran 77 (character concatenation)
can theoretically lead to a program with O(N) total allocated space
needing O(2^N) to run. Which is, of course, why almost all compilers
have an ad-hoc kludge or two for the space to use for that horrible
construction :-(
>> 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 -- heck,
>in some cases, that meant you couldn't *link* it in the first
>place!
Yes, quite. And not so ancient machines, either. VS Fortran under
IBM MVS and CMS used that technique right up until its first CEL
(Common Execution Library) version - sometime in the late 1980s.
On the matter of systems that allow specification in advance, quite
a lot of mainframes did that - indeed, I would say almost all. And
even today, products like NQS do, but it typically done only for
supercomputers. Memory may be cheap - but not if you want it both
extremely fast, and by the terabyte!
[ And, yes, I agree with most of the rest of your points! ]
Nick Maclaren,
University of Cambridge Computing Service,
New Museums Site, Pembroke Street, Cambridge CB2 3QG, England.
Email: nmm1@cam.ac.uk
Tel.: +44 1223 334761 Fax: +44 1223 334679
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: fortran error?
1998-03-20 5:00 ` Peter Shenkin
1998-03-20 5:00 ` Craig Burley
@ 1998-03-20 5:00 ` Richard Maine
1 sibling, 0 replies; 32+ messages in thread
From: Richard Maine @ 1998-03-20 5:00 UTC (permalink / raw)
Peter Shenkin <shenkin@still3.chem.columbia.edu> writes:
> Craig Burley wrote:
> ...
> > Essentially, using FORTRAN 77, it is fairly straightforward to
> > analyze a complete program and determine whether it will run
> > to completion in a given amount of memory, because there's
> > no ability to explicitly *or* implicitly demand dynamic
> > allocation of memory resources (stack or heap).
>
> I think this isn't completely true...
Oh, I'm quite certain that it is completely true. Remember that f77
was designed in days where many machines didn't have stacks or much of
any other form of dynamic allocation. There are some quirky
restrictions in f77 that are there specifically to cater to such
machines. It is quite possible to run f77 with a stack size of zero
and with no other form of dynamic allocation. Numerous proofs by
example exist. This was basically a design requirement on the
language.
You basically do it by making *ALL* memory allocation static.
Any temporary space needed for a subroutine call is statically
allocated as part of the subroutine's memory.
Comparably, if you want to use a stack, you can total the stack
requirements for all of the subroutines. This is clearly not an
optimal solution, but it trivially works in a non-recursive
environment. And in the typical f77 implementation, where no user
data ends up on the stack, even if a stack does exist, it isn't even
an unreasonably large burden.
--
Richard Maine
maine@altair.dfrc.nasa.gov
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: fortran error?
1998-03-20 5:00 ` Nick Maclaren
@ 1998-03-20 5:00 ` Richard Maine
0 siblings, 0 replies; 32+ messages in thread
From: Richard Maine @ 1998-03-20 5:00 UTC (permalink / raw)
nmm1@cus.cam.ac.uk (Nick Maclaren) writes:
> However, one rare construction in Fortran 77 (character concatenation)
> can theoretically lead to a program with O(N) total allocated space
> needing O(2^N) to run. Which is, of course, why almost all compilers
> have an ad-hoc kludge or two for the space to use for that horrible
> construction :-(
Eh? Are you talking about standard f77 or some extension? Standard
Fortran 77 goes out of its way to disallow the cases where concatenation
would otherwise require dynamic allocation. This is exactly the reason
for a couple of the otherwise inexplicable limitations... such as
subroutine sub(c)
character c*(*)
character c1*10
c1 = c // "a" !-- This is ok (except for this form of commenting).
call sub2( c // "a" ) !-- But this isn't.
end
If you know a case where standard f77 requires dynamic allocation, I'd sure
like to see a sample - obscure or not.
--
Richard Maine
maine@altair.dfrc.nasa.gov
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: fortran error?
1998-03-20 5:00 ` Peter Shenkin
@ 1998-03-23 5:00 ` Craig Burley
0 siblings, 0 replies; 32+ messages in thread
From: Craig Burley @ 1998-03-23 5:00 UTC (permalink / raw)
Peter Shenkin <shenkin@still3.chem.columbia.edu> writes:
> Craig Burley wrote:
> >
> > Dick Hendrickson <dick.hendrickson@worldnet.att.net> writes:
> >
> > > This doesn't mean compilers shouldn't do it, only that there is a
> > > real cost. Inlining helps, but some library code is only available
> > > in binary form.
> >
> > That's a point in favor of short-term practicality, but I'd
> > like to point out that restricting language and tool design to
> > allow library code to be distributed only in binary form
> > (i.e. proprietary and made hard to reverse engineer), especially
> > to *existing* such libraries, *severely* restricts the power of
> > those languages and tools.
>
> I've reread Dick's and Craig's comments a few times, and I'm not
> sure I understand Craig's harangue in this context. I think Dick
> was using as an example ("Inlining helps....") the fact that, if
> you have a library only in binary form, you can't insert INLINE
> directives; therefore, if a library is slow because of failure
> of the writer to INLINE, the user cannot recompile it after making
> changes unless he has source.
[...]
> But I also take exception to Craig's overall point of view
> on this. I think that if the language definition makes it hard
> to distribute libraries as binaries, this also makes it hard
> to utilize libraries as re-usable code, even if you do have
> the source. In other words, if I have source for a library, and
> if I can compile and readily use the binaries for many programs
> on my system, then there is no reason the binary can't be used
> without source by other people. On the other hand, if I cannot
> compile the library code and readily use the binary libraries
> for many programs after compilation, then I have lost a major
> benefit of libraries in the first place: code reusability.
[...]
> Further, any language that fails to make it easy to use a binary-only
> distribution is making most users do lots of work they shouldn't have
> to do. For instance, if I needed to do something to the source of
> the C stdlib or stdio functions (or even have it on my system)
> every time I wanted to write a program using malloc() or printf(),
> I would certainly never write code in C. The whole purpose of
> writing libraries is so that users don't *have* to know anything
> about the source, or even about the language the libraries are written
> in. Any language that requires the user of a library to know something
> about the source language (other than the API) is failing in its
> fundamental task: to allow the user to utilize a computational
> facility without understanding all the gory details of how it works.
I was generalizing from Dick's comments to the more general idea
that possible new features might not be good ideas because they'd
make it hard for proprietary-software vendors to deliver upgraded
versions of their products.
You make good points, and, rather than discuss them, I just want
to give a simple example of what I'm talking about.
Suppose the Fortran standard was improved to require diagnostics
if it was "obvious" that a procedure call mismatched the procedure
itself in a program.
That would be a decent feature, but would make it hard for
existing systems, especially binary-only libraries, to be
upgraded to the new standard, because the linker wouldn't
(normally) be able to extract the necessary information to
produce the required diagnostics.
Further, even if the technical issues were easily addressed,
vendors of proprietary software might complain that putting
the necessary information into their binary-only distributions
made those distributions too easy to reverse-engineer.
My point is that these are *not* worthwhile arguments against the
viability of a proposed new feature, such as this one. For
one thing, the benefits far outweigh the costs. For another,
it's up to the proprietary vendors to figure out a way to meet
their own needs while meeting the standard -- *they*, and their
customers, should have to bear the costs of distributing software
so it cannot easily be reverse-engineered, copied, whatever. Users
and vendors of *free* (source-available) software should *not* have
to pay a greater price to do their work, just to make life easier
for those who insist on using the proprietary-software approach.
There simply is *nothing* to be gained, technically, from distributing
or receiving proprietary, binary-only distributions. All gains you
might *think* are to be so gained are either purely economic
(by creating artificial scarcity, the price of software is driven
up) or can be fairly trivially obtained without going the proprietary
route. (For example, you seem to conclude that, if the language
definition makes it hard to distribute libraries as binaries, it
also makes it hard to utilize libraries as re-usable code, even
if source is available. That's backwards, actually -- code re-
usability is *simplified* by doing good language design *without*
catering to proprietary vendors. I've been wrapping my head around
the GNU model of software distribution for a few years now, and
it's amazing how much, taken seriously, it solves tons of problems
I'd simply taken for granted for a couple of decades of being
exposed pretty much solely to the proprietary-software-must-be-
catered-to model we all have built into all our software systems.)
It's not that economic realities aren't to be taken into account
by the *community*, because, obviously, they are -- people do,
and will continue to, buy proprietary software, such as Fortran
libraries they are not allowed to reverse-engineer.
What I'm saying is that this sub-market should not be *catered*
to by the *language-design* community (i.e. standards), especially
when the result is at the expense of the larger market. That is,
a new feature should not be rejected because "that'll make it
hard for people to distribute proprietary versions of their
run-time libraries".
There are plenty of other features and behaviors language standards
could (and, some do!) mandate that make distributing proprietary
software quite difficult, but everything else (mostly) easier.
Again, it's up to the proprietary vendors to cope, not up to us
all to (continue to) shoot ourselves in the feet to make their
lives easier.
Of course, standards that describe how to package proprietary
software in a way that meets the needs of *other* standards are
another issue. E.g. if F2K proprietary vendors got together
and standardized how to distribute binary-only software that
still met F2K and related usability expectations, that'd be fine.
--
"Practice random senselessness and act kind of beautiful."
James Craig Burley, Software Craftsperson burley@gnu.org
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: fortran error?
1998-03-20 5:00 ` Peter Shenkin
@ 1998-03-23 5:00 ` Craig Burley
1998-03-23 5:00 ` Craig Burley
1998-03-23 5:00 ` Summary (I hope) failure of automatic allocation; was, " Peter Shenkin
0 siblings, 2 replies; 32+ messages in thread
From: Craig Burley @ 1998-03-23 5:00 UTC (permalink / raw)
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
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: fortran error?
1998-03-23 5:00 ` Craig Burley
@ 1998-03-23 5:00 ` Craig Burley
1998-03-23 5:00 ` Peter Shenkin
1998-03-23 5:00 ` Summary (I hope) failure of automatic allocation; was, " Peter Shenkin
1 sibling, 1 reply; 32+ messages in thread
From: Craig Burley @ 1998-03-23 5:00 UTC (permalink / raw)
Craig Burley <burley@tweedledumb.cygnus.com> writes:
> Peter Shenkin <shenkin@still3.chem.columbia.edu> writes:
>
> > 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 noticed this -- I've been assuming you meant to say
"...control whether stack or static memory is used at compile time".
F77 code can be trivially compiled to an executable that makes
no use whatsover of the stack *or* heap, and thus does not
grow during run time. (Of course, the underlying system might
mandate certain uses of stack/heap for things like starting up
the program, calling the OS, etc., but it's unlikely that any
of this would contribute to overflowing the stack or heap when
run as part of a F77 program that is compiled to use neither!)
--
"Practice random senselessness and act kind of beautiful."
James Craig Burley, Software Craftsperson burley@gnu.org
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: fortran error?
1998-03-23 5:00 ` Craig Burley
@ 1998-03-23 5:00 ` Peter Shenkin
1998-03-24 5:00 ` Craig Burley
0 siblings, 1 reply; 32+ messages in thread
From: Peter Shenkin @ 1998-03-23 5:00 UTC (permalink / raw)
Craig Burley wrote:
...
> F77 code can be trivially compiled to an executable that makes
> no use whatsover of the stack *or* heap, and thus does not
> grow during run time. (Of course, the underlying system might
> mandate certain uses of stack/heap for things like starting up
> the program, calling the OS, etc.,...
Or calling procedures. But I don't disagree with this statement,
generally.
-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 *
^ permalink raw reply [flat|nested] 32+ messages in thread
* Summary (I hope) failure of automatic allocation; was, Re: fortran error?
1998-03-23 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
1 sibling, 1 reply; 32+ messages in thread
From: Peter Shenkin @ 1998-03-23 5:00 UTC (permalink / raw)
Craig Burley wrote:
>
> Peter Shenkin <shenkin@still3.chem.columbia.edu> writes:
> > ... 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?
Very rarely. I think that when we closely examine what I said,
what you said, what I said you said and what you said I said,
we'll discover that we agree even on the details.
But even if we don't, what is important is that automatic variables
are often (usually) implemented on the stack, and this makes
ungraceful program termination (typically, an untrappable SEGV)
far more likely than it used to be.
Handling such failures in a friendlier fashion is bound to become
a significant Q-of-I issue in the future -- especially since C
programs that use the new C9x "variable-length array" facility
(a counterpart to Fortran's automatic arrays) are likely to be
susceptible to the same problem.
IMHO, the Fortran standard should mandate an error-handling
mechanism for such events. At the very least, this should be
a program STOP, and good implementations will say why the program
stopped.
Also in the Q-of-I area, I think compilers should have options to
force automatics to be allocated on the heap, preferably in some
dynamic way. The simplest would be the Cray method of allowing
a size threshold to be specified such that automatics larger than
this size would be allocated on the heap. Perhaps better would
be a stack fraction: if an automatic would take up greater than
this fraction of the remaining available stack, it would be
allocated on the heap.
But avoiding a signal -- especially an untrappable signal --
is the least we can ask of our compiler vendors, even without
anything said in the standard.
-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 *
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: Summary (I hope) failure of automatic allocation; was, Re: fortran error?
1998-03-23 5:00 ` Summary (I hope) failure of automatic allocation; was, " Peter Shenkin
@ 1998-03-24 5:00 ` Craig Burley
0 siblings, 0 replies; 32+ messages in thread
From: Craig Burley @ 1998-03-24 5:00 UTC (permalink / raw)
Peter Shenkin <shenkin@still3.chem.columbia.edu> writes:
> But avoiding a signal -- especially an untrappable signal --
> is the least we can ask of our compiler vendors, even without
> anything said in the standard.
Yes, as I tried to say originally, I support this 100%, even
though I recognize (and have explained at ridiculous length
now, I'm afraid ;-) that it might be hard to do on some systems.
--
"Practice random senselessness and act kind of beautiful."
James Craig Burley, Software Craftsperson burley@gnu.org
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: fortran error?
1998-03-23 5:00 ` Peter Shenkin
@ 1998-03-24 5:00 ` Craig Burley
1998-03-24 5:00 ` Nick Maclaren
0 siblings, 1 reply; 32+ messages in thread
From: Craig Burley @ 1998-03-24 5:00 UTC (permalink / raw)
Peter Shenkin <shenkin@still3.chem.columbia.edu> writes:
> Craig Burley wrote:
> ...
> > F77 code can be trivially compiled to an executable that makes
> > no use whatsover of the stack *or* heap, and thus does not
> > grow during run time. (Of course, the underlying system might
> > mandate certain uses of stack/heap for things like starting up
> > the program, calling the OS, etc.,...
>
> Or calling procedures. But I don't disagree with this statement,
> generally.
I'm not sure I'm aware of any system that mandates that calling a
procedure requires using a stack. Calling pre-compiled *library*
procedures might, of course, but that is subsumed by my "calling
the OS, etc." comment.
That is, I'm pretty sure that most systems, perhaps all popular
ones during the F77 "era", offered "short call" instructions that
didn't use the stack. The machines on which I did a decent
amount of Fortran work usually had options you could give to the
compilers to specify that you wanted to use these "short call"
instructions instead of the longer form. (E.g. on a SPARC, you
can avoid using the stack and more than one register window for
most of your application except, of course, for library and OS
calls; dunno whether Sun/Solaris f77/f90 products provide options
to take advantage of this fact, though. Prime machines would use,
IIRC, JSX in place of the PCL instruction. The most primitive
form of non-stack-using instructions I can recall offhand was
exemplified by the PDP-8 in its JMS instruction -- instead of
storing the return address in a register, which the callee can
decide to store in "data memory", this form stores it directly
in the *callee* and starts execution at the next memory location,
making shared libraries kinda hard. And, debugging programs compiled
or hand-written to use these less-than-comprehensive procedure-
call instructions was, typically, annoying when using the fancier
debuggers, e.g. stack traces might not work.)
Regardless, in the F77 days, if you wanted to be absolutely sure
a running Fortran program never ran out of memory (once started
up by the OS), it was quite easy to do so on almost every system
out there, certainly every system I've used, modulo obscure
behaviors in the run-time library I didn't know about (and which
have basically nothing to do with Fortran).
That's no longer true, for three reasons:
1. Fortran has features by which the programmer explicitly
(in the sense of "usually knows it's happening") asks for
dynamic allocation. (ALLOCATE, automatic arrays, etc.)
2. Fortran has features by which the programmer implicitly
(in the sense of "might not know or care it's happening")
asks for dynamic allocation. (FOO//FOO, when FOO is
CHARACTER*(*), etc.)
3. Due to 1 and 2, Fortran implementations might now be exploiting
dynamic allocation, to implement otherwise innocuous features,
such that memory exhaustion (stack overflow or no room in the
heap) can happen even when performing one of these innocuous
features (e.g. a wholly "traditional" operation like WRITE).
For more traditional implementations and code, actual overflows
are, maybe, 99% likely to happen when implementing features in
Item 1 above, so enabling the programmer to explicitly avoid (or
at least trap on) these covers a lot of worthwhile cases.
For the newer implementations and newer, F90-based program,
though, the percentage of actual overflows that happen for
Item-1 situations is almost certainly going to be lower, which
means the usefulness of trapping only those overflows goes down
*unless* trapping on *all* overflows (meaning those that happen
in cases listed in Items 2 and 3) also works (and, preferably,
works seamlessly vis-a-vis traps of Item-1 cases).
--
"Practice random senselessness and act kind of beautiful."
James Craig Burley, Software Craftsperson burley@gnu.org
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: fortran error?
1998-03-24 5:00 ` Craig Burley
@ 1998-03-24 5:00 ` Nick Maclaren
0 siblings, 0 replies; 32+ messages in thread
From: Nick Maclaren @ 1998-03-24 5:00 UTC (permalink / raw)
In article <y63eg8xcu4.fsf@tweedledumb.cygnus.com>, Craig Burley <burley@tweedledumb.cygnus.com> writes:
|>
|> I'm not sure I'm aware of any system that mandates that calling a
|> procedure requires using a stack. Calling pre-compiled *library*
|> procedures might, of course, but that is subsumed by my "calling
|> the OS, etc." comment.
The VAX and quite a few other systems required the language to
maintain the stack pointer, ready for an interrupt. CLU didn't
do this, and failed horribly on the MicroVAX .... Some others
required the use of the (standard) stack if the system exception
handling was to work properly. But all of this was way outside the
language specification.
|> That is, I'm pretty sure that most systems, perhaps all popular
|> ones during the F77 "era", offered "short call" instructions that
|> didn't use the stack. ...
No, during the main part of that era, almost all used static
allocation. Both stack-based and static compilers often had a "fast
call" that evaded the standard conventions, and caused a greater or
lesser amount of chaos if failure occurred in the called routine, so
I am not really disagreeing with you on fundamentals.
|> Regardless, in the F77 days, if you wanted to be absolutely sure
|> a running Fortran program never ran out of memory (once started
|> up by the OS), it was quite easy to do so on almost every system
|> out there, certainly every system I've used, modulo obscure
|> behaviors in the run-time library I didn't know about (and which
|> have basically nothing to do with Fortran).
Um. Provided that you regard opening files as being in the last
category, yes. But OPEN often caused memory exhaustion, and READ
and WRITE sometimes did - e.g. unlike concatenation under MVS :-)
Nick Maclaren,
University of Cambridge Computing Service,
New Museums Site, Pembroke Street, Cambridge CB2 3QG, England.
Email: nmm1@cam.ac.uk
Tel.: +44 1223 334761 Fax: +44 1223 334679
^ permalink raw reply [flat|nested] 32+ messages in thread
end of thread, other threads:[~1998-03-24 5:00 UTC | newest]
Thread overview: 32+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` Nick Maclaren
1998-03-20 5:00 ` Peter Shenkin
1998-03-20 5:00 ` Craig Burley
1998-03-20 5:00 ` Peter Shenkin
1998-03-23 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-23 5:00 ` Summary (I hope) failure of automatic allocation; was, " Peter Shenkin
1998-03-24 5:00 ` Craig Burley
1998-03-20 5:00 ` Nick Maclaren
1998-03-20 5:00 ` Richard Maine
1998-03-20 5:00 ` Richard Maine
1998-03-20 5:00 ` Dick Hendrickson
1998-03-20 5:00 ` Peter Shenkin
1998-03-20 5:00 ` Craig Burley
1998-03-20 5:00 ` Peter Shenkin
1998-03-23 5:00 ` Craig Burley
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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox