Re: Allocating arrays inside a subroutine.



In article <1156841260.541988.5840@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
deltaquattro@xxxxxxxxx wrote:

[replace dummy argument with module array...]
Since no one else suggested this, I wonder if that's the best way to
get the job done (my compiler doesn't support "extended allocatables",
even though I'm trying to have this fixed).

Yes, that is a correct solution. It has the disadvantage that the
subroutine can allocate only that single array, whereas if it were a
dummy argument (pointer, or allocatable with the allocatable TR) it
could be called multiple times with different array arguments.

Fortran 90 and 95 were designed originally for such things to be
done with pointers, but the use of pointers has some disadvantages
(both performance and semantics). Most of us think that this was a
design mistake. It was later corrected (in the f95 allocatable TR
and in 2003), but these are not yet universally supported, so we are
still suffering from the original bad decision 15 years later. You
still need pointers in the language (e.g. for linked lists), but
almost everything else can be done better, cleaner, and more
efficiently with TR-style allocatable arrays.

In my own programming when this decision comes up, I usually use a
pointer array, and I leave a comment to myself to change it to an
allocatable array at some point in the future when the feature is
more universally supported. The same issue arises for allocatable
components of user defined data types.

$.02 -Ron Shepard
.



Relevant Pages

  • Re: Allocatable arrays in derived types
    ... | arrays is that, when an allocatable array goes out of scope, ... | A pointer which goes out of scope is not automatically deallocated, ... The primary cause of the overhead is complexity of Fortran arrays: ... (e.g. ALLOCATABLEs cannot have non-unit stride), ...
    (comp.lang.fortran)
  • Re: Some matlab -> fortran translation
    ... In f2003, that could be written, with array allocatable, as ... Doing it with allocatables ends up ... A pure f90 form with pointers looks something like ...
    (comp.lang.fortran)
  • Re: Q about simple program, with suggestions
    ... It's a pointer pointing to an array w/ dimension 2 ... > END TYPE Matrix ... With allocatables in f2003, you could even drop the second ...
    (comp.lang.fortran)
  • Re: Some matlab -> fortran translation
    ... The RHS is an array constuctor, with the elements of array, followed by ... Doing it with allocatables ends up ... A pure f90 form with pointers looks something like ... There really is no efficient way to build up an array by getting one memory element at a time. ...
    (comp.lang.fortran)
  • Re: gfortran & adjustable array: most values remain zero
    ... (snip on allocatables and subroutines) ... the dummy array is declared as that size; you don't end up trying to ...
    (comp.lang.fortran)