Hi,
In the following simple code, where the operator .lt. is used a lot of times, i found that ifort is slower than gfortran by a factor of 2. First i thought it was the handling of the class(*) but in this version there is no class(*) , then i suspected a slow select type, but it just appears that accessing the component from the original class is the problem. what are your thoughts on this ?
gfortran -O3 -fno-inline-functions tata.f90 T b1 extends btype to intb F T T T F time operator .lt. 0.40333300000000000 time selecttype .lt. 0.31666599999999995 time .lt. intb 0.31000000000000016 time .lt. btype 7.3333999999999788E-002
ifort -O3 -fno-inline-functions tata.f90 T b1 extends btype to intb T T T T F time operator .lt. 0.723333000000000 time selecttype .lt. 0.670000000000000 time .lt. intb 0.670000000000000 time .lt. btype 0.110000000000000
module tata implicit none type :: b_type integer,allocatable :: b contains procedure,private :: lower_than generic,public :: operator(.lt.) => lower_than end type type,extends(b_type) :: intb contains procedure,private :: lower_than=>lowerthan_intb !generic,public :: operator(.lt.) => lowerthan_intb end type interface intb module procedure :: intb_constructor end interface contains function intb_constructor(i) result(a) type(intb) :: a integer :: i allocate(a%b,source=i) end function function lowerthan_intb_intb(a,b) result(r) class(intb),intent(in) :: a!,b class(intb),intent(in) :: b logical :: r r=a%b<b%b end function function lowerthan_intb(a,b) result(r) class(intb),intent(in) :: a!,b class(b_type),intent(in) :: b logical :: r !print *,'lowerthan intb' !select type(i1 => a%b) !type is(integer) select type(b1 => b) class is (intb) !select type(i2 => b1%b) !type is(integer) r=a%b<b1%b !end select end select !end select end function function lower_than(a,b) class(b_type),intent(in) :: a class(b_type),intent(in) :: b logical :: lower_than lower_than=.false. print *, 'operator lower than class* no implementation' end function function lowerthan_bt_bt(a,b) result(r) class(b_type),intent(in) :: a!,b class(b_type),intent(in) :: b logical :: r r=a%b<b%b end function end module program foo use tata implicit none type(intb) :: d,d2 class(intb),allocatable :: cd,cd2 class(b_type),allocatable :: b1,b2 type(b_type) :: e1,e2 integer :: j logical :: res double precision :: t0,t1 j=1 allocate(e1%b,source=j) allocate(e2%b,source=j) d=intb(1) d2=intb(3) allocate(cd,source=d) allocate(cd2,source=d2) print *,d<d2 allocate(b1,source=cd) allocate(b2,source=cd2) print *,'b1 extends btype to intb',extends_type_of(b1,d),same_type_as(b1,d) print *,b1.lt.b2 print *,b1<b2 print *, cd<b1 deallocate(cd,cd2,b1,b2) call cpu_time(t0) do j=1,2000000 allocate(cd,source=d) allocate(cd2,source=d2) res=cd<cd2 deallocate(cd,cd2) end do call cpu_time(t1) print *,'time operator .lt.',t1-t0 call cpu_time(t0) do j=1,2000000 allocate(cd,source=d) allocate(cd2,source=d2) res=lowerthan_intb(cd,cd2) deallocate(cd,cd2) end do call cpu_time(t1) print *,'time selecttype .lt.',t1-t0 call cpu_time(t0) do j=1,2000000 allocate(cd,source=d) allocate(cd2,source=d2) res=lowerthan_intb_intb(cd,cd2) deallocate(cd,cd2) end do call cpu_time(t1) print *,'time .lt. intb',t1-t0 deallocate(e1%b,e2%b) call cpu_time(t0) do j=1,2000000 allocate(e1%b,source=j) allocate(e2%b,source=j) res=lowerthan_bt_bt(e1,e2) deallocate(e1%b,e2%b) end do call cpu_time(t1) print *,'time .lt. btype',t1-t0 end program