> Hi list members!
>
> the enclosed testprogram investigates the CPU-time of different data
> access on a F90-structure. In my opinion there should be no difference in
> CPU-time.
>
> I use the data access via functions with private structures to control
> writing and reading of variables.
>
> (direct access) (function access)
> Linux CPU-time: 0.75 sec 2.1 sec
> NT CPU-time: 2.6 sec 3.7 sec
>
> Linux: Xeon 2.2 Ghz, Absoft Compiler V7.1, basic optimization -O
> NT: Pentium4 2.0 Ghz, Visual Compiler V6.1, best performance with
> /optimize:1
>
> I would be very greatful for any comment on this problem. And I thank you
> in
> advance for any reply!
>
> Uwe Martens
>
> MODULE FortranStructure
> TYPE :: structure ! fortran structure
> SEQUENCE
> DOUBLE PRECISION,DIMENSION(100) :: xArray
> END TYPE Structure
> CONTAINS
> DOUBLE PRECISION FUNCTION ReadX (struct,i) RESULT(x)
> IMPLICIT NONE
> TYPE (structure) :: struct ! structure
> INTEGER :: i ! i=index of component
> !DOUBLE PRECISION : x ! x=element i of array
> xArray
> x = struct%xArray(i)
> END FUNCTION ReadX
> SUBROUTINE WriteX (struct,x,i)
> IMPLICIT NONE
> TYPE (structure) :: struct ! structure
> DOUBLE PRECISION :: x ! x=element i of array
> xArray
> INTEGER :: i ! i=index of component
> struct%xArray(i) = x
> END SUBROUTINE WriteX
> END MODULE FortranStructure
>
> PROGRAM Performancetest
> USE FortranStructure
> IMPLICIT NONE
> TYPE (structure) :: struct ! structure
> INTEGER :: ntimes=1000000 ! maximum number of
> iterations
> INTEGER :: i=0 ! loop variable of
> iterations
> INTEGER :: j=0 ! loop variable of
> iterations
> REAL :: timeCPUstart=0.0 ! start-time in fortran
> function cpu_time
> REAL :: timeCPUend=0.0 ! end-time in fortran
> function cpu_time
> DOUBLE PRECISION :: x=100.D0 ! value for calculation
> ! direct access of structure elements
> CALL cpu_time(timeCPUstart)
> DO i=1,ntimes
> x = 0.D0
> DO j=1,100
> x = DBLE(j) + x ! dummy calculation to
> prevent compiler-optimization
> struct%xArray(j) = x
> ENDDO
> DO j=1,100
> x = struct%xArray(j)
> IF (x < 0.D0) WRITE(*,*) "x : ",x ! dummy output to
> prevent compiler-optimization
> ENDDO
> END DO
> CALL cpu_time(timeCPUend)
> WRITE(*,*) "cpu-time taken with direct access is :
> ",timeCPUend-timeCPUstart
> WRITE(*,*) "x : ",x ! check of array x
> ! function access of structure elements
> CALL cpu_time(timeCPUstart)
> DO i=1,ntimes
> x = 0.D0
> DO j=1,100
> x = DBLE(j) + x ! dummy calculation to
> prevent compiler-optimization
> CALL WriteX (struct,x,j)
> ENDDO
> DO j=1,100
> x = ReadX (struct,j)
> IF (x < 0.D0) WRITE(*,*) "x : ",x ! dummy calculation to
> prevent compiler-optimization
> ENDDO
> END DO
> CALL cpu_time(timeCPUend)
> WRITE(*,*) "cpu-time taken with subroutine access is :
> ",timeCPUend-timeCPUstart
> WRITE(*,*) "x : ",x ! check of array x
> END PROGRAM Performancetest
>
|