From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9260 invoked by alias); 16 Jul 2011 15:25:54 -0000 Received: (qmail 9213 invoked by uid 22791); 16 Jul 2011 15:25:53 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE X-Spam-Check-By: sourceware.org Received: from mx01.qsc.de (HELO mx01.qsc.de) (213.148.129.14) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 16 Jul 2011 15:25:38 +0000 Received: from [192.168.178.22] (port-92-204-19-234.dynamic.qsc.de [92.204.19.234]) by mx01.qsc.de (Postfix) with ESMTP id 66D838B30; Sat, 16 Jul 2011 17:25:36 +0200 (CEST) Message-ID: <4E21AD70.2090508@net-b.de> Date: Sat, 16 Jul 2011 15:45:00 -0000 From: Tobias Burnus User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:5.0) Gecko/20110624 Thunderbird/5.0 MIME-Version: 1.0 To: Mikael Morin CC: fortran@gcc.gnu.org, gcc patches Subject: Re: [Patch, Fortran] Support allocatable *scalar* coarrays References: <4E1A03E8.3050706@net-b.de> <4E1AAB00.2030104@net-b.de> <201107161459.26836.mikael.morin@sfr.fr> In-Reply-To: <201107161459.26836.mikael.morin@sfr.fr> Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2011-07/txt/msg01327.txt.bz2 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[]" 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.