Hi Harald,

I see, that ifx has an "interesting" result. So what is wrong in the example:

program test_teams_1
    use, intrinsic :: iso_fortran_env
    use oc_assertions_interface, only : assert

    integer :: caf(3,3)[*] != 42
    type(team_type) :: row_team, column_team

    caf = reshape((/(-i, i = 1, 9 )/), [3,3])
    associate(me => this_image(), np => num_images())
        call assert(np == 9, "I need exactly 9 teams.")

        ! Form a row team
        form team((me - 1) / 3 + 1, row_team, new_index=mod(me - 1, 3) + 1)
        row_t: change team(row_team)
            associate(row => caf(:, team_number(row_team)))
            ! Form column teams; each team has only one image
            form team (this_image(), column_team)
            col_t: change team(column_team)
                associate(cell => row(this_image(row_team)))
                print *,this_image(row_team), ": cell", cell, ", 
team_number(row_team)", team_number(row_team)
                cell = team_number(row_team)
                if (this_image(row_team) /= 1) row(this_image(row_team))[1, 
team=row_team] = cell
                end associate
            end team col_t
            sync team(row_team)
            print *,this_image(), ": row", row
            if (this_image() == 1) caf(:, team_number(row_team))[1, team_number 
= -1] = row
            end associate
        end team row_t
        sync all
        if (me == 1) then
            if (all(caf == reshape([1,1,1,2,2,2,3,3,3], [3, 3]))) then
                print *, "Test passed."
            else
                print *, "Test failed."
                print *, "Expected:", reshape([1,1,1,2,2,2,3,3,3], [3, 3])
                print *, "Got     :", caf
            end if
        end if
    end associate

end program test_teams_1

I have added some prints and am using associate instead of the change
team-association now, but it still gives the wrong result. What I am trying to
do is define three teams, where each one has a row of the caf matrix. Then each
row_team defines three column teams, where each one has one entry of the row.
The example insists on exactly 9 images, i.e., every image has its exclusive
entry in the matrix, where it is supposed to put its row_team's number into. The
images with id 1 in each row_team then have to aggregate the data into the
global matrix on image 1 of the initial team (denoted by team_number -1 as per
standard). For row 1 this works. But then everything gets mixed up. I had this
while implementing caf_shmem and not taking the image offset in the shared
memory into account when remapping coarrays for the coarray pointer in the
associate/change team, but Intel can't do the same mistake. So what is wrong
with the code? I don't get it.

Anyhow to answer your initial question: The line:

if (this_image() == 1) caf(:, team_number(row_team))[1, team_number = -1] = row

made me rework replacing the function call of `team_number(row_team)` from the
beginning. Row_team is an opaque pointer and the size of the memory it points
to is not known. When now sending the data from `row` to the caf coarray, a
helper structure is created in the routine in question. For each non-coindex a
member in the structure is created. My initial thought was to allow certain
functions to be executed on the remote image. (Just remember, when on
MPI/OpenCoarrays, a separate thread is executing the modification of the data
in the coarray for remote access. In this case the loop over the entries of
`row` is done on the remote image.) Before I started this fix,
`team_number(row_team)` would be executed on the remote image. This does not
work, because the pointer to `row_team` is valid only on the source image. I
then tried to filter better for functions that are safe to execute on the
remote image. This is what all this mess with elemental and pure is about. I
now propose to keep it simple and when ever a function call is encountered in a
coindexed variable access, the evaluation is done on the source image and the
result propagated to the remote image. The attached patch has the modification
for this.

Does this explain, what I am trying to do?

Regards,
        Andre

On Tue, 15 Jul 2025 18:38:43 +0000
Harald Anlauf <anl...@gmx.de> wrote:

> Hi Andre,
> 
> Jerry kindly sent me the full path:
> 
> https://github.com/sourceryinstitute/OpenCoarrays/blob/vehre/issue-779-form-team/src/tests/unit/teams/test_teams_1.f90
> 
> Frankly, you need to provide more details for me.
> Or maybe someone else can jump in and help me out...
> 
> (Note: the above testcase fails with ifx, and it is not clear to me whether
> it is rather an issue with Intel.)
> 
> Harald
> 
> 
> > Gesendet: Dienstag, 15. Juli 2025 um 07:42
> > Von: "Andre Vehreschild" <ve...@gmx.de>
> > An: "Harald Anlauf" <anl...@gmx.de>
> > CC: fortran@gcc.gnu.org
> > Betreff: Re: Add: [Bug fortran/121043] [16 Regression] Tests of OpenCoarray
> > fail to pass, works on 15.1.1 20250712
> >
> > Hi Harald,
> > 
> > sorry, it's on this branch
> > 
> > https://github.com/sourceryinstitute/OpenCoarrays/tree/vehre/issue-779-form-team
> > 
> > only. There is PR for that, but it's not reviewed yet.
> > 
> > - Andre
> > 
> > On Mon, 14 Jul 2025 20:35:32 +0200
> > Harald Anlauf <anl...@gmx.de> wrote:
> >   
> > > Andre,
> > > 
> > > Am 14.07.25 um 18:12 schrieb Andre Vehreschild:  
> > > > Hi Jerry, hi Harald,
> > > > 
> > > > I am sorry for not responding earlier. I got a small but urgent project
> > > > in and have to do it first. It is only three days (w/ continuation
> > > > possible), but it pays so it has priority.
> > > > 
> > > > As for the issues at hand: Jerry, you probably should have the coarray
> > > > fixes patches from here :
> > > > https://gcc.gnu.org/pipermail/fortran/2025-July/062470.html on your test
> > > > branch (both on 15 and 16) to pass the OpenCoarray tests successfully.
> > > > Because with it: works for me ;-)
> > > > 
> > > > Harald, when you look at OpenCoarray's test_teams_1.f90.006.original
> > > > tree dump (src/tests/unit/teams/ directory), then it may answer your
> > > > question why I want to put all function evaluation to the calling side
> > > > and not to the remote accessor. In this testcase w/o my patch the
> > > > team_number(team) gets moved to the accessor, but `team` can not be
> > > > moved there (opaque pointer on the source side w/o known size and how
> > > > to copy).    
> > > 
> > > I downloaded OpenCoarrays-2.10.3 but cannot find the file you mention:
> > > 
> > > % ls src/tests/unit/teams/
> > > CMakeLists.txt        teams_coarray_get_by_ref.f90 
> > > teams_coarray_sendget.f90
> > > get-communicator.F90  teams_coarray_get.f90          teams_send.f90
> > > sync-team.f90         teams_coarray_send_by_ref.f90  teams_subset.f90
> > > team-number.f90       teams_coarray_send.f90
> > > 
> > > The only file where grep finds the string test_teams1 is teams_send.f90,
> > > but I don't see any relation to what you are talking about.
> > > 
> > > Can you provide a full path / URL and more details?
> > > 
> > > Harald
> > >   
> > > > When you test OpenCoarrays, Jerry, then please make sure to use
> > > > separate and clean build directories. The build stuff from OpenCoarrays
> > > > is sometimes not cleaning up its artifacts correctly, so that .o's stay
> > > > that better shouldn't.
> > > > 
> > > > Hope to get back to gfortran hacking by mid of the week and that this
> > > > few tips helped.
> > > > 
> > > > Regards,
> > > >         Andre    
> > > 
> > >   
> > 
> > 
> > -- 
> > Andre Vehreschild * Email: vehre ad gmx dot de 
> >   


