Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
Welcome to the Intel Community. If you get an answer you like, please mark it as an Accepted Solution to help others. Thank you!
26734 Discussions

assumed rank arrays -> ICE and runtime error

Johannes_Rieke
New Contributor III
98 Views

Dear all,

I wrote an example for getting in touch with assumed rank arrays and got two issues. Once an ICE assumed in subroutine bar in line 44 (if un-commented) and in foo in line 22 a run-time error is thrown for i>=2. To get the ICE one have to uncomment lines 21 to 23. The ICE occures in PSXE 2016.3 up to version 2017.2.

Maybe the things I do are not standard conform...

module mod_subs
  implicit none  
 
  contains
  
  subroutine foo(t)
    implicit none
    real, intent(inout)  :: t(..)  
    
    integer              :: i
    integer              :: i_rank
    integer, allocatable :: i_size_1(:), i_size_2(:)
    
    i_rank = rank(t)    
    allocate(i_size_1(i_rank))
    allocate(i_size_2(i_rank))
    i_size_1=shape(t)
    write(*,'("The rank    of the array is: ",*(i3))') i_rank   ! gives  3
    write(*,'("The shape   of the array is: ",*(i3))') i_size_1 ! gives  2  2  2  
    write(*,'("The content of the array is: ",*(f6.2))') t      ! stops at 2.0
    do i = 1, i_rank
      i_size_2(i) = size(t,dim=i)  ! runtime error at i=2: The DIM value 2 must not be greater than 1, the rank of array 'T'.
    end do
  
    return  
  end subroutine foo
  
  ! --------------------------------------------
  
  subroutine bar(t)
    implicit none
    real, intent(inout)  :: t(..)  
    
    integer              :: i
    integer              :: i_rank
    integer, allocatable :: i_size(:)
    
    i_rank = rank(t)    
    allocate(i_size(i_rank))
    i_size=shape(t)  
    write(*,'("The rank    of the array is: ",*(i3))') i_rank   ! gives  3
    write(*,'("The shape   of the array is: ",*(i3))') i_size   ! gives  2  2  2  
    write(*,'("The content of the array is: ",*(f6.2))') t      ! stops at 2.0
    !write(*,*) t(1:i_size(1),1:i_size(2),1:i_size(3)) ! un-commenting throws an ICE (PSXE 2016.3 up to 2017.2)
  
    return  
  end subroutine bar
  
end module mod_subs


program Assumed_Rank
    use mod_subs
    implicit none

    ! Variables
    integer                :: i, j, k
    real, dimension(2,2,2) :: r_dummy

    ! Body of Assumed_Rank
    r_dummy = reshape([1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0],[2,2,2])
    
    do i = 1, size(r_dummy,dim=3)
      do j = 1, size(r_dummy,dim=2)
        do k = 1, size(r_dummy,dim=1)
          write(*,'(*(f6.2))',advance='no') r_dummy(k,j,i)
        end do
        write(*,'(/)')
      end do
    end do
    
    call foo(r_dummy)
    call bar(r_dummy)
    

end program Assumed_Rank
Compiling with Intel(R) Visual Fortran Compiler 17.0.2.187 [Intel(R) 64]...
ifort /nologo /debug:full /Od /warn:interfaces /module:"x64\Debug\\" /object:"x64\Debug\\" /Fd"x64\Debug\vc140.pdb" /traceback /check:bounds /check:stack /libs:dll /threads /dbglibs /c /Qlocation,link,"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\\bin\amd64" /Qm64 "D:\02_Fortran\99_test\Assumed_Rank\mod_subs.f90"
ifort /nologo /debug:full /Od /warn:interfaces /module:"x64\Debug\\" /object:"x64\Debug\\" /Fd"x64\Debug\vc140.pdb" /traceback /check:bounds /check:stack /libs:dll /threads /dbglibs /c /Qlocation,link,"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\\bin\amd64" /Qm64 "D:\02_Fortran\99_test\Assumed_Rank\Assumed_Rank.f90"
Linking...
Link /OUT:"x64\Debug\Assumed_Rank.exe" /INCREMENTAL:NO /NOLOGO /MANIFEST /MANIFESTFILE:"x64\Debug\Assumed_Rank.exe.intermediate.manifest" /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG /PDB:"D:\02_Fortran\99_test\Assumed_Rank\x64\Debug\Assumed_Rank.pdb" /SUBSYSTEM:CONSOLE /IMPLIB:"D:\02_Fortran\99_test\Assumed_Rank\x64\Debug\Assumed_Rank.lib" -qm64 "x64\Debug\mod_subs.obj" "x64\Debug\Assumed_Rank.obj"
Embedding manifest...
mt.exe /nologo /outputresource:"D:\02_Fortran\99_test\Assumed_Rank\x64\Debug\Assumed_Rank.exe;#1" /manifest "x64\Debug\Assumed_Rank.exe.intermediate.manifest"

