hi everyone. I've been profiling the attached code to measure the performance impact when using virtual procedures in Fortran 2003. As it's shown in the profile log, I've found that the polymorphic variable "af" actually consumes less time than the static one "sf". Is there something am I doing wrong in this example? Or it's possible to get best performance with polymorphic variables in some cases?
-juan
Test data: compiler: ifort13.1.1; compiler flags = -ipo -O3 -inline-forceinline; OS: linux debian; execution script: mpirun -np 1 main.out
Module TestOOP implicit none public type :: pointerfunction procedure(a), pointer :: f end type type, abstract :: abstractfunction contains procedure(b), deferred, public :: f end type type, extends(abstractfunction) :: concretefunction contains procedure, public :: f => fconcrete end type abstract interface pure subroutine a(this,i) import :: pointerfunction class(pointerfunction), intent(inout) :: this integer, intent(in) :: i end subroutine pure subroutine b(this,i) import :: abstractfunction class(abstractfunction), intent(inout) :: this integer, intent(in) :: i end subroutine end interface type staticfunction contains procedure, public :: f => fstatic end type contains pure subroutine fpointer(this,i) implicit none class(pointerfunction), intent(inout) :: this integer, intent(in) :: i end subroutine pure subroutine fstatic(this,i) implicit none class(staticfunction), intent(inout) :: this integer,intent(in) :: i end subroutine pure subroutine fconcrete(this,i) implicit none class(concretefunction), intent(inout) :: this integer, intent(in) :: i end subroutine End Module
Program Main use TestOOP use base_parallel_mod implicit none integer :: i, j integer, parameter :: N = 2000 type(pointerfunction) :: pf type(staticfunction) :: sf class(abstractfunction), pointer :: af type(concretefunction) :: cf call pumainit() !wrapper to mpi_initialize pf%f => fpointer allocate(concretefunction::af) do j = 1, N do i = 1, N call pf%f(i) end do end do do j = 1, N do i = 1, N call af%f(i) end do end do do j = 1, N do i = 1, N call cf%f(i) end do end do do j = 1, N do i = 1, N call sf%f(i) end do end do call pumaend() ! wrapper to mpi_finalize End Program