Re: Speed penalty for using allocatable arrays?
- From: "Mark Morss" <mfmorss@xxxxxxx>
- Date: 14 Nov 2006 04:53:10 -0800
"Leading dimension" means dimension 1, I assume. Is this an x86
problem or a general problem? It's rather disturbing, in any case, if
an innocent size choice along the first dimension can cause a
significant performance hit. What, rather than a 16-row array, should
a 17-row array be specified, and one row not used?
One would hope that this issue had been addressed by those writing
Fortran compilers, rather than having being left those writing Fortran
applications. It should not be necessary to master such arcana to be
able to write efficient Fortran code.
Kay Diederichs wrote:
jomarbueyes@xxxxxxxxxxx wrote:
Dear Group,
I am in the process of converting a collection of Fortran 77 programs
into
Fortran 90/95. One of the reasons for converting is the dynamic memory
allocation available in Fortran 90/95. However, I noticed that the
version
of the program that allocates the large arrays we use runs at a much
slower speed compared to the version of the same program that uses
static allocation. More precisely, the arrays are allocated once at the
begining of the program and then they are used in an iterative
algorithm.
With the Irix MIPSpro compiler version 7.4, each iteration slows down
by a factor of approx. one third when allocating the large arrays
(compared to statically allocating them). With the Absoft Fortran 90
compiler (Pro-Fortran Version 8) on G4 and G5 Macintosh computers
(Mac OS 10.3.9), each iteraion of the program that allocates the large
arrays runs at about half the speed of the static-memory version.
Is this a known "feature" of Fortran 90/95? Is there a solution to this
problem other than going back to static memory allocation?
Feedback to this newsgroup and/or e-mail to jomarBueyes@xxxxxxxxxxx
will be greatly appreciated.
Jomar
(jomarBueyes@xxxxxxxxxxx)
Jomar,
if you use two-dimensional (or higher) arrays then the leading dimension
should not be a power of 2 (e.g. 128, 256, ...), otherwise you run into
adverse cache effects in case you vary the second (or a higher) array
index fastest (this is inavoidable in 2D-FFTs, for example).
Probably your Fortran77 program had a non-power-of-2 leading dimension
for the array(s) it defined. Maybe your Fortran90 version allocates them
with the size violating the rule above.
Try the little test program below. On the CPUs that I tried, the penalty
was a factor of 5 and more.
HTH,
Kay
double complex,allocatable :: a(:,:)
integer i,j
real t1,t2,t3,t4
print*,'enter power of 2'
read*,n
allocate(a(n+4,n+4))
do m=n-4,n+4
a=1.
call cpu_time(t1)
do l=1,max(1,10000000/(n*n))
call test(a,m,n-4)
end do
call cpu_time(t2)
print '(i,f8.3)',m,t2-t1
end do
end
subroutine test(a,m,n)
! goes through a in "wrong" order
double complex a(m,m)
do i = 2, n-1
do j = 2, n-1
a(i,j) = (a(i+1,j-1) + a(i-1,j+1)) * 0.5
end do
enddo
end
.
- Follow-Ups:
- Re: Speed penalty for using allocatable arrays?
- From: glen herrmannsfeldt
- Re: Speed penalty for using allocatable arrays?
- From: Jan Vorbrüggen
- Re: Speed penalty for using allocatable arrays?
- References:
- Speed penalty for using allocatable arrays?
- From: jomarbueyes
- Re: Speed penalty for using allocatable arrays?
- From: Kay Diederichs
- Speed penalty for using allocatable arrays?
- Prev by Date: Re: Speed penalty for using allocatable arrays?
- Next by Date: Re: Speed penalty for using allocatable arrays?
- Previous by thread: Re: Speed penalty for using allocatable arrays?
- Next by thread: Re: Speed penalty for using allocatable arrays?
- Index(es):
Relevant Pages
|