Assumed_Rank - 0 error(s), 0 warning(s)

 

1>------ Rebuild All started: Project: Assumed_Rank, Configuration: Debug x64 ------
1>Deleting intermediate files and output files for project 'Assumed_Rank', configuration 'Debug|x64'.
1>Compiling with Intel(R) Visual Fortran Compiler 17.0.2.187 [Intel(R) 64]...
1>mod_subs.f90
1>fortcom: Fatal: There has been an internal compiler error (C0000005).
1>compilation aborted for D:\02_Fortran\99_test\Assumed_Rank\mod_subs.f90 (code 1)
1>Assumed_Rank.f90
1>
1>Build log written to  "file://D:\02_Fortran\99_test\Assumed_Rank\x64\Debug\BuildLog.htm"
1>Assumed_Rank - 1 error(s), 0 warning(s)
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

 

 

0 Kudos
4 Replies
Kevin_D_Intel
Employee
98 Views

I can reproduce both of these. Thank you. I'll roll these up to Development shortly.

Johannes_Rieke
New Contributor III
98 Views

Hi Kevin,

thanks fro the quick reply. The simpler version with just using a fix index below produces also the ICE.

Anyway, does the standard allow the use of assumed rank in such a way? What is meant by the help exactly:

An assumed-rank variable name must not appear in a designator or expression except as one of the following: 
- An actual argument corresponding to a dummy argument that is assumed-rank 
- The argument of the C_LOC function in the ISO_C_BINDING intrinsic module 
- The first argument in a reference to an intrinsic inquiry function 

  subroutine bar(t)
    implicit none
    real, intent(inout)  :: t(..)  
    
    integer              :: i, j, k
    integer              :: i_rank
    integer, allocatable :: i_size(:)
    
    i_rank = rank(t)    
    allocate(i_size(i_rank))
    i_size=shape(t)  
    write(*,'("The rank    of the array is: ",*(i3))') i_rank   ! gives  3
    write(*,'("The shape   of the array is: ",*(i3))') i_size   ! gives  2  2  2  
    write(*,'("The content of the array is: ",*(f6.2))') t      ! stops at 2.0
    write(*,'(*(f6.2))',advance='no') t(1,1,1) ! also an ICE
  
    return  
  end subroutine bar

 

Johannes_Rieke
New Contributor III
98 Views

This version works. Line 20 of original foo should throw a compile time error IMHO...

subroutine foo(t)
    use, intrinsic :: iso_c_binding, only : c_loc, c_ptr, c_f_pointer
    implicit none
    real, intent(inout)  :: t(..)  
    
    integer              :: i
    integer              :: i_rank
    integer, allocatable :: i_size_1(:), i_size_2(:)
    real, pointer        :: pt_t(:,:,:)
    
    i_rank = rank(t)    
    allocate(i_size_1(i_rank))
    allocate(i_size_2(i_rank))
    i_size_1=shape(t)
    write(*,'("The rank    of the array is: ",*(i3))') i_rank   ! gives  3
    write(*,'("The shape   of the array is: ",*(i3))') i_size_1 ! gives  2  2  2  
    !write(*,'("The content of the array is: ",*(f6.2))') t      ! stops at 2.0, error expected
    !do i = 1, i_rank
    !  i_size_2(i) = size(t,dim=i)  ! runtime error at i=2: The DIM value 2 must not be greater than 1, the rank of array 'T'.
    !end do
    call c_f_pointer( cptr=c_loc(t), fptr=pt_t, shape=i_size_1 )
    write(*,'("The content of the array is: ",*(f6.2))') pt_t      ! prints 1.0 to 8.0
  
    return  
  end subroutine foo

 

Kevin_D_Intel
Employee
98 Views

I reported the issues to Development. Yes, for the case that compiles/runs, the usage appears non-conformant; therefore, should provoke a compile-time error I believe. Thank for the additional concise test cases.

(Internal tracking id: DPD200418864 – internal error with assumed-rank array)
(Internal tracking id: DPD200418868 – missing error for non-conformant assumed-rank array usage)

Reply