public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* A question about coarrays and -Warray-temporaries
@ 2021-01-31 15:51 Jorge D'Elia
  2021-02-01  7:42 ` Thomas Koenig
  2021-03-21 16:18 ` A doubt about lbound and ubound of an array inside a coarray Jorge D'Elia
  0 siblings, 2 replies; 13+ messages in thread
From: Jorge D'Elia @ 2021-01-31 15:51 UTC (permalink / raw)
  To: Gfortran List

Hi all,

I have a question with -Warray-temporaries in the test below. 

With the AA coarray that warning appears in the first loop (on its local part), 
but not with the BB array with the same task, i.e.


$ gfortran --version
GNU Fortran (GCC) 11.0.0 20210125 (experimental)
Copyright (C) 2021 Free Software Foundation, Inc.

$ gfortran -march=native -mtune=native -Ofast -fcheck=all -fcoarray=single -std=f2018 -Wall -Wextra -Warray-temporaries -o test.exe test.f90 
test.f90:37:19:

   37 |     AA (k1:nn,j) = AA (k1:nn,j) - UU (k1:nn) * AA (k,j)
      |                   1
Warning: Creating array temporary at (1) [-Warray-temporaries]


Why this difference in behavior? Is it ok? 

Thanks in advance for some clarification. 

Greetings. 
Jorge

program test
  implicit none
  integer, parameter :: iin = kind (1)     
  integer, parameter :: idp = kind (1.0d0) 
  real    (kind=idp), allocatable :: AA (:,:)[:]
  real    (kind=idp), allocatable :: BB (:,:)
  real    (kind=idp), allocatable :: UU (:)
  integer (kind=iin) :: nn, n1, n2
  integer (kind=iin) :: j, k, k1
  !
  nn =  5
  n1 =  1
  n2 = 10
  !
  allocate (AA (1:nn,n1:n2)[*])
  allocate (BB (1:nn,n1:n2))
  allocate (UU (1:nn))
  !
  k  = 1
  k1 = k + 1
  !
  AA = 1.0_idp
  UU = 2.0_idp
  !
  do  j = 1, nn
    AA (k1:nn,j) = AA (k1:nn,j) - UU (k1:nn) * AA (k,j)
  end do
  !
  do  j = 1, nn
    BB (k1:nn,j) = BB (k1:nn,j) - UU (k1:nn) * BB (k,j)
  end do
  !
  deallocate (AA)
  deallocate (BB)
  deallocate (UU)
  !
end program test
--

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: A question about coarrays and -Warray-temporaries
  2021-01-31 15:51 A question about coarrays and -Warray-temporaries Jorge D'Elia
@ 2021-02-01  7:42 ` Thomas Koenig
  2021-02-01 10:43   ` Jorge D'Elia
  2021-02-01 11:52   ` Tobias Burnus
  2021-03-21 16:18 ` A doubt about lbound and ubound of an array inside a coarray Jorge D'Elia
  1 sibling, 2 replies; 13+ messages in thread
From: Thomas Koenig @ 2021-02-01  7:42 UTC (permalink / raw)
  To: Jorge D'Elia, Gfortran List


Hi Jorge,

> I have a question with -Warray-temporaries in the test below.
> 
> With the AA coarray that warning appears in the first loop (on its local part),
> but not with the BB array with the same task, i.e.
> 
> 
> $ gfortran --version
> GNU Fortran (GCC) 11.0.0 20210125 (experimental)
> Copyright (C) 2021 Free Software Foundation, Inc.
> 
> $ gfortran -march=native -mtune=native -Ofast -fcheck=all -fcoarray=single -std=f2018 -Wall -Wextra -Warray-temporaries -o test.exe test.f90
> test.f90:37:19:
> 
>     37 |     AA (k1:nn,j) = AA (k1:nn,j) - UU (k1:nn) * AA (k,j)
>        |                   1
> Warning: Creating array temporary at (1) [-Warray-temporaries]
> 
> 
> Why this difference in behavior? Is it ok?

It seems that dependency checking does not detect that no overlap
can exist in that case, and so generates a temporary.  Probably,
dependency checking was not updated when coarrays were introduced.

This is a missed optimization, not a correctness issue.

