At 04:16 02-12-01 +0000, Jun Xiong wrote:
>Hello,
> I'm a novice in Fortran 90. In my opinion, once an allocatable or
>pointer array is allocated, it performs as efficient, i.e. fast, as a
>static or automatic array. But the fact surprises me. I wrote a simple test
>program as below:
>
>PROGRAM test
> IMPLICIT NONE
> INTEGER, PARAMETER :: N=5000
> REAL, DIMENSION(N, N) :: x1, x2
> REAL, DIMENSION(:, :), ALLOCATABLE :: y1, y2
> INTEGER :: i
> REAL, DIMENSION(0:10) :: t
>
> allocate(y1(N, N), y2(N, N))
>
> t(0)=secnds(0.0)
>
> call random_number(x1)
> t(1)=secnds(0.0)
> call random_number(y1)
> t(2)=secnds(0.0)
>
> x2=x1**2
> t(3)=secnds(0.0)
> y2=y1**2
> t(4)=secnds(0.0)
>
> do i=1, 3, 2
> write(*, *) t(i)-t(i-1), t(i+1)-t(i), (t(i+1)-t(i))/(t(i)-t(i-1))
> enddo
>
> deallocate(y1, y2)
>END PROGRAM test
>
> I compiled it with Compaq Visual Fortran 6.6 under Win2000
>professional, and executed it for several times. The results are almost the
>same as:
>3.304688 3.765625 1.139480
>0.000000 0.9804688 Infinity
>
>My questions are:
>(1) Why do the allocatable arrays y1 and y2 need more time to
>accomplish the same operations than the static arrays x1 and x2 in this
>program?
>(2) Do allocatable or pointer arrays ALWAYS perform at least 10%
>percent slower than static or automatic arrays?
>(3) If the answer to the question (2) is positive, any suggestions
>concerning the efficiency when using allocatable or pointer arrays?
>
>Sincerely,
>Jun Xiong
I cannot provide you with a general answer to these questions.
The subject arises every now and then on this list.
But I did the test again with the slightly modified program
to prevent cpu time beging zero.
The answer to qustion 2 is NO.
! [Jun Xiong] 2001-12-02 timing.f95
PROGRAM test
IMPLICIT NONE
INTEGER, PARAMETER :: N=1000
REAL, DIMENSION(N, N) :: x1, x2
REAL, DIMENSION(:, :), ALLOCATABLE :: y1, y2
INTEGER :: i
REAL, DIMENSION(0:10) :: t
allocate(y1(N, N), y2(N, N))
call cpu_time(t(0))
call cpu_time(t(0))
do i = 1, 10
call random_number(x1)
x1(n,n-1) = i
end do
call cpu_time(t(1))
do i = 1, 10
call random_number(y1)
y1(n,n-1) = i
end do
call cpu_time(t(2))
do i = 1, 10
x2=x1**2
x2(n,n-1) = i
end do
call cpu_time(t(3))
do i = 1, 10
y2=y1**2
y2(n, n-1) = i
end do
call cpu_time(t(4))
do i = 1, 3, 2
if(t(i) /= t(i-1) ) &
write(*, *) t(i)-t(i-1), t(i+1)-t(i), (t(i+1)-t(i))/(t(i)-t(i-1))
enddo
deallocate(y1, y2)
END PROGRAM test
! Results from one system:
!E:\Fortran\Test>atiming
! 1.15527 0.834961 0.722739
! 0.821289 0.968750 1.17955
! Another compiler:
!E:\Fortran\Test>stiming
! 2.36000 1.71000 0.724576
! 0.710000 0.710000 1.00000
!E:\Fortran\Test>stiming
! 2.36000 1.82000 0.771186
! 0.660000 0.760000 1.15152
Best regards,
--
Jan van Oosterwijk
Computing Centre
Delft University of Technology
Phone: +31 15 278 5017
Fax: +31 15 278 3787
mailto:[log in to unmask]
http://huizen.dto.tudelft.nl/vanOosterwijk/
|