Andy
Further to my previous posting on this matter, I have just tried my shiny
new Intel 7.0 compiler on my version of the three examples, and found that
all three give similar performance and that the performance was much the
same as the quickest time of the Compaq (6.6) compiler. So it looks to me
as if the Intel compiler is smart and can do the right thing quickly.
Does anyone have anything else to say about this? Each of my examples runs
in just over 6 seconds on my Pentium 4, 2.2 GHz.
Alistair
-----Original Message-----
From: Fortran 90 List [mailto:[log in to unmask]] On Behalf Of
Andy Leonard
Sent: 27 January 2003 15:39
To: [log in to unmask]
Subject: Performance penalties for allocatable arrays?
Can anyone explain why the use of allocatable arrays in the first example
program below causes a 10% increase in the CPU time spent in the subroutine,
compared to the second example program where the arrays are in a common
block? (When the allocatable is changed to pointer, it adds another 10%).
Both codes were compiled with the IBM xlf90 compiler (with the same compiler
options) and the cpu time determined by profiling with gprof.
We have noticed some significant increases in CPU time in our software since
we started dynamically allocating arrays. The trivial examples below are
representative of our code, as we frequently use common blocks (and now
modules) rather than passing data through the arguments.
Thanks,
Andy
Program 1:
c==============================
program main
use A_MOD
na = 100000
ALLOCATE(A(na))
ALLOCATE(dAdt(na))
do n=1,1000
call SUB
enddo
stop
end
c==============================
subroutine SUB
use A_MOD
do n=1,na
A(n) = A(n) + dAdt(n)*dt
enddo
return
end
c==============================
module A_MOD
integer :: na
real :: dt = 0.001
real, allocatable, dimension(:) :: A, dAdt
end module A_MOD
c==============================
Program 2:
c==============================
program main
parameter (na = 100000)
common /A_MOD/ dt,A(na),dAdt(na)
dt = 0.001
do n=1,1000
call SUB
enddo
stop
end
c==============================
subroutine SUB
parameter (na = 100000)
common /A_MOD/ dt,A(na),dAdt(na)
do n=1,na
A(n) = A(n) + dAdt(n)*dt
enddo
return
end
Andy Leonard
Gamma Technologies, Inc.
601 Oakmont Lane, Suite 220
Westmont, IL 60559
Tel: (630) 325-5848
Fax: (630) 325-5849
E-mail: [log in to unmask]
Web: http://www.gtisoft.com
|