Re: Derived types and allocatable



James Giles wrote:
(snip on overhead for allocate on assignment)

It's still not clear to me what that overhead consists of.
In order to do a whole array assignment at all you must
do almost all (90+ %) of the work necessary to do conformance
tests. You have to find out how much data is moving and
from where to where,, that's nearly everything. Further,
that work is outside of the data movement itself, so the
remaining (<10%) of the effort is not "inside the loop".

If bounds checking is on, I agree the overhead is small.

Another consideration is in debugging where it is nice to
know the places where an array can be reallocated. If I
later find an array to be the wrong size, I have to go
through all possible reallocation statements to check.

(Partly that has to do with bugs I have chased down
in R programs, where R does allocate on assignment.
It also has to do with a feature of the R apply function.)

Since conformance testing is identical to the test for
reallocation (the only difference is what you do if
conformance didn't match), the only overhead if
both sides do conform is the test. I'm aware that
some implementors claim the overhead is significant.
I have no idea why.

Well, for small arrays in deeply nested loops it could
easily be very significant. Also, I am not sure how
good compilers are at optimizing bounds checking.
A DO variable (that isn't modified in the loop) can
be assumed to stay within the loop bounds, and should
avoid some bounds tests. I don't know which compilers
do that optimization.

Is it something inherent in the
problem, or (more likely) just something they haven't
worked out yet? The latter is likely because they can
always tell users to turn off the tests if the performance
is unacceptable. This allows them to put off the job
of fixing the performance problem. Things like that
can exist in implementations for years.
(snip)

If you really need a way to defeat reallocation, how would
be:

A(::1) = b + c

I suppose that works.

-- glen

.



Relevant Pages

  • Re: Overloading OPERATOR(+): my usage causing memory leaks.
    ... Imemory leaks when apply it to array arguments. ... I'd guess it to be a compiler bug, and I can even roughly guess where. ... assignment, but it seems a good candidate for something some compilers ... where a and b are derived types with allocatable components, the compiler should allocate ...
    (comp.lang.fortran)
  • Re: Derived types and allocatable
    ... prevent allocate by assignment. ... It's still not clear to me what that overhead consists of. ... do almost all of the work necessary to do conformance ...
    (comp.lang.fortran)
  • Re: F2003 syntax for this?
    ... > This implies that a implicit allocate is added by the compiler ... array and the right hand side is an array with ... is deallocated as part of the assignment process to ... It all happens under the covers by compiler magic. ...
    (comp.lang.fortran)
  • Re: Extremly fast dinamic array implementation
    ... assignment perhaps? ... what it does is to allocate a cache of objects (12 is its ... Yo can access the size of the array because it is allocated 1 point ...
    (comp.lang.c)
  • Re: array lines shifting
    ... What is it ment to do? ... This is your array: ... What is the goal, the goal is, to rotate array rows, the ... There is an assignment to stored value ...
    (alt.comp.lang.learn.c-cpp)