From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fee84,1ef3b84ca62fad7b X-Google-Attributes: gidfee84,public X-Google-Thread: 1094ba,1ef3b84ca62fad7b X-Google-Attributes: gid1094ba,public From: jjd@cray.com (Jeff Drummond) Subject: Re: fortran error? Date: 1998/03/18 Message-ID: <6ep8fc$6lt$1@walter-fddi.cray.com>#1/1 X-Deja-AN: 335339139 Distribution: world References: <3507A4A5.F8A7DDC2@matd.tu-graz.ac.at> <6ejfii$kbd@usenet.pa.dec.com> <350E95A7.41C6@still3.chem.columbia.edu> <350EDA13.2781@still3.chem.columbia.edu> <6eopju$pfi$2@news.utrecht.NL.net> Organization: Cray Research, a subsidiary of Silicon Graphics, Inc. Keywords: When Segments Fault, No One Can Hear You Scream Newsgroups: comp.lang.fortran,comp.unix.osf.osf1 In article <6eopju$pfi$2@news.utrecht.NL.net>, Toon Moene writes: |> [ I hope I can add some bits to this discussion, but might |> raise more questions instead ... ] |> |> Peter Shenkin 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