Questions about dependency analysis
Dominique Dhumieres
dominiq@lps.ens.fr
Tue Jan 22 11:22:00 GMT 2008
(1) Is the dependency in gfortran documented somewhere?
or only in the comments of gcc/fortran/dependency.*?
(2) Am I correct to understand that this analysis is quite
elementary and very conservative: non dependency is found
for simple (generic) cases, if not a dependency is assumed?
(3) If a dependency is assumed the RHS is stored in a temporary
with the same size as the LHS array, then copied back to it?
The two following tests seem to support these conclusions, but I
don't know if the middle-end can remove the/some unneeded temporaries.
integer, parameter :: n = 10
integer :: i
real :: a(0:n+1) = (/(real(i), i =0, n), 0.0/)
print *, sum(a)
a(:6:2) = a(::3)
print *, a
end
Here there is no dependency if the loop is computed with an ascending index.
Nevertheless I see temporaries even in the result of -fdump-tree-optimized -O3.
The second test is a very elementary finite-difference stencil for diffusion:
integer, parameter :: n = 10
integer :: i
real :: a(0:n+1) = (/(real(i), i =0, n), 0.0/)
print *, sum(a)
a(1:n)=(a(0:n-1)+a(2:n+1))/2.0
print *, sum(a)
end
Here the dependency cannot be avoided. Up to the result of
-fdump-tree-optimized -O3 the temporary has the size of a(1:n).
A standard trick reduces the size of the temporary to two scalars (which can be
eliminated from the loop by the middle-end):
tmp = a(0)
do i=1,n
res = (tmp+a(i+1))/2.0
tmp = a(i)
a(i) = res
end do
This extends to higher dimensions of the LHS, the bottom line being that the
temporary needed is the rank of the LHS minus one. For a 100**3 array, this
reduces the temporary form 1,000,000 elements to 10,000, having a chance to
stay in the cache of modern CPUs and reducing the memory footprint and
bandwith usage (limiting factor in this kind of code).
I think the dependency analysis is a rather elementary number theory problem
(I know most of the answers for only one index) and reducing the size of the
temporary seems doable, though I don't know how difficult it would be.
Is there any interest around to continue in this direction?
Cheers
Dominique
More information about the Fortran
mailing list