diff mbox

[fortran,06/21] Remove coarray support in the scalarizer: Request coarray for an actual arg associed with a coarray dummy

Message ID 20110915230827.28513.18093@gimli.local
State New
Headers show

Commit Message

Mikael Morin Sept. 15, 2011, 11:08 p.m. UTC
This one is more controversial and I need input from a coarray-fluent guy, for
example Tobias.

As I introduced the want_coarray flag (see previous patch), it made sense to me
to also set want_coarray for coarray dummies. After some more thought,
I decided to restrict further want_coarray to assumed shape coarray
dummies. The patch does that.

However, what comes up from testing is that neither is needed.
I'm not submiting this patch for approval, I'm submitting it to understand why
it is not necessary.
How are cobounds passed to a coarray dummy?
2011-09-14  Mikael Morin  <mikael.morin@sfr.fr>

	* trans-expr.c (gfc_conv_procedure_call): Set want_coarray flag if the
	dummy argument is an assumed-shape coarray.

Comments

Tobias Burnus Oct. 2, 2011, 4:34 p.m. UTC | #1
On 16.09.2011 01:08, Mikael Morin wrote:
> How are cobounds passed to a coarray dummy?

For explicit shape, assumed-size and assumed shape coarrays: The value 
is not passed but is set for the dummy argument. While that's not 
surprising for explicit shape/assumed shape arrays, e.g.
   integer :: A(5,7,n)[1:4, 4:*]
   integer :: B(2:*)[*]
it might be slightly surprising for assumed-shape coarrays. However, 
also for normal assumed-shape arrays, only the rank and not the lower 
bound is preserved (default lbound value: 1). For coarrays, also the 
upper bound needs to be given:
   integer :: B(1:, 5:)[4,*]
Note: In all those cases, the corank can differ between actual and dummy 
argument.

The only case where the the cobounds are passed are deferred-shape 
coarrays, i.e. allocatable ones, e.g.
   integer, allocatable :: A(:)[:,:]
here, the corank needs to agree and the lower/upper bounds are kept.

For deferred-shape coarrays, the array descriptor contains behind the 
array dimension triplets, additional triplets for the cobounds.

Except for the small difference for deferred-shape coarrays, with 
-fcoarray=single the normal data as with noncoarrays is transferred. For 
-fcoarray=lib one transfers in all cases additional information: A token 
identifying the coarray and the offset between the first coarray memory 
location and the one one passes (e.g., for a coarray "A(5)[*]", the 
element A(3) is also a coarray and the offset would be the one between 
A(1) and A(3)). For deferred-shape coarrays, the token is part of the 
array descriptor and no offset exists. For all other cases, there is a 
hidden additional argument for offset and token. See CoarrayLib in the 
wiki for details.

> However, what comes up from testing is that neither is needed.
> I'm not submiting this patch for approval, I'm submitting it to understand why
> it is not necessary.

I do not immediately see whether it is needed or not. However, as this 
is about the scalarizer: You cannot pass an allocatable array (coarray) 
to an (impure) elemental function which has a scalar *allocatable* dummy 
argument.* You can only do so if the dummy argument is not allocatable. 
However, in that case the cobounds are not taken from the actual 
argument but are constructed in the called procedure.

(* Separately allocating an single argument does not make sense. I have 
not checked the standard, but I don't think it can be valid.)

Does this answer the question?

Tobias
diff mbox

Patch

diff --git a/trans-expr.c b/trans-expr.c
index 131927c..80447fa 100644
--- a/trans-expr.c
+++ b/trans-expr.c
@@ -2990,8 +2990,12 @@  gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym,
 	{
 	  /* A scalar or transformational function.  */
 	  gfc_init_se (&parmse, NULL);
-	  argss = gfc_walk_expr (e);
+	  if (fsym && fsym->attr.codimension
+	      && (fsym->as->cotype == AS_ASSUMED_SHAPE
+		  || fsym->as->cotype == AS_DEFERRED))
+	    parmse.want_coarray = 1;
 
+	  argss = gfc_walk_expr (e);
 	  if (argss == gfc_ss_terminator)
 	    {
 	      if (e->expr_type == EXPR_VARIABLE