Best regards

	Thomas

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: A question about coarrays and -Warray-temporaries
  2021-02-01  7:42 ` Thomas Koenig
@ 2021-02-01 10:43   ` Jorge D'Elia
  2021-02-01 11:52   ` Tobias Burnus
  1 sibling, 0 replies; 13+ messages in thread
From: Jorge D'Elia @ 2021-02-01 10:43 UTC (permalink / raw)
  To: Thomas Koenig; +Cc: Gfortran List

Hi Thomas,

----- Mensaje original -----
> De: "Thomas Koenig" <tkoenig@netcologne.de>
> Para: "jdelia" <jdelia@cimec.unl.edu.ar>, "Gfortran List" <fortran@gcc.gnu.org>
> CC: "Jorge D'Elia" <jdelia@intec.unl.edu.ar>
> Enviados: Lunes, 1 de Febrero 2021 4:42:19
> Asunto: Re: A question about coarrays and -Warray-temporaries
>
> Hi Jorge,
> 
>> I have a question with -Warray-temporaries in the test below.
>> 
>> With the AA coarray that warning appears in the first loop (on its local part),
>> but not with the BB array with the same task, i.e.
>> 
>> 
>> $ gfortran --version
>> GNU Fortran (GCC) 11.0.0 20210125 (experimental)
>> Copyright (C) 2021 Free Software Foundation, Inc.
>> 
>> $ gfortran -march=native -mtune=native -Ofast -fcheck=all -fcoarray=single
>> -std=f2018 -Wall -Wextra -Warray-temporaries -o test.exe test.f90
>> test.f90:37:19:
>> 
>>     37 |     AA (k1:nn,j) = AA (k1:nn,j) - UU (k1:nn) * AA (k,j)
>>        |                   1
>> Warning: Creating array temporary at (1) [-Warray-temporaries]
>> 
>> 
>> Why this difference in behavior? Is it ok?
> 
> It seems that dependency checking does not detect that no overlap
> can exist in that case, and so generates a temporary.  Probably,
> dependency checking was not updated when coarrays were introduced.

Ok.

> This is a missed optimization, not a correctness issue.

Yes, you're right. Nevertheless it would be very interesting in 
the (near?) future to have that optimization for coarrays. 
 
> Best regards
> 
> 	Thomas

Thanks for your reply. 

Regards.
Jorge.
--

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: A question about coarrays and -Warray-temporaries
  2021-02-01  7:42 ` Thomas Koenig
  2021-02-01 10:43   ` Jorge D'Elia
@ 2021-02-01 11:52   ` Tobias Burnus
  2021-02-02 11:46     ` [Patch] Fortran: Fix Array dependency with local coarrays [PR98913] (was: Re: A question about coarrays and -Warray-temporaries) Tobias Burnus
  1 sibling, 1 reply; 13+ messages in thread
From: Tobias Burnus @ 2021-02-01 11:52 UTC (permalink / raw)
  To: Thomas Koenig, Jorge D'Elia, Gfortran List

Hi Thomas & Jorge,

On 01.02.21 08:42, Thomas Koenig via Fortran wrote:
>> I have a question with -Warray-temporaries in the test below.
>> With the AA coarray that warning appears in the first loop (on its
>> local part),
>> but not with the BB array with the same task, i.e. [...]
> It seems that dependency checking does not detect that no overlap
> can exist in that case, and so generates a temporary.  Probably,
> dependency checking was not updated when coarrays were introduced.
> This is a missed optimization, not a correctness issue.

I have now filled https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98913

Tobias

-----------------
Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany
Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander Walter

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Patch] Fortran: Fix Array dependency with local coarrays [PR98913] (was: Re: A question about coarrays and -Warray-temporaries)
  2021-02-01 11:52   ` Tobias Burnus
