Le 25/09/2026 à 19:24, Jerry D a écrit :
See attached patch. This implements the teams registry solution for tracking failed images.

Regression tested on x86_64.

OK for mainline?

Regards,

Jerry

---

libgfortran: [PR127347] caf_shmem: drop images killed by a
  signal from teams

An image that terminates without STOP or FAIL IMAGE, e.g. when it is
killed by a signal, cannot drop itself from the barriers of its teams,
so the other images blocked forever in their next image control
statement.  Only the supervisor notices such an image, and it has no
access to the teams the image was a member of.

Every team now registers itself with the supervisor when it is formed,
which happens once per team, so that the supervisor can walk the teams
and do for a killed image what the image itself does for a STOP.
Entries are pushed onto the list without a lock, so that an image
killed while registering a team cannot block the supervisor.

An image killed this way stays a failed image (F2023 5.3.6): the other
images of its teams carry on and report it through STAT=.

Assisted-by: Claude Opus 5.5

     PR libfortran/127347

libgfortran/ChangeLog:

     * caf/shmem.c (_gfortran_caf_form_team): Register the team.
     * caf/shmem/supervisor.c (ensure_shmem_initialization): Initialize
     the list of teams.  Register the initial team.
     (supervisor_main_loop): Drop an image that terminated without
     leaving its teams from them.
     * caf/shmem/supervisor.h (supervisor): Add teams.
     * caf/shmem/teams_mgmt.c (team_terminated_images)
     (update_teams_images_locked, leave_team): Take the team's image
     info.
     (register_team, update_registered_teams): New functions.
     * caf/shmem/teams_mgmt.h (shmem_image_info): Add next_team.
     (register_team, update_registered_teams): Declare.

gcc/testsuite/ChangeLog:

     * gfortran.dg/coarray/signal_sync_1.f90: New test.
     * gfortran.dg/coarray/signal_team_1.f90: New test.
---

Hello,

The initialization of the stat= variable doesn't seem to be reliable.
With this example:

program prog
   use iso_fortran_env, only : stat_failed_image
   implicit none
   integer :: img, team_id, s[*], i, v, st
   if (num_images() < 2) stop
   if (this_image() == 1) then
      s = heavy_work(2)
      call abort
   end if
   print *, this_image()
   sync all (stat=st)
   print *, this_image(), st, s[1]
contains
   function heavy_work(i) result(r)
      integer :: r, c
      integer(kind=8) :: v
      integer, intent(in) :: i
      integer, parameter :: p = 199679
      c = 0
      v = i
      do while (c == 0 .or. v /= i)
         v = v * i
         v = mod(v, p)
         c = c + 1
      end do
      r = c
   end function
end program

The stat= variable ends up as zero, as shown by the program output:
           8
           5
           3
           2
           6
           4
           7

Program aborted. Backtrace:
#0  0x409463 in ???
#1  0x409615 in ???
#2  0x41db9c in ???
#3  0x401f54 in ???
#4  0x40225a in ???
#5  0x44fab5 in ???
#6  0x4518cc in ???
#7  0x401d80 in ???
ERROR: Image 1(pid: 80792) failed with signal 6, exitstatus 0.
           3           0       99839
           8           0       99839
           5           0       99839
           2           0       99839
           6           0       99839
           4           0       99839
           7           0       99839




Reply via email to