From: jjd@cray.com (Jeff Drummond)
Subject: Re: fortran error?
Date: 1998/03/18 [thread overview]
Message-ID: <6ep8fc$6lt$1@walter-fddi.cray.com> (raw)
In-Reply-To: 6eopju$pfi$2@news.utrecht.NL.net
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
next prev parent reply other threads:[~1998-03-18 5:00 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
1998-03-12 5:00 fortran error? Armin Leuprecht
1998-03-12 5:00 ` robin
1998-03-16 5:00 ` Steve Lionel
1998-03-17 5:00 ` Peter Shenkin
1998-03-17 5:00 ` Craig Burley
1998-03-17 5:00 ` Peter Shenkin
1998-03-18 5:00 ` Toon Moene
1998-03-18 5:00 ` Jeff Drummond [this message]
1998-03-19 5:00 ` Peter Shenkin
1998-03-18 5:00 ` Craig Burley
1998-03-19 5:00 ` Peter Shenkin
1998-03-19 5:00 ` Craig Burley
1998-03-20 5:00 ` Nick Maclaren
1998-03-20 5:00 ` Peter Shenkin
1998-03-20 5:00 ` Craig Burley
1998-03-20 5:00 ` Nick Maclaren
1998-03-20 5:00 ` Richard Maine
1998-03-20 5:00 ` Peter Shenkin
1998-03-23 5:00 ` Craig Burley
1998-03-23 5:00 ` Summary (I hope) failure of automatic allocation; was, " Peter Shenkin
1998-03-24 5:00 ` Craig Burley
1998-03-23 5:00 ` Craig Burley
1998-03-23 5:00 ` Peter Shenkin
1998-03-24 5:00 ` Craig Burley
1998-03-24 5:00 ` Nick Maclaren
1998-03-20 5:00 ` Richard Maine
1998-03-20 5:00 ` Dick Hendrickson
1998-03-20 5:00 ` Craig Burley
1998-03-20 5:00 ` Peter Shenkin
1998-03-23 5:00 ` Craig Burley
1998-03-20 5:00 ` Peter Shenkin
1998-03-18 5:00 ` Steve Lionel
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox