(j3.2006) Question about zero-sized array.
Daniel C Chen
cdchen
Thu Jun 22 10:41:37 EDT 2017
Thanks Bill. That works!
Daniel
XL Fortran Development, Fortran Standard Representative
IBM Toronto Software Lab
Phone: 905-413-3056
Tie: 969-3056
Email: cdchen at ca.ibm.com
http://www.ibm.com/software/awdtools/fortran/xlfortran
From: Bill Long <longb at cray.com>
To: fortran standards email list for J3 <j3 at mailman.j3-fortran.org>
Date: 06/22/2017 10:35 AM
Subject: Re: (j3.2006) Question about zero-sized array.
Sent by: j3-bounces at mailman.j3-fortran.org
> On Jun 22, 2017, at 9:22 AM, Daniel C Chen <cdchen at ca.ibm.com> wrote:
>
> Thanks Walt and Tom!
>
> I think my confusion is I still couldn't find a place in the standard
that specifies the behavior you guys described.
A bit obscured. The MATMUL result is computed in terms of the SUM()
intrinsic, and the result value for SUM specifically says that the SUM(x)
is zero if x is zero-size.
Cheers,
Bill
>
> Daniel
>
> XL Fortran Development, Fortran Standard Representative
> IBM Toronto Software Lab
> Phone: 905-413-3056
> Tie: 969-3056
> Email: cdchen at ca.ibm.com
> http://www.ibm.com/software/awdtools/fortran/xlfortran
>
> <graycol.gif>Walt Brainerd ---06/21/2017 07:24:04 PM---I think Tom
correctly answered your Q3. The result of the MATMUL is a rank-1 size 7
array of 0s,
>
> From: Walt Brainerd <walt.brainerd at gmail.com>
> To: fortran standards email list for J3 <j3 at mailman.j3-fortran.org>
> Date: 06/21/2017 07:24 PM
> Subject: Re: (j3.2006) Question about zero-sized array.
> Sent by: j3-bounces at mailman.j3-fortran.org
>
>
>
>
> I think Tom correctly answered your Q3.
> The result of the MATMUL is a rank-1 size 7 array of 0s,
> since each element is the sum of an empty array.
>
> You can generate all the code you want as long as you get the right
answer,
> but as Tom says, if somehow you figure out that the MATMUL result is all
0,
> it certainly could be optimized away. So the whole assignment can be
> optimized away (again, if all that can be determined by the compiler).
>
>
> On Wed, Jun 21, 2017 at 1:18 PM, Clune, Thomas L. (GSFC-6101)
<thomas.l.clune at nasa.gov> wrote:
> On Jun 21, 2017, at 2:51 PM, Daniel C Chen <cdchen at ca.ibm.com> wrote:
> Sure. I agree with Q1 and Q2.
>
> As for Q3,
> 1. is the statement standard conforming?
> y(:) = MATMUL( a(:,:), x(:) ) + 2*y(:)
>
>
> Yes.
>
> 2. if it is standard conforming, would it be equivalent to
> y(:) = 2*y(:)
>
> Yes.
> or it should be no code gen for the whole assignment?
> The array y _does_ have elements. The expression changes their values.
The compiler would need to ?know? that all of the elements are initially 0
to skip the assignment, and this has nothing to do with zero-sized things.
>
> - Tom
>
>
> Thanks,
>
> Daniel
>
> XL Fortran Development, Fortran Standard Representative
> IBM Toronto Software Lab
> Phone: 905-413-3056
> Tie: 969-3056
> Email: cdchen at ca.ibm.com
> http://www.ibm.com/software/awdtools/fortran/xlfortran
>
> <graycol.gif>Walt Brainerd ---06/21/2017 01:43:49 PM---Let me try to help
(maybe it won't) with a different point of view. I always thought it was
not the
>
>
> From: Walt Brainerd <walt.brainerd at gmail.com>
> To: fortran standards email list for J3 <j3 at mailman.j3-fortran.org>
> Date: 06/21/2017 01:43 PM
> Subject: Re: (j3.2006) Question about zero-sized array.
> Sent by: j3-bounces at mailman.j3-fortran.org
>
>
>
>
>
> Let me try to help (maybe it won't) with a different point of view.
> I always thought it was not the best to say that x is always defined,
> but since the standard does . . .
>
> For Q1, I would say the value of x is the empty array.
>
> For Q2, I think you are asking the wrong question.
> An *element* of the array can have the value 0.0 or 1.0, but
> x has no elements, and the question is meaningless.
> Also Q3.
>
> Crystal clear?
>
> On Wed, Jun 21, 2017 at 9:37 AM, Daniel C Chen <cdchen at ca.ibm.com> wrote:
> Thanks John and Malcolm for your response. I didn't make the questions
clear enough so I will try again.
>
> As for Q1,
> non-allocatable case:
> real :: x(0) ! x is always defined by the standard. What is its value at
this point?
> allocatable case:
> real, allocatable :: x(:)
> allocate(x0)) ! at this point, x is defined by allocation. Again, what is
the value after allocation?
>
> As for Q2, I actualy meant to ask 'x' rather than 'a'.
> x = 0.0 ! Does x have value 0.0?
> x = 1.0 ! x Does x have value 1.0?
>
> As for Q3, if x in Q2 is defined with the value 0.0 or 1.0 and used in
the following statement respectively,
> a(:,:) = 1.0
> y(:) = MATMUL( a(:,:), x(:) ) + 2*y(:) ! Does the value of x affect the
result?
>
> Thanks,
>
> Daniel
>
> XL Fortran Development, Fortran Standard Representative
> IBM Toronto Software Lab
> Phone: 905-413-3056
> Tie: 969-3056
> Email: cdchen at ca.ibm.com
> http://www.ibm.com/software/awdtools/fortran/xlfortran
>
> <graycol.gif>"Malcolm Cohen" ---06/20/2017 07:52:35 PM---Daniel Chen
asks: > The standard specifies, "Zero-sized arrays and zero-length strings
are
>
>
> From: "Malcolm Cohen" <malcolm at nag-j.co.jp>
> To: "'fortran standards email list for J3'" <j3 at mailman.j3-fortran.org>
> Date: 06/20/2017 07:52 PM
> Subject: Re: (j3.2006) Question about zero-sized array.
> Sent by: j3-bounces at mailman.j3-fortran.org
>
>
>
> Daniel Chen asks:
> > The standard specifies, "Zero-sized arrays and zero-length strings are
> > always defined".
> > It also says "Allocation of a zero-sized array or zero-length character
> > variable causes the array or variable to become defined"
> >
> > Question1: Does it have initial value at all?
>
> John Reid opines:
> >Well, yes. It always has the same value, including initially.
>
> No. Being allocatable or a pointer it is initially undefined.
?initially? means at the beginning of execution; at that point the array
does not have any shape.
>
> Daniel continues::
> > allocate(a(7,0),x(0),y(7))
> > a(:,:) = 0.0 !Q2: Is this legal? What is the value of a?
>
> John replies:
> >Yes, you are broadcasting a scalar to every element of the array. a has
> >the value it always has when the size is zero.
>
> ?it always has? could be a little misleading here; being an array, the
shape is part of the value, so the value is the 7x0 empty array and not the
0x23 empty array. I?m not sure we have all this explicitly written down
anywhere though, except for derived types, where we say the array bounds of
a component are part of the value of the structure. Outside of a structure
it is the shape that?s important rather than the bounds.
>
> Cheers,
> --
> ..............Malcolm Cohen, NAG Oxford/Tokyo.
>
> From: j3-bounces at mailman.j3-fortran.org [
mailto:j3-bounces at mailman.j3-fortran.org] On Behalf Of John Reid
> Sent: Wednesday, June 21, 2017 12:53 AM
> To: fortran standards email list for J3 <j3 at mailman.j3-fortran.org>
> Subject: Re: (j3.2006) Question about zero-sized array.
>
>
>
> Daniel C Chen wrote:
> > Hello,
> >
> > The standard specifies, "Zero-sized arrays and zero-length strings are
> > always defined".
> > It also says "Allocation of a zero-sized array or zero-length character
> > variable causes the array or variable to become defined"
> >
> > Question1: Does it have initial value at all?
>
> Well, yes. It always has the same value, including initially.
>
> > Question2: Can it appear as the LHS of an assignment?
>
> Yes.
>
> > Question3: Can it be used in an expression and have a defined result?
>
> Yes.
> >
> > Please consider the following example:
> >
> > program test
> > real, dimension(:,:), allocatable:: a
> > real, dimension(:), allocatable :: x,y
> >
> > allocate(a(7,0),x(0),y(7))
> > a(:,:) = 0.0 !Q2: Is this legal? What is the value of a?
>
> Yes, you are broadcasting a scalar to every element of the array. a has
> the value it always has when the size is zero.
>
> > x(:) = 0.0
>
> Yes, you are again broadcasting a scalar to every element of the array.
>
> > y(:) = 1.0
> > y(:) = MATMUL( a(:,:), x(:) ) !Q3: Is this legal? what is the value of
y?
>
> Yes. Every element of y has the value 0.0.
>
> > end program test
> >
> > Non-allocatable version:
>
> Nothing is reallocated in the allocatable version, so this is the same.
>
> Cheers,
>
> John.
>
> > program test2
> > real :: a(7,0)
> > real :: x(0),y(7)
> >
> > a = 0.0 !Q2: is this legal? What is the value of a?
> > x = 0.0
> > y = 1.0
> > y = MATMUL( a, x ) !Q3: is this legal? what is the value of y?
> > end program test2
> >
> > Thanks,
> >
> > Daniel
> >
> > XL Fortran Development, Fortran Standard Representative
> > IBM Toronto Software Lab
> > Phone: 905-413-3056
> > Tie: 969-3056
> > Email: cdchen at ca.ibm.com
> > http://www.ibm.com/software/awdtools/fortran/xlfortran
> >
> >
> > _______________________________________________
> > J3 mailing list
> > J3 at mailman.j3-fortran.org
> > http://mailman.j3-fortran.org/mailman/listinfo/j3
> >
> _______________________________________________
> J3 mailing list
> J3 at mailman.j3-fortran.org
> http://mailman.j3-fortran.org/mailman/listinfo/j3
> Disclaimer
>
> The Numerical Algorithms Group Ltd is a company registered in England and
Wales with company number 1249803. The registered office is: Wilkinson
House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom.
>
> This e-mail has been scanned for all viruses and malware, and may have
been automatically archived by Mimecast Ltd, an innovator in Software as a
Service (SaaS) for business._______________________________________________
> J3 mailing list
> J3 at mailman.j3-fortran.org
> http://mailman.j3-fortran.org/mailman/listinfo/j3
>
>
>
> _______________________________________________
> J3 mailing list
> J3 at mailman.j3-fortran.org
> http://mailman.j3-fortran.org/mailman/listinfo/j3
>
>
>
>
> --
> Walt Brainerd_______________________________________________
> J3 mailing list
> J3 at mailman.j3-fortran.org
> http://mailman.j3-fortran.org/mailman/listinfo/j3
>
>
>
> _______________________________________________
> J3 mailing list
> J3 at mailman.j3-fortran.org
> http://mailman.j3-fortran.org/mailman/listinfo/j3
>
>
> _______________________________________________
> J3 mailing list
> J3 at mailman.j3-fortran.org
> http://mailman.j3-fortran.org/mailman/listinfo/j3
>
>
>
> --
> Walt Brainerd_______________________________________________
> J3 mailing list
> J3 at mailman.j3-fortran.org
> http://mailman.j3-fortran.org/mailman/listinfo/j3
>
>
>
> _______________________________________________
> J3 mailing list
> J3 at mailman.j3-fortran.org
> http://mailman.j3-fortran.org/mailman/listinfo/j3
Bill Long
longb at cray.com
Principal Engineer, Fortran Technical Support & voice: 651-605-9024
Bioinformatics Software Development fax: 651-605-9143
Cray Inc./ 2131 Lindau Lane/ Suite 1000/ Bloomington, MN 55425
_______________________________________________
J3 mailing list
J3 at mailman.j3-fortran.org
http://mailman.j3-fortran.org/mailman/listinfo/j3
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.j3-fortran.org/pipermail/j3/attachments/20170622/d1912bc8/attachment-0001.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: graycol.gif
Type: image/gif
Size: 105 bytes
Desc: not available
Url : http://mailman.j3-fortran.org/pipermail/j3/attachments/20170622/d1912bc8/attachment-0001.gif
More information about the J3
mailing list