[J3] [EXTERNAL] Re: Why is += missing?
Clune, Thomas L. (GSFC-6101)
thomas.l.clune at nasa.gov
Wed Sep 1 12:33:39 UTC 2021
Jeff,
I think you want to allow spaces after the “=” also. Modifying your first git grep to
$ git grep -E "(\b[a-zA-Z].*)=.*(\1)\+" | wc -l
Jumped the results from my main repository from 94 to 668:
I don’t have a strong opinion on the feature in question, but would certainly use it if available. (+= and -=; have rarely wanted *=, and have never wanted “div =”)
For some of the layers of the weather/climate model that I used, I have the following results:
Repository SLOC A = A+ % use
MAPL 145k 668 0.5
GMAO_Shared 331k 9415 2.8
FMS 122k 1920 1.6
NCEP_Shared 84k 1711 2.0
AGCM 1506k 4689 0.3
I suppose another measure that would be useful here is the average size of the expression involved. If all of these look like `x = x + <expr>` then the argument is weaker. My intuition is that most involve array elements with 2-3 indices, with the rarer cases involving “complex” indices.
Cheers,
_ Tom
From: J3 <j3-bounces at mailman.j3-fortran.org> on behalf of j3 <j3 at mailman.j3-fortran.org>
Reply-To: j3 <j3 at mailman.j3-fortran.org>
Date: Wednesday, September 1, 2021 at 2:24 AM
To: j3 <j3 at mailman.j3-fortran.org>
Cc: Jeff Hammond <jehammond at nvidia.com>, Malcolm Cohen <malcolm at nag-j.co.jp>
Subject: [EXTERNAL] Re: [J3] Why is += missing?
> It bloats the language with extra (and un-Fortran-like) syntax. There is a cognitive load associated with the size of a language.
The cost to users of unused language features is zero. If the convenience feature I propose is too much of a mental burden for users, they can ignore it, in the same way that I ignore >50% of the features of Fortran 2018.
Do you genuinely believe that adding the += and -= operators is going to make the cognitive load of Fortran so high as to harm the community? I can understand such an objection to other proposals, but not this one.
> It is not self-explanatory at all; many Fortran users are not familiar with C or C++.
It’s not just C, C++, but Julia, Java, Python, GNU Make, etc. Are you actually going to assert that a substantial fraction Fortran programmers are familiar with so few other common program languages that they are going to be confused by += and subsequently be unable to help themselves using the resources available to them in books and on the internet?
> The density of “+=” and friends in C code is not necessarily a good indication of how widely used it would be in Fortran.
The good news is, we can actually query Fortran codes to see what the use might be. There are no less than 80000 lines of code in NWChem that are eligible to use += alone. There are at least 12000 lines that could use -=. Should I continue? The last time I measured, I had 40M lines of Fortran on my workstation.
src % git grep -E "(\b[a-zA-Z].*)=(\1)\+" | wc -l
11972
src % git grep -E "(\b[a-zA-Z].*) = (\1)\+" | wc -l
2353
src % git grep -E "(\b[a-zA-Z].*)= (\1)\+" | wc -l
64817
src % git grep -E "(\b[a-zA-Z].*) =(\1)\+" | wc -l
51
> for example the SUM intrinsic.
Did you look at the code I shared? Please feel free to suggest the intrinsics that obviate the need for X=X+Y expressions.
do ii=1,nocc
do l=1,nfl
do j=1,nfj
do i=ilo,ihi
do k=klo,khi
int1=eri1(l,k,j,i)*factor
int2=eri2(j,k,l,i)*factor
snsi(i,j,l,ii)=snsi(i,j,l,ii)+t1ao(k,ii)*int1
snsi(k,j,l,ii)=snsi(k,j,l,ii)+t1ao(i,ii)*int2
sisn(k,l,j,ii)=sisn(k,l,j,ii)+t1ao(i,ii)*int1
sisn(i,l,j,ii)=sisn(i,l,j,ii)+t1ao(k,ii)*int2
enddo
enddo
enddo
enddo
enddo
Jeff
From: J3 <j3-bounces at mailman.j3-fortran.org> on behalf of Malcolm Cohen via J3 <j3 at mailman.j3-fortran.org>
Date: Thursday, August 26, 2021 at 5:47 AM
To: 'General J3 interest list' <j3 at mailman.j3-fortran.org>
Cc: Malcolm Cohen <malcolm at nag-j.co.jp>
Subject: Re: [J3] Why is += missing?
External email: Use caution opening links or attachments
Well, I don’t like it.
Below are some reasons and comments. Perhaps not overly compelling, but they are, I think, quite valid reasons for not doing this.
A: It bloats the language with extra (and un-Fortran-like) syntax. There is a cognitive load associated with the size of a language.
B: Then there’s the “why not operator= for all operators”. Doing that would change it from a smallish feature into a largish feature (quite apart from the ambiguity with /=). Not doing that would result in C-familiar user annoyance when the “obvious” things did not work.
C: It is not self-explanatory at all; many Fortran users are not familiar with C or C++.
D: As noted by someone else, it is not the same as X = X + expr, because the compiler can evaluate any mathematical equivalent to “X+expr”, and that is lost with the “obvious” semantics of “add expr to X”. With FMA and similar being quite popular these days, I’d expect some but not all compilers would violate those semantics at least some of the time by turning it back into X=X+expr (to avoid losing performance and accuracy). That’s a recipe for reduced portability.
E: The density of “+=” and friends in C code is not necessarily a good indication of how widely used it would be in Fortran. Quite apart from some uses of += being trivial (N=N+2 is certainly not less readable than N+=2), and some already being handled by ASSOCIATE as previously mentioned, some cases might be covered by a totally different Fortran feature, for example the SUM intrinsic.
F: For that matter, “++” is likely widely used in C codes. That does not mean it would be a good fit for Fortran.
For me, “B” by itself is sufficient to make this not worthwhile.
Cheers,
--
..............Malcolm Cohen, NAG Oxford/Tokyo.
From: J3 <j3-bounces at mailman.j3-fortran.org> On Behalf Of Damian Rouson via J3
Sent: Thursday, August 26, 2021 8:47 AM
To: General J3 interest list <j3 at mailman.j3-fortran.org>
Cc: Damian Rouson <damian at sourceryinstitute.org>
Subject: Re: [J3] Why is += missing?
On Wed, Aug 25, 2021 at 6:27 AM Jeff Hammond via J3 <j3 at mailman.j3-fortran.org<mailto:j3 at mailman.j3-fortran.org>> wrote:
I will argue that it is syntactic sugar in the same sense that multidimensional arrays are. Below is the perfectly functional C code I wrote to match my Fortran years ago (because computer scientists don’t know their history). There is no actual need for multidimensional arrays in Fortran, just the practical difficulty of not having them.
// t3(h3,h2,h1,p6,p5,p4)+=t1(p4,h1)*v2(h3,h2,p6,p5);
t3[h3+h3u*(h2+h2u*(h1+h1u*(p6+p6u*(p5+p5u*p4))))] += t1[p4+p4u*h1] * v2[h3+h3u*(h2+h2u*(p6+p6u*p5))];
Jeff,
If I'm interpreting the responses accurately, it sounds like the idea simply fell too far down the list of priorities, but I haven't heard any fundamental resistance modulo syntax. Hopefully that's encouraging.
Is the provided C code really so short or were the nested for loops omitted for the sake of brevity?
Damian
Disclaimer
The Numerical Algorithms Group Ltd is a company registered in England and Wales with company number 1249803. The registered office is: 30 St. Giles, Oxford, OX1 3LE, United Kingdom. Please see our Privacy Notice<https://gcc02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.nag.co.uk%2Fcontent%2Fprivacy-notice&data=04%7C01%7Cthomas.l.clune%40nasa.gov%7C2f6ab5d08240471500b108d96d113021%7C7005d45845be48ae8140d43da96dd17b%7C0%7C0%7C637660742871984498%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=2trI%2B%2BZbwvmdrnmHiowdJbnxrVHG5%2BNdCnYFy0%2Bw%2B%2FE%3D&reserved=0> for information on how we process personal data and for details of how to stop or limit communications from us.
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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20210901/ba6a9e04/attachment-0001.htm>
More information about the J3
mailing list