Re: [PATCH 6/13] Coarray shared memory library
On Thu, Feb 12, 2026 at 08:17:21PM -0800, Steve Kargl wrote:
> On Wed, Feb 11, 2026 at 10:58:32AM +0100, Tobias Burnus wrote:
> > Jerry D wrote:
> > > +foreach flags $option_list {
> > > +verbose "Testing $nshort (libcaf_shmem), $flags" 1
> > > +set gfortran_aux_module_flags "-fcoarray=lib $flags -lcaf_shmem"
> > > +dg-test $test "-fcoarray=lib $flags -lcaf_shmem" {}
> > > +cleanup-modules ""
> > > +}
> >
> > As mentioned in 13/13, the current implementation seems to assume that POSIX
> > threads are available; additionally, -lpthread or -pthread might be needed
> > for linking. In any case, it seems as if some check is required whether
> > caf_shmem is actually available; otherwise, the shmem tests have to be
> > skipped.
> >
>
> Unfortunately, I don't know how to fix. In libgomp/configure.txt one sees
>
> % more libgomp/configure.txt
> # This is the target specific configuration file. This is invoked by the
> # autoconf generated configure script. Putting it in a separate shell file
> # lets us skip running autoconf when modifying target specific information.
>
> # This file switches on the shell variable ${target}, and sets the
> # following shell variables:
> # config_path An ordered list of directories to search for
> # sources and headers. This is relative to the
> # config subdirectory of the source tree.
> # XCFLAGS Add extra compile flags to use.
> # XLDFLAGS Add extra link flags to use.
> # tmake_file A list of machine-description-specific
> # makefile fragments.
> ...
> *-*-freebsd*)
> # Need to link with -lpthread so libgomp.so is self-contained.
> XLDFLAGS="${XLDFLAGS} -lpthread"
> ;;
>
> It looks like AIX also needs -lpthread added to its linker flags.
> In libgfortran/configure.host, there are target specific checks,
> but adding the above with would unconditional add -lpthread to
> the linker flags even if caf_shmem is not used.
If I manually add -lpthread to caf.exp, then I see
=== gfortran Summary ===
# of expected passes74989
# of unexpected failures37
# of expected failures 343
# of unsupported tests 95
/home/kargl/gcc/obj/gcc/gfortran version 16.0.1 20260204 (experimental) (GCC)
which means caf_shmem seems to work on FreeBSD.
--
Steve
Re: [PATCH 6/13] Coarray shared memory library
On Wed, Feb 11, 2026 at 10:58:32AM +0100, Tobias Burnus wrote:
> Jerry D wrote:
> > +foreach flags $option_list {
> > +verbose "Testing $nshort (libcaf_shmem), $flags" 1
> > +set gfortran_aux_module_flags "-fcoarray=lib $flags -lcaf_shmem"
> > +dg-test $test "-fcoarray=lib $flags -lcaf_shmem" {}
> > +cleanup-modules ""
> > +}
>
> As mentioned in 13/13, the current implementation seems to assume that POSIX
> threads are available; additionally, -lpthread or -pthread might be needed
> for linking. In any case, it seems as if some check is required whether
> caf_shmem is actually available; otherwise, the shmem tests have to be
> skipped.
>
Unfortunately, I don't know how to fix. In libgomp/configure.txt one sees
% more libgomp/configure.txt
# This is the target specific configuration file. This is invoked by the
# autoconf generated configure script. Putting it in a separate shell file
# lets us skip running autoconf when modifying target specific information.
# This file switches on the shell variable ${target}, and sets the
# following shell variables:
# config_path An ordered list of directories to search for
# sources and headers. This is relative to the
# config subdirectory of the source tree.
# XCFLAGS Add extra compile flags to use.
# XLDFLAGS Add extra link flags to use.
# tmake_file A list of machine-description-specific
# makefile fragments.
...
*-*-freebsd*)
# Need to link with -lpthread so libgomp.so is self-contained.
XLDFLAGS="${XLDFLAGS} -lpthread"
;;
It looks like AIX also needs -lpthread added to its linker flags.
In libgfortran/configure.host, there are target specific checks,
but adding the above with would unconditional add -lpthread to
the linker flags even if caf_shmem is not used.
--
Steve
Re: [PATCH 6/13] Coarray shared memory library
Jerry D wrote:
Fortran: Enable coarray tests for multi image use [PR88076]
Change some of regression tests to run on single and multiple images.
Add some new tests.
PR fortran/88076
gcc/testsuite/ChangeLog:
* gfortran.dg/coarray/alloc_comp_4.f90: Make multi image
compatible.
* gfortran.dg/coarray/atomic_2.f90: Same.
* gfortran.dg/coarray/caf.exp: Also test caf_shmem and choose
I think this should be split into two parts – one part will be changing
the testcases to handle more than 1 image – and the second part that needs
to land with or after 13/13 is to actually enable it.
Regarding the first part: I or someone else still has to review those
changes.
Regarding the second part:
--- a/gcc/testsuite/gfortran.dg/coarray/caf.exp
+++ b/gcc/testsuite/gfortran.dg/coarray/caf.exp
@@ -70,6 +70,12 @@ proc dg-compile-aux-modules { args } {
}
}
+if { [getenv GFORTRAN_NUM_IMAGES] == "" } {
+ # Some caf_shmem tests need at least 8 images. This is also to limit the
+ # number of images on big machines preventing overload w/o any benefit.
+ setenv GFORTRAN_NUM_IMAGES 8
+}
+
FYI only: When doing remote testing, DejaGNU does not properly forward
environment variables. I assume it also works somewhat gracefully when
it is unset.
+foreach flags $option_list {
+verbose "Testing $nshort (libcaf_shmem), $flags" 1
+set gfortran_aux_module_flags "-fcoarray=lib $flags -lcaf_shmem"
+dg-test $test "-fcoarray=lib $flags -lcaf_shmem" {}
+cleanup-modules ""
+}
As mentioned in 13/13, the current implementation seems to assume that
POSIX threads are available; additionally, -lpthread or -pthread might
be needed for linking. In any case, it seems as if some check is
required whether caf_shmem is actually available; otherwise, the shmem
tests have to be skipped.
Tobias
[PATCH 6/13] Coarray shared memory library
Dear all, as requested, See attached patch 6 of 13 Best Regards, Jerrycommit 9f74ce7aa6b7caadbd760a5920b87ac4016a5b92 Author: Andre Vehreschild Date: Wed Jun 18 09:26:22 2025 +0200 Fortran: Enable coarray tests for multi image use [PR88076] Change some of regression tests to run on single and multiple images. Add some new tests. PR fortran/88076 gcc/testsuite/ChangeLog: * gfortran.dg/coarray/alloc_comp_4.f90: Make multi image compatible. * gfortran.dg/coarray/atomic_2.f90: Same. * gfortran.dg/coarray/caf.exp: Also test caf_shmem and choose eight images as a default. * gfortran.dg/coarray/coarray_allocated.f90: Add multi image support. * gfortran.dg/coarray/coindexed_1.f90: Same. * gfortran.dg/coarray/coindexed_3.f08: Same. * gfortran.dg/coarray/coindexed_5.f90: Same. * gfortran.dg/coarray/dummy_3.f90: Same. * gfortran.dg/coarray/event_1.f90: Same. * gfortran.dg/coarray/event_3.f08: Same. * gfortran.dg/coarray/event_4.f08: Same. * gfortran.dg/coarray/failed_images_2.f08: Same. * gfortran.dg/coarray/image_status_1.f08: Same. * gfortran.dg/coarray/image_status_2.f08: Same. * gfortran.dg/coarray/lock_2.f90: Same. * gfortran.dg/coarray/poly_run_3.f90: Same. * gfortran.dg/coarray/scalar_alloc_1.f90: Same. * gfortran.dg/coarray/stopped_images_2.f08: Same. * gfortran.dg/coarray/sync_1.f90: Same. * gfortran.dg/coarray/sync_3.f90: Same. * gfortran.dg/coarray/co_reduce_string.f90: New test. * gfortran.dg/coarray/sync_team.f90: New test. diff --git a/gcc/testsuite/gfortran.dg/coarray/alloc_comp_4.f90 b/gcc/testsuite/gfortran.dg/coarray/alloc_comp_4.f90 index 2ee8ff0253d..50b4bab1603 100644 --- a/gcc/testsuite/gfortran.dg/coarray/alloc_comp_4.f90 +++ b/gcc/testsuite/gfortran.dg/coarray/alloc_comp_4.f90 @@ -11,11 +11,19 @@ program main end type type(mytype), save :: object[*] - integer :: me + integer :: me, other me=this_image() - allocate(object%indices(me)) - object%indices = 42 + other = me + 1 + if (other .GT. num_images()) other = 1 + if (me == num_images()) then + allocate(object%indices(me/2)) + else +allocate(object%indices(me)) + end if + object%indices = 42 * me - if ( any( object[me]%indices(:) /= 42 ) ) STOP 1 + sync all + if ( any( object[other]%indices(:) /= 42 * other ) ) STOP 1 + sync all end program diff --git a/gcc/testsuite/gfortran.dg/coarray/atomic_2.f90 b/gcc/testsuite/gfortran.dg/coarray/atomic_2.f90 index 5e1c4967248..7eccd7b578c 100644 --- a/gcc/testsuite/gfortran.dg/coarray/atomic_2.f90 +++ b/gcc/testsuite/gfortran.dg/coarray/atomic_2.f90 @@ -61,7 +61,7 @@ end do sync all call atomic_ref(var, caf[num_images()], stat=stat) -if (stat /= 0 .or. var /= num_images() + this_image()) STOP 12 +if (stat /= 0 .or. var /= num_images() * 2) STOP 12 do i = 1, num_images() call atomic_ref(var, caf[i], stat=stat) if (stat /= 0 .or. var /= num_images() + i) STOP 13 @@ -328,7 +328,7 @@ end do sync all call atomic_ref(var, caf[num_images()], stat=stat) -if (stat /= 0 .or. var /= num_images() + this_image()) STOP 45 +if (stat /= 0 .or. var /= num_images() * 2) STOP 45 do i = 1, num_images() call atomic_ref(var, caf[i], stat=stat) if (stat /= 0 .or. var /= num_images() + i) STOP 46 @@ -403,7 +403,7 @@ if (this_image() < storage_size(caf)-2) then do i = this_image(), min(num_images(), storage_size(caf)-2) var = -99 call atomic_fetch_and(caf[i], shiftl(1, this_image()), var, stat=stat) -if (stat /= 0 .or. var <= 0) STOP 53 +if (stat /= 0) STOP 53 end do end if sync all @@ -544,7 +544,7 @@ if (this_image() < storage_size(caf)-2) then do i = this_image(), min(num_images(), storage_size(caf)-2) var = -99 call atomic_fetch_xor(caf[i], shiftl(1, this_image()), var, stat=stat) -if (stat /= 0 .or. (var < 0 .and. var /= -1)) STOP 68 +if (stat /= 0) STOP 68 end do end if sync all @@ -628,26 +628,27 @@ sync all if (this_image() == 1) then call atomic_cas(caf_log[num_images()], compare=.false., new=.false., old=var2, stat=stat) - if (stat /= 0 .or. var2 .neqv. .true.) STOP 82 + if (stat /= 0 .or. (var2 .neqv. .true.)) STOP 82 call atomic_ref(var2, caf_log[num_images()], stat=stat) - if (stat /= 0 .or. var2 .neqv. .true.) STOP 83 + if (stat /= 0 .or. (var2 .neqv. .true.)) STOP 83 end if sync all -if (this_image() == num_images() .and. caf_log .neqv. .true.) STOP 84 +if (this_image() == num_images() .and. (caf_log .neqv. .true.)) STOP 84 call atomic_ref(var2, caf_log[num_images()], stat=stat) -if (stat /= 0 .or. var2 .neqv. .true.) STOP 85 +if (stat /= 0 .or. (var2 .neqv. .true.)) STOP 85 sync all if (this_image() == 1) then call atomic_cas(ca
