sourceryinstitute / OpenCoarrays

A parallel application binary interface for Fortran 2018 compilers.
http://www.opencoarrays.org
BSD 3-Clause "New" or "Revised" License
244 stars 58 forks source link

RFE: coarray allocate enhanced checks #351

Open sfilippone opened 7 years ago

sfilippone commented 7 years ago

RFE:coarray allocate enhanced checks.

This has been crossposted to the gfortran mailing list. Apparently, a Fortran compiler is not required to detect at runtime that the attached code violates the standard by having different lower/upper bounds in the allocation statement on different images. However it would be nice to have such a check enabled (at runtime) under one of the -fcheck= options (-fcheck=bounds ?)


program try_coarray
  use iso_fortran_env
  implicit none
  integer, allocatable :: iv(:)[:]
  integer :: me, np, info

  me = this_image()
  np = num_images()

  allocate(iv(me)[*],stat=info)
  write(*,*) me,'allocate(me):',info
  if (info /= 0) write(*,*) size(iv)
  if (allocated(iv)) deallocate(iv)

  allocate(iv(me:me+1)[*],stat=info)
  write(*,*)  me,'allocate(me:me+1):',info
  if (info /= 0) write(*,*) size(iv)
  iv(me:me+1) = [me,me+1]
  if (me>1) write(*,*) me,'Accessing left',iv(me)[me-1]
  if (me<np) write(*,*) me,'Accessing right',iv(me+1)[me+1]
  if (allocated(iv)) deallocate(iv)

end program try_coarray

which currently (gcc 6.3.0/ opencoarrays 1.8.4) results in

e802756@service1:/scratch/e802756> cafrun -np 2 ./a.out
           1 allocate(me):           0
           2 allocate(me):           0
           2 allocate(me:me+1):           0
           2 Accessing left           1
           1 allocate(me:me+1):           0
           1 Accessing right           3

It should be (relatively) easy to broadcast the bounds available on image 1, and then each image checks that they are the same as the local ones (and the broadcast being expensive is the obvious explanation why a compiler is not required to do it, and of why it is not advisable to have this enabled by default).

Thanks Salvatore

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.