-- 
Andre Vehreschild * Email: vehre ad gmx dot de 
From 161b400f29d22098256bbcb3d5e9046106bb11ef Mon Sep 17 00:00:00 2001
From: Andre Vehreschild <ve...@gcc.gnu.org>
Date: Fri, 4 Jul 2025 11:26:46 +0200
Subject: [PATCH] Fortran: Evaluate all functions on the source image.

Formerly pure elemental functions were evaluated in the caf_accessor.
This had so many dependencies that there was no benefit.  Evaluate
every function on the calling side now, which has the benefit, that
only one temporary has to be created instead of argument many.

gcc/fortran/ChangeLog:

	* coarray.cc (check_add_new_component): Evaluate all functions
	on the source image.
	* trans-decl.cc (gfc_build_builtin_function_decls): The only
	argument of team_number() is of type void* in the library ABI.
---
 gcc/fortran/coarray.cc    | 16 +++-------------
 gcc/fortran/trans-decl.cc |  7 +++----
 2 files changed, 6 insertions(+), 17 deletions(-)

diff --git a/gcc/fortran/coarray.cc b/gcc/fortran/coarray.cc
index ef8fd4e42d0..07e4f91d2d5 100644
--- a/gcc/fortran/coarray.cc
+++ b/gcc/fortran/coarray.cc
@@ -696,21 +696,11 @@ check_add_new_component (gfc_symbol *type, gfc_expr *e, gfc_symbol *add_data)
 	    check_add_new_component (type, actual->expr, add_data);
 	  break;
 	case EXPR_FUNCTION:
-	  if (!e->symtree->n.sym->attr.pure
-	      && !e->symtree->n.sym->attr.elemental
-	      && !(e->value.function.isym
-		   && (e->value.function.isym->pure
-		       || e->value.function.isym->elemental)))
-	    /* Treat non-pure/non-elemental functions.  */
-	    check_add_new_comp_handle_array (e, type, add_data);
-	  else
-	    for (gfc_actual_arglist *actual = e->value.function.actual; actual;
-		 actual = actual->next)
-	      check_add_new_component (type, actual->expr, add_data);
+	  check_add_new_comp_handle_array (e, type, add_data);
 	  break;
 	case EXPR_VARIABLE:
-	    check_add_new_comp_handle_array (e, type, add_data);
-	    break;
+	  check_add_new_comp_handle_array (e, type, add_data);
+	  break;
 	case EXPR_ARRAY:
 	case EXPR_PPC:
 	case EXPR_STRUCTURE:
diff --git a/gcc/fortran/trans-decl.cc b/gcc/fortran/trans-decl.cc
index 43bd7be54cb..ba4a842a025 100644
--- a/gcc/fortran/trans-decl.cc
+++ b/gcc/fortran/trans-decl.cc
@@ -4223,10 +4223,9 @@ gfc_build_builtin_function_decls (void)
 	get_identifier (PREFIX ("caf_sync_team")), ". r w w w ", void_type_node,
 	4, pvoid_type_node, pint_type, pchar_type_node, size_type_node);
 
-      gfor_fndecl_caf_team_number
-      	= gfc_build_library_function_decl_with_spec (
-	    get_identifier (PREFIX("caf_team_number")), ". r ",
-      	    integer_type_node, 1, integer_type_node);
+      gfor_fndecl_caf_team_number = gfc_build_library_function_decl_with_spec (
+	get_identifier (PREFIX ("caf_team_number")), ". r ", integer_type_node,
+	1, pvoid_type_node);
 
       gfor_fndecl_caf_image_status = gfc_build_library_function_decl_with_spec (
 	get_identifier (PREFIX ("caf_image_status")), ". r r ",
-- 
2.50.1

Reply via email to