This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: gfortran47, pgf90 work - ifort segfaults


Hi,

On 02/10/2012 01:45 PM, Arjen Markus wrote:
2012/2/10 Anton Shterenlikht<mexas@bristol.ac.uk>:
What is "explicit allocation"?
Sorry for the confusion, I simply meant: via the allocate statement.
That is: use variables with the allocatable or pointer attribute and
use the allocate statement to allocate the memory needed for these
variables. (Automatic variables get their memory automatically - hence
my use of "explicit")

It is actually not that easy to see where memory is taken from. For allocatables and pointers with anonymous targets it's simple: When one calls ALLOCATE they are allocated on the heap.
Similarly for variables which have the SAVE attribute: They are always in the static memory.


For local nonautomatic variables in procedures: If they are scalars, they typically are on the stack. For arrays, gfortran places them - if they are larger - by default in static memory. One can tune when stack or static memory should be used, including always static (-fno-automatic) and always stack (RECURSIVE, -frecursive or -fopenmp). (In principle, it would be also possible for the compiler to use heap memory.)

For temporary variables, generated by the compiler, or for automatic variables: gfortran either places them on the heap or (with -fstack-arrays) on the stack.

Thus, it is not as obvious which memory gets used. Stack memory is best: It's very quickly allocated - but one has stack size issues (segfault if exceeded) and the memory expires automatically. Static memory is also good performance wise, but tracking the memory is more difficult for the compiler, leading to less optimized code. And heap memory is slowest, but most flexible. It also provides a nice error message when exceeded and doesn't have the optimization issue variables in static memory have.

Tobias


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]