@ 2021-02-02 11:46     ` Tobias Burnus
  2021-02-02 14:32       ` Jorge D'Elia
  2021-02-02 14:54       ` Thomas Koenig
  0 siblings, 2 replies; 13+ messages in thread
From: Tobias Burnus @ 2021-02-02 11:46 UTC (permalink / raw)
  To: Thomas Koenig, Jorge D'Elia, Gfortran List, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 1730 bytes --]

Hi all,

the attached patch now handles -fcoarray=single and access to the local
image like no coarray access, using the same check a before.

Actually, I think we could remove the if (..coarray..) check completely:
For 'single', it is like no coarrays; for 'lib' both AA[remote] =... and
"AA = ... AA[remove]" will create a function call and uses already
temporaries. I don't know what 'native'/'threads' does – but either it
the image index is different, then no temporary is needed at all – or it
is the same (in particular: this_image / not present), but then the
noncoarray analysis would work.

(Knowing that for i != this_image(), AA and AA[i] – or i /= j for AA[i]
and AA[j] – we could further relax the checks, but I don't think that
that's needed.)

Hence: Is the patch OK for the trunk? Or should we completely get rid of
if-conditional block?

Tobias

On 01.02.21 12:52, Tobias Burnus wrote:

> On 01.02.21 08:42, Thomas Koenig via Fortran wrote:
>>> I have a question with -Warray-temporaries in the test below.
>>> With the AA coarray that warning appears in the first loop (on its
>>> local part),
>>> but not with the BB array with the same task, i.e. [...]
>> It seems that dependency checking does not detect that no overlap
>> can exist in that case, and so generates a temporary.  Probably,
>> dependency checking was not updated when coarrays were introduced.
>> This is a missed optimization, not a correctness issue.
> I have now filled https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98913
-----------------
Mentor Graphics (Deutschland) GmbH, Arnulfstrasse 201, 80634 München Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Frank Thürauf

[-- Attachment #2: dep-caf.diff --]
[-- Type: text/x-patch, Size: 3927 bytes --]

Fortran: Fix Array dependency with local coarrays [PR98913]

gcc/fortran/ChangeLog:

	PR fortran/98913
	* dependency.c (gfc_dep_resolver): Treat local access
	to coarrays like any array access in dependency analysis.

gcc/testsuite/ChangeLog:

	PR fortran/98913
	* gfortran.dg/coarray/array_temporary.f90: New test.

 gcc/fortran/dependency.c                           | 11 +++-
 .../gfortran.dg/coarray/array_temporary.f90        | 74 ++++++++++++++++++++++
 2 files changed, 83 insertions(+), 2 deletions(-)

diff --git a/gcc/fortran/dependency.c b/gcc/fortran/dependency.c
index c9baca80cbc..0de5d093aab 100644
--- a/gcc/fortran/dependency.c
+++ b/gcc/fortran/dependency.c
@@ -30,6 +30,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "dependency.h"
 #include "constructor.h"
 #include "arith.h"
+#include "options.h"
 
 /* static declarations */
 /* Enums  */
@@ -2143,8 +2144,14 @@ gfc_dep_resolver (gfc_ref *lref, gfc_ref *rref, gfc_reverse *reverse,
 
 	case REF_ARRAY:
 
-	  /* For now, treat all coarrays as dangerous.  */
-	  if (lref->u.ar.codimen || rref->u.ar.codimen)
+	  /* For now, treat all nonlocal coarrays as dangerous.  */
+	  if (flag_coarray != GFC_FCOARRAY_SINGLE
+	      && ((lref->u.ar.codimen
+		   && lref->u.ar.dimen_type[lref->u.ar.dimen]
+		      != DIMEN_THIS_IMAGE)
+		  || (rref->u.ar.codimen
+		      && lref->u.ar.dimen_type[lref->u.ar.dimen]
+			 != DIMEN_THIS_IMAGE)))
 	    return 1;
 
 	  if (ref_same_as_full_array (lref, rref))
diff --git a/gcc/testsuite/gfortran.dg/coarray/array_temporary.f90 b/gcc/testsuite/gfortran.dg/coarray/array_temporary.f90
new file mode 100644
index 00000000000..86460a7c282
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/coarray/array_temporary.f90
@@ -0,0 +1,74 @@
+! { dg-do compile }
+! { dg-additional-options "-Warray-temporaries" }
+!
+! PR fortran/98913
+!
+! Contributed by Jorge D'Elia
+!
+! Did create an array temporary for local access to coarray
+! (but not for identical noncoarray use).
+!
+
+program test
+  implicit none
+  integer, parameter :: iin = kind (1)     
+  integer, parameter :: idp = kind (1.0d0) 
+  real    (kind=idp), allocatable :: AA (:,:)[:]
+  real    (kind=idp), allocatable :: BB (:,:)
+  real    (kind=idp), allocatable :: UU (:)
+  integer (kind=iin) :: nn, n1, n2
+  integer (kind=iin) :: j, k, k1
+  !
+  nn =  5
+  n1 =  1
+  n2 = 10
+  !
+  allocate (AA (1:nn,n1:n2)[*])
+  allocate (BB (1:nn,n1:n2))
+  allocate (UU (1:nn))
+  !
+  k  = 1
+  k1 = k + 1
+  !
+  AA = 1.0_idp
+  BB = 1.0_idp
+  UU = 2.0_idp
+
+  ! AA - coarrays
+  ! No temporary needed:
+  do  j = 1, nn
+    AA (k1:nn,j) = AA (k1:nn,j) - UU (k1:nn) * AA (k,j)  ! { dg-bogus "Creating array temporary" }
+  end do
+  do  j = 1, nn
+    AA (k1:nn,j) = AA (k1:nn,j) - UU (k1:nn) * AA (k,j) - UU(k) * AA (k1-1:nn-1,j)  ! { dg-bogus "Creating array temporary" }
+  end do
+  do  j = 1, nn
+    AA (k1:nn,j) = AA (k1:nn,j) - UU (k1:nn) * AA (k,j) - UU(k) * AA (k1+1:nn+1,j)  ! { dg-bogus "Creating array temporary" }
+  end do
+
+  ! But:
+  do  j = 1, nn
+    AA (k1:nn,j) = AA (k1-1:nn-1,j) - UU (k1:nn) * AA (k,j) - UU(k) * AA (k1+1:nn+1,j)  ! { dg-warning "Creating array temporary" }
+  end do
+
+  ! BB - no coarrays
+  ! No temporary needed:
+  do  j = 1, nn
+    BB (k1:nn,j) = BB (k1:nn,j) - UU (k1:nn) * BB (k,j)  ! { dg-bogus "Creating array temporary" }
+  end do
+  do  j = 1, nn
+    BB (k1:nn,j) = BB (k1:nn,j) - UU (k1:nn) * BB (k,j) - UU(k) * BB (k1-1:nn-1,j)  ! { dg-bogus "Creating array temporary" }
+  end do
+  do  j = 1, nn
+    BB (k1:nn,j) = BB (k1:nn,j) - UU (k1:nn) * BB (k,j) - UU(k) * BB (k1+1:nn+1,j)  ! { dg-bogus "Creating array temporary" }
+  end do
+
+  ! But:
+  do  j = 1, nn
+    BB (k1:nn,j) = BB (k1-1:nn-1,j) - UU (k1:nn) * BB (k,j) - UU(k) * BB (k1+1:nn+1,j)  ! { dg-warning "Creating array temporary" }
+  end do
+
+  deallocate (AA)
+  deallocate (BB)
+  deallocate (UU)
+end program test

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [Patch] Fortran: Fix Array dependency with local coarrays [PR98913] (was: Re: A question about coarrays and -Warray-temporaries)
  2021-02-02 11:46     ` [Patch] Fortran: Fix Array dependency with local coarrays [PR98913] (was: Re: A question about coarrays and -Warray-temporaries) Tobias Burnus
@ 2021-02-02 14:32       ` Jorge D'Elia
  2021-02-02 14:54       ` Thomas Koenig
  1 sibling, 0 replies; 13+ messages in thread
From: Jorge D'Elia @ 2021-02-02 14:32 UTC (permalink / raw)
  To: Tobias Burnus; +Cc: Thomas Koenig, Gfortran List, GCC Patches

Hi Tobias,,

----- Mensaje original -----
> De: "Tobias Burnus" 
> Para: "Thomas Koenig" , "jdelia" <jdelia@cimec.unl.edu.ar>, "Gfortran List"
> gcc.gnu.org>, "GCC Patches" <gcc-patches@gcc.gnu.org>
> Enviados: Martes, 2 de Febrero 2021 8:46:00
> Asunto: [Patch] Fortran: Fix Array dependency with local coarrays [PR98913] (was: Re: A question about coarrays and
> -Warray-temporaries)
>
> Hi all,
> 
> the attached patch now handles -fcoarray=single and access to the local
> image like no coarray access, using the same check a before.

I would like to apply the patch but, sorry, how do I proceed? 
Where in the gcc tree to apply the patch file? 
Should I use git apply or diff? e.g. it does not work with

$ pwd
/home/bigpack/gcc-paq/sources/gcc-11.0-20210202
$ git apply dep-caf.diff
error: patch failed: gcc/fortran/dependency.c:30
error: gcc/fortran/dependency.c: patch does not apply

