Gerald Pfeifer wrote:
There is one sentence (preceding my patch) which I don't quite
understand (specifically around the "to"):

   "...which diagnose when code to is inserted for automatic
   (re)allocation of a variable during assignment."

Let me try to explain what the warning does and what "automatic (re)allocation" is; either the meaning becomes clear – or you might get an idea how to improve the wording.

But I concur that the current version is odd; it should either be "when code is [or: "will be"] inserted" or, maybe, "when code is to be inserted".

* * *

Fortran has allocatable variables, e.g.
real, allocatable :: array(:)

If one now has the assignment
array = [ 1, 2, 3, 4 ]
the "array" gets automatically allocated for an array size of 4 before the assignment. If one now has
array = [ 5,6,7,8 ]
there is only the assignment as "array" is already allocated while for
array = [ 1, 2 ]
"array" is reallocated to have an array size of 2 (and then the array "[1,2]" is assigned).

In order to do this, the compiler has to add a check whether the LHS is allocated and whether the type parameters (e.g. the [allocatable] string length) and array shape are the same. Thus, the compiler adds internally a lot of code.

While this (re)allocate-on-assignment feature is very convenient, it can cause some severe slow down if it occurs in a hot loop. If users knows that the variable is allocated and of the correct shape (should be true for all code before Fortran 2003), they can either disable the feature (-std=f95, -fno-realloc-lhs) or they can prevent the reallocation by using a (whole) array section, e.g. "array(:) = [5,6,7,8]". And to avoid guessing where reallocation on assignment might happen, the warning shows where. Thus, the warning helps with performance tuning.

Tobias

Reply via email to