program main
  use, intrinsic :: iso_fortran_env, only: stat_stopped_image, stat_failed_image
  implicit none
  integer :: me, sync_stat
  me = this_image()
  if (me == 1) then
    print *, "Hello image", me
  else  
    stop
  end if
  sync all (stat = sync_stat)
  if (sync_stat /= 0) then
    if (sync_stat == stat_stopped_image) then
      print *, "Stopped images", stopped_images()
    else if (sync_stat == stat_failed_image) then
      print *, "Failed images", failed_images()
      error stop me
    else
      print *, "Unexpected failure", sync_stat
      error stop me
    end if
  end if
  print *, "Goodbye image", me
end program
