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: Peter Shenkin Subject: Re: fortran error? Date: 1998/03/20 Message-ID: <3512FE4B.2781@still3.chem.columbia.edu>#1/1 X-Deja-AN: 336105406 Content-Transfer-Encoding: 7bit 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> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Organization: MacroModel Development Group, Columbia University Newsgroups: comp.lang.fortran,comp.unix.osf.osf1 Craig Burley wrote: > > Peter Shenkin 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 *