Mikael Morin wrote:
let me understand one thing about coarray scalars: despite their name, they
are arrays, right?
Yes and no. In terms of the language, they are scalars - but they have a
codimension, e.g.
integer, save :: A[4:6, 7:*]
is a scalar variable on each image, but it has a coarank of 2 with
lcobound(A) == [4, 7] and ucobound(A, dim=1) == 7. (The value of
cobound(A, dim=2) depends on the number of images, it's >= 7 in this
example.)
In terms of gfortran, nonallocatable coarrays are normal scalars - with
a lang-specific node attached to them, which contains the cobounds, i.e.,
GFC_ARRAY_TYPE_P (type) = 1;
GFC_TYPE_ARRAY_CORANK (type) = as->corank;
with
GFC_TYPE_ARRAY_LBOUND (type, dim)
containing the trees for dim = (rank + 1) ... (rank + corank).
The same scheme is used for assumed-type coarrays:
subroutine sub(B, n)
integer :: B(:)[5:7, n:*]
Note that here that contrary to the dimension, the codimension is not
":" (i.e. assumed shape) but that it is assumed-size.
For allocatable (scalar) coarrays, one has:
integer, allocatable :: B[:, :] ! Note: The coshape is deferred
...
allocate (B[2:3, 5:*])
Again, one has the actual data and the cobounds. For that case, I have
decided to store the information in the array descriptor of rank == 0
and dim[0 ... corank-1] for the bounds. Thus, "desc->data" contains the
scalar but the variable itself is a descriptor (GFC_DESCRIPTOR_TYPE_P).
The corank is not stored in the descriptor, but as one knows the number
of codimensions (an explicit interface is required for allocatable
coarray dummies), one knows the corank.
Then when you do in gfc_conv_array_ref:
+ if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (se->expr)))
+ se->expr = build_fold_indirect_ref (gfc_conv_array_data (se->expr));
[...]
return;
you are returning scalar[1] instead of scalar (== scalar[this_image()]) or
scalar[whatever_image_selector], aren't you?
Well, the current implementation supports effectively only a single
image - for -fcoarray=single on purpose and for -fcoarray=lib because it
has not yet been implemented.
Later, one has to add some function call for "scalar[<image_numer>]"
while "scalar" itself is the local variable and can be handled as above.
The expression of "scalar" ends up having expr->ref->type == REF_ARRAY
with dimen_type == DIMEN_THIS_IMAGE. That way one can distinguish a
reference to the local coarray and to a remote coarray (coindexed
variable); note that "coarray[this_image()]" also counts as
remote/coindexed.
Sorry for the delay; it seems that the more it goes, the more you are the only
one who can maintain coarray stuff. :-(
Well, Daniel Carrera develops into an trans*.c, allocate,
libgfortran/caf/ expert :-)
Tobias
PS: I should document somewhere how coarrays are implemented internally.