[J3] Locality of do-variable
Malcolm Cohen
malcolm at nag-j.co.jp
Wed Feb 19 01:16:25 UTC 2025
> This seems to be fulfilled for n <= 1, making it conforming code.
Perhaps more notable is that the code is also conforming if n>1, as j is defined before use in every iteration.
Furthermore, after execution of the do concurrent terminates, if n<1 j is undefined (never given a value), and if n==1, j is defined to be equal to m+1, but if n>1 it is undefined (because it is defined in more than one iteration). That allows parallel execution when n>1.
Cheers,
--
..............Malcolm Cohen, NAG Oxford/Tokyo.
-----Original Message-----
From: J3 <j3-bounces at mailman.j3-fortran.org> On Behalf Of Tobias Burnus via J3
Sent: Tuesday, February 18, 2025 10:35 PM
To: General J3 interest list <j3 at mailman.j3-fortran.org>
Cc: Tobias Burnus <burnus at net-b.de>
Subject: Re: [J3] Locality of do-variable
Klemm, Michael via J3 wrote:
> integer :: i, j
> do concurrent(i=1:n)
> do j=1,m
> ...
> end do
> end do
In my reading of Fortran 2023, 'j' has unspecified locality and this implies "if it is referenced in an iteration it shall either be previously defined during that iteration, or shall not be defined or become undefined during any other iteration."
This seems to be fulfilled for n <= 1, making it conforming code.
> I read the top of page 201 of the Fortran 2023 document such that variable j in the example should (or can) have LOCAL locality, if it does not have the SAVE attribute (which it does not in this example):
I read the second part of the quoted text such that the LOCAL vs. SHARED applies to variables declared inside the do concurrent, e.g. in the specification part of a block construct or inside of a called subroutine or function:
> "The locality of a variable that appears in a DO CONCURRENT construct is LOCAL, LOCAL_INIT, REDUCE, SHARED, or unspecified. A construct or statement entity of a construct or statement within the DO CONCURRENT construct has SHARED locality if it has the SAVE attribute. If it does not have the SAVE attribute, it is a different entity in each iteration, similar to LOCAL locality."
Tobias
More information about the J3
mailing list