> Actually, I think we could remove the if (..coarray..) check completely:
> For 'single', it is like no coarrays; for 'lib' both AA[remote] =... and
> "AA = ... AA[remove]" will create a function call and uses already
> temporaries. I don't know what 'native'/'threads' does – but either it
> the image index is different, then no temporary is needed at all – or it
> is the same (in particular: this_image / not present), but then the
> noncoarray analysis would work.
> 
> (Knowing that for i != this_image(), AA and AA[i] – or i /= j for AA[i]
> and AA[j] – we could further relax the checks, but I don't think that
> that's needed.)
> 
> Hence: Is the patch OK for the trunk? Or should we completely get rid of
> if-conditional block?

Thanks for the fast work with this code optimization issue.

Regards,
Jorge.

> --
> On 01.02.21 12:52, Tobias Burnus wrote:
> 
>> On 01.02.21 08:42, Thomas Koenig via Fortran wrote:
>>>> I have a question with -Warray-temporaries in the test below.
>>>> With the AA coarray that warning appears in the first loop (on its
>>>> local part),
>>>> but not with the BB array with the same task, i.e. [...]
>>> It seems that dependency checking does not detect that no overlap
>>> can exist in that case, and so generates a temporary.  Probably,
>>> dependency checking was not updated when coarrays were introduced.
>>> This is a missed optimization, not a correctness issue.
>> I have now filled https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98913
> -----------------
> Mentor Graphics (Deutschland) GmbH, Arnulfstrasse 201, 80634 München
> Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Frank
> Thürauf

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [Patch] Fortran: Fix Array dependency with local coarrays [PR98913] (was: Re: A question about coarrays and -Warray-temporaries)
  2021-02-02 11:46     ` [Patch] Fortran: Fix Array dependency with local coarrays [PR98913] (was: Re: A question about coarrays and -Warray-temporaries) Tobias Burnus
  2021-02-02 14:32       ` Jorge D'Elia
@ 2021-02-02 14:54       ` Thomas Koenig
  2021-02-02 17:15         ` Tobias Burnus
  1 sibling, 1 reply; 13+ messages in thread
From: Thomas Koenig @ 2021-02-02 14:54 UTC (permalink / raw)
  To: Tobias Burnus, Jorge D'Elia, Gfortran List, gcc-patches

Am 02.02.21 um 12:46 schrieb Tobias Burnus:
> Hi all,
> 
> the attached patch now handles -fcoarray=single and access to the local
> image like no coarray access, using the same check a before.
> 
> Actually, I think we could remove the if (..coarray..) check completely:
> For 'single', it is like no coarrays; for 'lib' both AA[remote] =... and
> "AA = ... AA[remove]" will create a function call and uses already
> temporaries. I don't know what 'native'/'threads' does – but either it
> the image index is different, then no temporary is needed at all – or it
> is the same (in particular: this_image / not present), but then the
> noncoarray analysis would work.

That analysis is correct, also as far as the shared memory coarray goes
(where you do offsets as an extra dimension, either it points to the
same memory or to different memory).

So, while your patch is OK, I think a simple removal of the test
is also OK.

Take your pick :-)

