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
|