Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

class keyword produces wrong results for elemental subroutines

kostas85
초급자
941 조회수

Hello all,

In the following code two derived types, t1,t2 are defined and two functions whose arguments are of type t1, and output of type t2, an elemental and a "classic one". When the elemental is used wrong results are produced if t1 is defined as a class array. The code follows, along with correct and wrong results. Did something change about the class keyword from the previous version? Thank you!

module type_funs

type t1
  integer :: i
end type t1

type t2
  integer :: i
end type t2

type(t1) :: t1_start = t1(0)

contains

type(t2) elemental function bin_op(this,that) result(res)
type(t1), intent(in) :: this, that
res%i=this%i-that%i
end function bin_op

function bin_op_arr(this,that) result(res)
type(t1), dimension(:), intent(in) :: this
type(t1), intent(in) :: that
type(t2), dimension(size(this)) :: res
res%i=this%i-that%i
end function bin_op_arr

end module type_funs


program test_funs

use type_funs

implicit none

! this produces wrong results
class(t1), dimension(:), allocatable :: t1arr
! this produces correct results
!type(t1), dimension(:), allocatable :: t1arr

allocate(t1arr(10))
t1arr%i=[1:10]

print *, bin_op(t1arr,t1_start)
print *, bin_op_arr(t1arr,t1_start)

end program test_funs

correct result

           1           2           3           4           5           6
           7           8           9          10
           1           2           3           4           5           6
           7           8           9          10

wrong result

           1           1           1           1           1           1
           1           1           1           1
           1           2           3           4           5           6
           7           8           9          10

 

 

0 포인트
6 응답
Kevin_D_Intel
직원
941 조회수

The test case produces the incorrect results for me going back as far as the 13.1 compilers. Which compiler did you find produced the correct results?
 

0 포인트
kostas85
초급자
941 조회수

Thanks for the comment!!! I checked again and the previous version I used, 14.0.3, produces the incorrect result. I must had mistakenly compiled and run the code version with the type declaration while thinking it was the class declaration. I am sorry.

0 포인트
FortranFan
명예로운 기여자 III
941 조회수

FWIW, gfortran 4.9 produces the correct results.

0 포인트
Kevin_D_Intel
직원
941 조회수

Thank you FortranFan for that note.

Thank you for double-checking the reproducer with your previous version. I reported this issue to Development (see internal tracking id below) and will keep you updated on what I hear from them following their further investigation.

(Internal tracking id: DPD200362027)

(Resolution Update on 09/12/2015): This defect is fixed in the Intel® Parallel Studio XE 2016 Release (2016.0.109 - Linux)

0 포인트
Kevin_D_Intel
직원
941 조회수

Development has targeted the fix for this issue to the next major release later next year. I will update again when the release containing this fix is available

0 포인트
Kevin_D_Intel
직원
941 조회수

I confirmed the associated fix for this issue in the Intel® Parallel Studio XE 2016 Release (Version 16.0.0.109 Build 20150815) available from the Intel® Software Development Products Registration Center (IRC).
 

0 포인트
응답