Should an assumed shape argument cause a stack overflow in read?

Should an assumed shape argument cause a stack overflow in read?

Consider the following program:

module io_mod
    implicit none
contains
    subroutine read_vals_assumed_shape(vals, ios)
        character(*), intent(inout), contiguous :: vals(:)
        integer, intent(out) :: ios
        read(1, pos = 1, iostat = ios) vals
    end subroutine
    subroutine read_vals_assumed_size(vals, size_vals, ios)
        character(*), intent(inout) :: vals(*)
        integer, intent(in) :: size_vals
        integer, intent(out) :: ios
        read(1, pos = 1, iostat = ios) vals(:size_vals)
    end subroutine
end module
    
program Console24
    use io_mod
    implicit none
    character(64), allocatable :: vals(:)
    integer :: ios
    allocate (vals(300000))
    vals = ' '
    open(1, file = 'test.out', access='stream', form = 'unformatted')
    write(1, pos = 1, iostat = ios) vals
    close(1)
    open(1, file = 'test.out', access='stream', form = 'unformatted')
    ! The following three statements should do the same thing
    read(1, pos = 1, iostat = ios) vals
    call read_vals_assumed_size(vals, size(vals), ios)
    call read_vals_assumed_shape(vals, ios)
    close(1)
end program Console24

This crashes on line 8 with a stack overflow in recent releases of the compiler (I've tried this with XE 2013 update 1 and XE 2013 SP1 update 1).

Workarounds:

1) Use the "/heap_arrays:0" option.

2) Use an assumed size argument.

3) Read the array in stack friendly chunks.

Or should the compiler be able to cope with this as is, given the contiguous attribute on vals (which seems to make no difference in this case)?

5 Beiträge / 0 neu
Letzter Beitrag
Nähere Informationen zur Compiler-Optimierung finden Sie in unserem Optimierungshinweis.

I agree with you that the stack temporary should not have been created. especially as you added the CONTIGUOUS attribute. I will ask the developers to improve this. Issue ID is DPD200249510.

Steve - Intel Developer Support

Thanks Steve,

Aside: the forum syntax highlighting strips out blank lines, so the stack overflow is on line 7 of the posted listing (read(1, pos = 1, iostat = ios) vals) in io_mod::read_vals_assumed_shape.

Mark

Yeah, I figured that out...

Steve - Intel Developer Support

For a release later this year, we've fixed the compiler to use the CONTIGUOUS attribute to avoid creating stack temps.

Steve - Intel Developer Support

Kommentar hinterlassen

Bitte anmelden, um einen Kommentar hinzuzufügen. Sie sind noch nicht Mitglied? Jetzt teilnehmen