Re: SAVE



Ganesh <ganesh.iitm@xxxxxxxxx> wrote:
hi !

I have a subroutine where I am currently allocating 3 arrays at
every function call.. ! I learnt of this SAVE statement just now...!
However it's not quite what I want.. it's much more than what I want..

I can't have array lengths defined at compile time.. but each time
the subroutine is called it's going to be same length.... that is once
the execution has started.. it's going to be the same..

These arrays are used only internally and are not needed outside the
subroutine..

And i don't need the variables saved across the function calls.. i
just need to avoid allocation on every call...

Any idea what will be the best thing to do here..? To avoid
allocating on every call.. or does the compiler detect this
automatically and does something on it's own..I'm using IFORT 9.0..
but I need this to work on Sun Studio 8 (gfortran also if possible)

I have had the idea of declaring these arrays once in the main program
itself and passing them everytime.. that way it will be declared only
once..But that would put something totally out of place in the main
program...Hence i would like to know of some other way if it's
possible..


I would recommend automatic arrays for the internal workspace. The
condition for this to work is that the array bounds can be calculated
in a specification expression on entry. One of the easiest ways is to
pass the lengths as arguments in the call.

These arrays usually are actually allocated on every call, but this is
done on the stack and takes very little or no additional execution
time. It happens automatically, there is no allocate statement or
anything.


--
Klaus Wacker klaus.wacker@xxxxxxx
Experimentelle Physik V http://www.physik.uni-dortmund.de/~wacker
Universitaet Dortmund Tel.: +49 231 755 3587
D-44221 Dortmund Fax: +49 231 755 4547
.



Relevant Pages

  • Re: SAVE
    ... I have a subroutine where I am currently allocating 3 arrays at ... These arrays are used only internally and are not needed outside the ... I have had the idea of declaring these arrays once in the main program ...
    (comp.lang.fortran)
  • Re: Basic ASCII File Reading
    ... critical first step to almost anything like this - defining the problem. ... FJ appears to have guessed that the header is always exactly 7 lines. ... His involves allocating and deallocating, ... time consuming than resizing arrays. ...
    (comp.lang.fortran)
  • SAVE
    ... I have a subroutine where I am currently allocating 3 arrays at ... These arrays are used only internally and are not needed outside the ... I have had the idea of declaring these arrays once in the main program ...
    (comp.lang.fortran)
  • Re: ALLOCATABLE arrays
    ... > If try to create a very large array on the stack and you do not have enough ... > Allocating on the heap gives you access to a hell of a lot more memory (well ... Allocatable arrays are allocated on the heap. ... Automatic arrays are always allocated on the stack. ...
    (comp.lang.fortran)
  • Re: ALLOCATABLE arrays
    ... || If try to create a very large array on the stack and you do not have enough ... || Allocating on the heap gives you access to a hell of a lot more memory (well ... and "heap" (and there probably are/were some computers which don't/didn't ... | Automatic arrays are always allocated on the stack. ...
    (comp.lang.fortran)