From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1094ba,1ef3b84ca62fad7b X-Google-Attributes: gid1094ba,public X-Google-Thread: fee84,1ef3b84ca62fad7b X-Google-Attributes: gidfee84,public From: Craig Burley Subject: Re: fortran error? Date: 1998/03/23 Message-ID: #1/1 X-Deja-AN: 336925772 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> <351181DB.2781@still3.chem.columbia.edu> <351296BC.167E@still3.chem.columbia.edu> <3512FE4B.2781@still3.chem.columbia.edu> Organization: Cygnus Support Newsgroups: comp.lang.fortran,comp.unix.osf.osf1 Peter Shenkin 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