Best regards

	Thomas


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [Patch] Fortran: Fix Array dependency with local coarrays [PR98913] (was: Re: A question about coarrays and -Warray-temporaries)
  2021-02-02 14:54       ` Thomas Koenig
@ 2021-02-02 17:15         ` Tobias Burnus
  2021-02-09 11:52           ` [Patch] Fortran: Fix coarray handling for gfc_dep_resolver [PR99010] (was: Re: [Patch] Fortran: Fix Array dependency with local coarrays [PR98913] Tobias Burnus
  0 siblings, 1 reply; 13+ messages in thread
From: Tobias Burnus @ 2021-02-02 17:15 UTC (permalink / raw)
  To: Thomas Koenig, Jorge D'Elia, Gfortran List, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 578 bytes --]

Hi Thomas,

On 02.02.21 15:54, Thomas Koenig wrote:
> So, while your patch is OK, I think a simple removal of the test
> is also OK.
> Take your pick :-)

I think I will do a combination: If 'identical' is true, I think I
cannot remove it. If it is false, it can be identical or nonoverlapping
– which makes sense.

Unless there are further comments, I will commit it later.

Tobias

-----------------
Mentor Graphics (Deutschland) GmbH, Arnulfstrasse 201, 80634 München Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Frank Thürauf

[-- Attachment #2: dep-caf-v2.diff --]
[-- Type: text/x-patch, Size: 4219 bytes --]

Fortran: Fix Array dependency with local coarrays [PR98913]

gcc/fortran/ChangeLog:

	PR fortran/98913
	* dependency.c (gfc_dep_resolver): Treat local access
	to coarrays like any array access in dependency analysis.

gcc/testsuite/ChangeLog:

	PR fortran/98913
	* gfortran.dg/coarray/array_temporary.f90: New test.

 gcc/fortran/dependency.c                           | 15 ++++-
 .../gfortran.dg/coarray/array_temporary.f90        | 74 ++++++++++++++++++++++
 2 files changed, 86 insertions(+), 3 deletions(-)

diff --git a/gcc/fortran/dependency.c b/gcc/fortran/dependency.c
index c9baca80cbc..58593ba535b 100644
--- a/gcc/fortran/dependency.c
+++ b/gcc/fortran/dependency.c
@@ -30,6 +30,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "dependency.h"
 #include "constructor.h"
 #include "arith.h"
+#include "options.h"
 
 /* static declarations */
 /* Enums  */
@@ -2142,9 +2143,17 @@ gfc_dep_resolver (gfc_ref *lref, gfc_ref *rref, gfc_reverse *reverse,
 	  return (fin_dep == GFC_DEP_OVERLAP) ? 1 : 0;
 
 	case REF_ARRAY:
-
-	  /* For now, treat all coarrays as dangerous.  */
-	  if (lref->u.ar.codimen || rref->u.ar.codimen)
+	  /* Coarrays: If there is a coindex, either the image differs and there
+	     is no overlap or the image is the same - then the normal analysis
+	     applies.  Hence, return early only if 'identical' is required and
+	     either ref is coindexed and more than one image can exist.  */
+	  if (identical && flag_coarray != GFC_FCOARRAY_SINGLE
+	      && ((lref->u.ar.codimen
+		   && lref->u.ar.dimen_type[lref->u.ar.dimen]
+		      != DIMEN_THIS_IMAGE)
+		  || (rref->u.ar.codimen
+		      && lref->u.ar.dimen_type[lref->u.ar.dimen]
+			 != DIMEN_THIS_IMAGE)))
 	    return 1;
 
 	  if (ref_same_as_full_array (lref, rref))
diff --git a/gcc/testsuite/gfortran.dg/coarray/array_temporary.f90 b/gcc/testsuite/gfortran.dg/coarray/array_temporary.f90
new file mode 100644
index 00000000000..86460a7c282
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/coarray/array_temporary.f90
@@ -0,0 +1,74 @@
+! { dg-do compile }
+! { dg-additional-options "-Warray-temporaries" }
+!
+! PR fortran/98913
+!
+! Contributed by Jorge D'Elia
+!
+! Did create an array temporary for local access to coarray
+! (but not for identical noncoarray use).
+!
+
+program test
+  implicit none
+  integer, parameter :: iin = kind (1)     
+  integer, parameter :: idp = kind (1.0d0) 
+  real    (kind=idp), allocatable :: AA (:,:)[:]
+  real    (kind=idp), allocatable :: BB (:,:)
+  real    (kind=idp), allocatable :: UU (:)
+  integer (kind=iin) :: nn, n1, n2
+  integer (kind=iin) :: j, k, k1
+  !
+  nn =  5
+  n1 =  1
+  n2 = 10
+  !
+  allocate (AA (1:nn,n1:n2)[*])
+  allocate (BB (1:nn,n1:n2))
+  allocate (UU (1:nn))
+  !
+  k  = 1
+  k1 = k + 1
+  !
+  AA = 1.0_idp
+  BB = 1.0_idp
+  UU = 2.0_idp
+
+  ! AA - coarrays
+  ! No temporary needed:
+  do  j = 1, nn
+    AA (k1:nn,j) = AA (k1:nn,j) - UU (k1:nn) * AA (k,j)  ! { dg-bogus "Creating array temporary" }
+  end do
+  do  j = 1, nn
+    AA (k1:nn,j) = AA (k1:nn,j) - UU (k1:nn) * AA (k,j) - UU(k) * AA (k1-1:nn-1,j)  ! { dg-bogus "Creating array temporary" }
+  end do
+  do  j = 1, nn
+    AA (k1:nn,j) = AA (k1:nn,j) - UU (k1:nn) * AA (k,j) - UU(k) * AA (k1+1:nn+1,j)  ! { dg-bogus "Creating array temporary" }
+  end do
+
+  ! But:
+  do  j = 1, nn
+    AA (k1:nn,j) = AA (k1-1:nn-1,j) - UU (k1:nn) * AA (k,j) - UU(k) * AA (k1+1:nn+1,j)  ! { dg-warning "Creating array temporary" }
+  end do
+
+  ! BB - no coarrays
+  ! No temporary needed:
+  do  j = 1, nn
+    BB (k1:nn,j) = BB (k1:nn,j) - UU (k1:nn) * BB (k,j)  ! { dg-bogus "Creating array temporary" }
+  end do
+  do  j = 1, nn
+    BB (k1:nn,j) = BB (k1:nn,j) - UU (k1:nn) * BB (k,j) - UU(k) * BB (k1-1:nn-1,j)  ! { dg-bogus "Creating array temporary" }
+  end do
+  do  j = 1, nn
+    BB (k1:nn,j) = BB (k1:nn,j) - UU (k1:nn) * BB (k,j) - UU(k) * BB (k1+1:nn+1,j)  ! { dg-bogus "Creating array temporary" }
+  end do
+
+  ! But:
+  do  j = 1, nn
+    BB (k1:nn,j) = BB (k1-1:nn-1,j) - UU (k1:nn) * BB (k,j) - UU(k) * BB (k1+1:nn+1,j)  ! { dg-warning "Creating array temporary" }
+  end do
+
+  deallocate (AA)
+  deallocate (BB)
+  deallocate (UU)
+end program test

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Patch] Fortran: Fix coarray handling for gfc_dep_resolver [PR99010] (was: Re: [Patch] Fortran: Fix Array dependency with local coarrays [PR98913]
  2021-02-02 17:15         ` Tobias Burnus
@ 2021-02-09 11:52           ` Tobias Burnus
  2021-02-13 19:57             ` Tobias Burnus
  2021-02-19  9:33             ` *PING**2 " Tobias Burnus
  0 siblings, 2 replies; 13+ messages in thread
From: Tobias Burnus @ 2021-02-09 11:52 UTC (permalink / raw)
  To: Thomas Koenig, Jorge D'Elia, Gfortran List, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 1003 bytes --]

Hi all, hi Thomas,

On 02.02.21 18:15, Tobias Burnus wrote:
> I think I will do a combination: If 'identical' is true, I think I
> cannot remove it. If it is false, it can be identical or nonoverlapping
> – which makes sense.

Well, it turned out that coarray scalars did not work; for them,
the array ref consists only of the coindexed access: falling through
then triggered as fin_dep == GFC_DEP_ERROR.

To be more careful, I also removed the 'identical &&' check such that
the first loop is now always triggered if coarray != SINGLE not only
if identical – I am not sure whether it is really needed or whether
falling though is the better solution (with updating the comment).

I would be happy if someone could carefully check the logic –
in the details, it is rather confusing.

OK?

Tobias

-----------------
Mentor Graphics (Deutschland) GmbH, Arnulfstrasse 201, 80634 München Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Frank Thürauf

[-- Attachment #2: caf-dep-fix.diff --]
[-- Type: text/x-patch, Size: 2491 bytes --]

Fortran: Fix coarray handling for gfc_dep_resolver [PR99010]

Check failed if identical = false was requested or for -fcoarray=single
if an array ref was for a coindexed scalar.

gcc/fortran/ChangeLog:

	PR fortran/99010
	* dependency.c (gfc_dep_resolver): Fix coarray handling.

gcc/testsuite/ChangeLog:

	PR fortran/99010
	* gfortran.dg/coarray/array_temporary-1.f90: New test.

 gcc/fortran/dependency.c                                | 14 +++++++++++---
 gcc/testsuite/gfortran.dg/coarray/array_temporary-1.f90 | 13 +++++++++++++
 2 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/gcc/fortran/dependency.c b/gcc/fortran/dependency.c
index 5de3b2cf520..e1336e1c654 100644
--- a/gcc/fortran/dependency.c
+++ b/gcc/fortran/dependency.c
@@ -2145,9 +2145,9 @@ gfc_dep_resolver (gfc_ref *lref, gfc_ref *rref, gfc_reverse *reverse,
 	case REF_ARRAY:
 	  /* Coarrays: If there is a coindex, either the image differs and there
 	     is no overlap or the image is the same - then the normal analysis
-	     applies.  Hence, return early only if 'identical' is required and
-	     either ref is coindexed and more than one image can exist.  */
-	  if (identical && flag_coarray != GFC_FCOARRAY_SINGLE
+	     applies.  Hence, return early if either ref is coindexed and more
+	     than one image can exist.  */
+	  if (flag_coarray != GFC_FCOARRAY_SINGLE
 	      && ((lref->u.ar.codimen
 		   && lref->u.ar.dimen_type[lref->u.ar.dimen]
 		      != DIMEN_THIS_IMAGE)
@@ -2155,6 +2155,14 @@ gfc_dep_resolver (gfc_ref *lref, gfc_ref *rref, gfc_reverse *reverse,
 		      && lref->u.ar.dimen_type[lref->u.ar.dimen]
 			 != DIMEN_THIS_IMAGE)))
 	    return 1;
+	  if (lref->u.ar.dimen == 0 || rref->u.ar.dimen == 0)
+	    {
+	      /* Coindexed scalar coarray with GFC_FCOARRAY_SINGLE.  */
+	      if (lref->u.ar.dimen || rref->u.ar.dimen)
+		return 1;  /* Just to be sure.  */
+	      fin_dep = GFC_DEP_EQUAL;
+	      break;
+	    }
 
 	  if (ref_same_as_full_array (lref, rref))
 	    return identical;
diff --git a/gcc/testsuite/gfortran.dg/coarray/array_temporary-1.f90 b/gcc/testsuite/gfortran.dg/coarray/array_temporary-1.f90
new file mode 100644
index 00000000000..454929cf53b
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/coarray/array_temporary-1.f90
@@ -0,0 +1,13 @@
+! PR fortran/99010
+!
+! Follow-up to PR fortran/98913
+!
+! Contributed by G. Steinmetz
+!
+program p
+   integer :: x[*]
+   x = this_image()
+   if ( this_image() == 2 ) then
+      x = x[1]
+   end if
+end

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [Patch] Fortran: Fix coarray handling for gfc_dep_resolver [PR99010] (was: Re: [Patch] Fortran: Fix Array dependency with local coarrays [PR98913]
  2021-02-09 11:52           ` [Patch] Fortran: Fix coarray handling for gfc_dep_resolver [PR99010] (was: Re: [Patch] Fortran: Fix Array dependency with local coarrays [PR98913] Tobias Burnus
@ 2021-02-13 19:57             ` Tobias Burnus
  2021-02-19  9:33             ` *PING**2 " Tobias Burnus
  1 sibling, 0 replies; 13+ messages in thread
From: Tobias Burnus @ 2021-02-13 19:57 UTC (permalink / raw)
  To: Thomas Koenig, Jorge D'Elia, Gfortran List, gcc-patches; +Cc: Tobias Burnus

*PIN*

On 09.02.21 12:52, Tobias Burnus wrote:
> Hi all, hi Thomas,
>
> On 02.02.21 18:15, Tobias Burnus wrote:
>> I think I will do a combination: If 'identical' is true, I think I
>> cannot remove it. If it is false, it can be identical or nonoverlapping
>> – which makes sense.
>
> Well, it turned out that coarray scalars did not work; for them,
> the array ref consists only of the coindexed access: falling through
> then triggered as fin_dep == GFC_DEP_ERROR.
>
> To be more careful, I also removed the 'identical &&' check such that
> the first loop is now always triggered if coarray != SINGLE not only
> if identical – I am not sure whether it is really needed or whether
> falling though is the better solution (with updating the comment).
>
> I would be happy if someone could carefully check the logic –
> in the details, it is rather confusing.
>
> OK?
>
> Tobias
>
> -----------------
> Mentor Graphics (Deutschland) GmbH, Arnulfstrasse 201, 80634 München 
> Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, 
> Frank Thürauf

^ permalink raw reply	[flat|nested] 13+ messages in thread

* *PING**2 Re: [Patch] Fortran: Fix coarray handling for gfc_dep_resolver [PR99010] (was: Re: [Patch] Fortran: Fix Array dependency with local coarrays [PR98913]
  2021-02-09 11:52           ` [Patch] Fortran: Fix coarray handling for gfc_dep_resolver [PR99010] (was: Re: [Patch] Fortran: Fix Array dependency with local coarrays [PR98913] Tobias Burnus
  2021-02-13 19:57             ` Tobias Burnus
@ 2021-02-19  9:33             ` Tobias Burnus
  2021-02-19 16:25               ` Jerry DeLisle
  1 sibling, 1 reply; 13+ messages in thread
From: Tobias Burnus @ 2021-02-19  9:33 UTC (permalink / raw)
  To: Thomas Koenig, Jorge D'Elia, Gfortran List, gcc-patches


On 09.02.21 12:52, Tobias Burnus wrote:
> Hi all, hi Thomas,
>
> On 02.02.21 18:15, Tobias Burnus wrote:
>> I think I will do a combination: If 'identical' is true, I think I
>> cannot remove it. If it is false, it can be identical or nonoverlapping
>> – which makes sense.
>
> Well, it turned out that coarray scalars did not work; for them,
> the array ref consists only of the coindexed access: falling through
> then triggered as fin_dep == GFC_DEP_ERROR.
>
> To be more careful, I also removed the 'identical &&' check such that
> the first loop is now always triggered if coarray != SINGLE not only
> if identical – I am not sure whether it is really needed or whether
> falling though is the better solution (with updating the comment).
>
> I would be happy if someone could carefully check the logic –
> in the details, it is rather confusing.
>
> OK?
>
> Tobias
>
-----------------
Mentor Graphics (Deutschland) GmbH, Arnulfstrasse 201, 80634 München Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Frank Thürauf

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: *PING**2 Re: [Patch] Fortran: Fix coarray handling for gfc_dep_resolver [PR99010] (was: Re: [Patch] Fortran: Fix Array dependency with local coarrays [PR98913]
  2021-02-19  9:33             ` *PING**2 " Tobias Burnus
@ 2021-02-19 16:25               ` Jerry DeLisle
  0 siblings, 0 replies; 13+ messages in thread
From: Jerry DeLisle @ 2021-02-19 16:25 UTC (permalink / raw)
  To: Tobias Burnus, Thomas Koenig, Jorge D'Elia, Gfortran List,
	gcc-patches

On 2/19/21 1:33 AM, Tobias Burnus wrote:
>
> On 09.02.21 12:52, Tobias Burnus wrote:
>> Hi all, hi Thomas,
>>
>> On 02.02.21 18:15, Tobias Burnus wrote:
>>> I think I will do a combination: If 'identical' is true, I think I
>>> cannot remove it. If it is false, it can be identical or nonoverlapping
>>> – which makes sense.
>>
>> Well, it turned out that coarray scalars did not work; for them,
>> the array ref consists only of the coindexed access: falling through
>> then triggered as fin_dep == GFC_DEP_ERROR.
>>
>> To be more careful, I also removed the 'identical &&' check such that
>> the first loop is now always triggered if coarray != SINGLE not only
>> if identical – I am not sure whether it is really needed or whether
>> falling though is the better solution (with updating the comment).
>>
>> I would be happy if someone could carefully check the logic –
>> in the details, it is rather confusing.
>>
>> OK?
>>
Yes OK, thanks for patch.

Jerry


^ permalink raw reply	[flat|nested] 13+ messages in thread

* A doubt about lbound and ubound of an array inside a coarray
  2021-01-31 15:51 A question about coarrays and -Warray-temporaries Jorge D'Elia
  2021-02-01  7:42 ` Thomas Koenig
@ 2021-03-21 16:18 ` Jorge D'Elia
  1 sibling, 0 replies; 13+ messages in thread
From: Jorge D'Elia @ 2021-03-21 16:18 UTC (permalink / raw)
  To: Gfortran List

Hi all,
 
I have a doubt about lbound and bound in the test below 
using gfortran with opencoarrays, gasnet, and openmpi.

With the AA coarray (each AA entry is a 2D array), 
the values obtained with lbound and ubound are different 
from the initial and final values arbitrarily defined for 
each array entry. 

Is this ok and did I miss something here? 

Thanks in advance for some clarification.

Regards.
Jorge.

$ which gfortran
/usr/beta/gcc-trunk/bin/gfortran

$ gfortran --version
GNU Fortran (GCC) 11.0.1 20210315 (experimental)
Copyright (C) 2021 Free Software Foundation, Inc.

$ which ompi_info
/usr/beta/openmpi/bin/ompi_info

$ ompi_info
  ...
  /usr/beta/gcc-trunk/bin/gfortran

$ mpifort -Wall -Wextra -g -fcoarray=lib doubt1.f90 -o doubt1-openmpi.exe -L/usr/beta/opencoarrays-openmpi/lib64 -lcaf_mpi -lopencoarrays_mod -lmpi

$ mpirun --mca pml ucx --mca osc ucx -np 4 --mca btl vader,self,tcp --machinefile ${HOME}/machi-openmpi.dat --map-by node --map-by slot --map-by core --bind-to l2cache --mca orte_base_help_aggregate 0 --report-bindings --display-allocation --display-devel-map  doubt1-openmpi.exe
 
======================   ALLOCATED NODES   ======================
        flags=0x11 slots=16 max_slots=16 slots_inuse=0 state=UP
=================================================================
 Data for JOB [53806,1] offset 0 Total slots allocated 16

 Mapper requested: NULL  Last mapper: round_robin  Mapping policy: BYCORE:NOOVERSUBSCRIBE  Ranking policy: CORE
 Binding policy: L2CACHE  Cpu set: NULL  PPR: NULL  Cpus-per-rank: 0
         Num new daemons: 0        New daemon starting vpid INVALID
         Num nodes: 1

 Data for node: State: 3        Flags: 11
         Daemon: [[53806,0],0]        Daemon launched: True
         Num slots: 16        Slots in use: 4        Oversubscribed: FALSE
         Num slots allocated: 16        Max slots: 16
         Num procs: 4        Next node_rank: 4
         Data for proc: [[53806,1],0]
                 Pid: 0        Local rank: 0        Node rank: 0        App rank: 0
                 State: INITIALIZED        App_context: 0
                 Locale:  [BB/../../..]
                 Binding: [BB/../../..]
         Data for proc: [[53806,1],1]
                 Pid: 0        Local rank: 1        Node rank: 1        App rank: 1
                 State: INITIALIZED        App_context: 0
                 Locale:  [../BB/../..]
                 Binding: [../BB/../..]
         Data for proc: [[53806,1],2]
                 Pid: 0        Local rank: 2        Node rank: 2        App rank: 2
                 State: INITIALIZED        App_context: 0
                 Locale:  [../../BB/..]
                 Binding: [../../BB/..]
         Data for proc: [[53806,1],3]
                 Pid: 0        Local rank: 3        Node rank: 3        App rank: 3
                 State: INITIALIZED        App_context: 0
                 Locale:  [../../../BB]
                 Binding: [../../../BB]
[55028] MCW rank 0 bound to socket 0[core 0[hwt 0-1]]: [BB/../../..]
[55028] MCW rank 1 bound to socket 0[core 1[hwt 0-1]]: [../BB/../..]
[55028] MCW rank 2 bound to socket 0[core 2[hwt 0-1]]: [../../BB/..]
[55028] MCW rank 3 bound to socket 0[core 3[hwt 0-1]]: [../../../BB]

  ti h lbound(aa%oo,1) ubound(aa%oo,1) lbound(aa%oo,2) ubound(aa%oo,2)
           1           1           1           2           1           2
           3           1           1           2           1           2
           4           1           1           2           1           2
           2           1           1           2           1           2
           2           2           1           3           1           3
           1           2           1           3           1           3
           4           2           1           3           1           3
           3           2           1           3           1           3
           3           3           1           4           1           4
           2           3           1           4           1           4
           1           3           1           4           1           4
           4           3           1           4           1           4
           4           4           1           5           1           5
           3           4           1           5           1           5
           2           4           1           5           1           5
           1           4           1           5           1           5

  ti h aa[h]%i1 aa[h]%i2 aa[h]%j1 aa[h]%j1 aa[h]%j2
           1           1           2           3           4           5
           2           1           2           3           4           5
           2           2           8          10          12          14
           1           2           8          10          12          14
           2           3          14          17          20          23
           2           4          20          24          28          32
           3           1           2           3           4           5
           4           1           2           3           4           5
           1           3          14          17          20          23
           3           2           8          10          12          14
           4           2           8          10          12          14
           1           4          20          24          28          32
           3           3          14          17          20          23
           4           3          14          17          20          23
           3           4          20          24          28          32
           4           4          20          24          28          32

$ cat doubt1.f90
program doubt1
  implicit none
  type tma
    integer, allocatable :: oo (:,:)
    integer :: i1,i2,j1,j2
  end type tma
  type (tma) :: aa [*]
  !
  integer, parameter :: np = 2, nq = 2
  integer :: map (np,nq)
  integer :: ni, ti
  integer :: i1, i2, j1, j2
  integer :: h, k, p, q
  !
  ni = num_images()
  ti = this_image()
  !
  if (ni .ne. 4) error stop "num_images() must be 4"
  !
  k = 1
  do q = 1, nq
  do p = 1, np
    map (p,q) = k
    k = k + 1
  end do
  end do
  !
  i1 = 2
  i2 = 3
  j1 = 4
  j2 = 5
  do  h = 1, ni
    if (ti .eq. h) then
      allocate (aa % oo (i1:i2,j1:j2))
      aa % oo (i1:i2,j1:j2) = k
      aa % i1 = i1
      aa % i2 = i2
      aa % j1 = j1
      aa % j2 = j2
    end if
    i1 = i1 + 6
    i2 = i2 + 7
    j1 = j1 + 8
    j2 = j2 + 9
  end do
  !
  sync all
  !
  if (ti .eq. 1) then
    write (*,*)
    write (*,*)" ti h lbound(aa%oo,1) ubound(aa%oo,1) lbound(aa%oo,2) ubound(aa%oo,2)"
  end if
  do h = 1, ni
    write (*,*) ti,h,lbound (aa[h]%oo,1), ubound (aa[h]%oo,1), &
                     lbound (aa[h]%oo,2), ubound (aa[h]%oo,2)
  end do
  !
  sync all
  !
  if (ti .eq. 1) then
    write (*,*)
    write (*,*)" ti h aa[h]%i1 aa[h]%i2 aa[h]%j1 aa[h]%j1 aa[h]%j2"
  end if
  do h = 1, ni
    write (*,*) ti, h, aa [h] % i1, aa [h] % i2, &
                       aa [h] % j1, aa [h] % j2
  end do
  !
end program doubt1
#end

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2021-03-21 16:16 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-31 15:51 A question about coarrays and -Warray-temporaries Jorge D'Elia
2021-02-01  7:42 ` Thomas Koenig
2021-02-01 10:43   ` Jorge D'Elia
2021-02-01 11:52   ` Tobias Burnus
2021-02-02 11:46     ` [Patch] Fortran: Fix Array dependency with local coarrays [PR98913] (was: Re: A question about coarrays and -Warray-temporaries) Tobias Burnus
2021-02-02 14:32       ` Jorge D'Elia
2021-02-02 14:54       ` Thomas Koenig
2021-02-02 17:15         ` Tobias Burnus
2021-02-09 11:52           ` [Patch] Fortran: Fix coarray handling for gfc_dep_resolver [PR99010] (was: Re: [Patch] Fortran: Fix Array dependency with local coarrays [PR98913] Tobias Burnus
2021-02-13 19:57             ` Tobias Burnus
2021-02-19  9:33             ` *PING**2 " Tobias Burnus
2021-02-19 16:25               ` Jerry DeLisle
2021-03-21 16:18 ` A doubt about lbound and ubound of an array inside a coarray Jorge D'Elia

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).