C****************************************************************************** C FILE: loop08.f C DESCRIPTION: C Demonstrates loop defactorization C****************************************************************************** program loop08 IMPLICIT NONE integer ARRAY_SIZE parameter(ARRAY_SIZE = 5000) integer I, J real(8) A(ARRAY_SIZE), AA(ARRAY_SIZE) real(8) B(ARRAY_SIZE), BB(ARRAY_SIZE) real(8) C(ARRAY_SIZE), CC(ARRAY_SIZE) real(8) D(ARRAY_SIZE), DD(ARRAY_SIZE) integer(8) T1, T2, IRTC C***************************************************************************** C* Factorized Loop * C***************************************************************************** T1 = IRTC() DO I=1, ARRAY_SIZE A(I) = 0.0D0 DO J = 1, ARRAY_SIZE A(I) = A(I) + B(J) * D(J) * C(I) ENDDO ENDDO T2 = IRTC() write(*,*)'Untuned loop took', (T2-T1)/1000000, 'msec' C***************************************************************************** C* Unfactorized Loop * C***************************************************************************** T1 = IRTC() DO I=1, ARRAY_SIZE AA(I) = 0.0D0 DO J = 1, ARRAY_SIZE AA(I) = AA(I) + BB(J) * DD(J) ENDDO AA(I) = AA(I) * CC(I) ENDDO T2 = IRTC() write(*,*)'Tuned loop took', (T2-T1)/1000000, 'msec' C Need to actually use the results of the calculations or else the C optimizing compiler may just skip doing them...so we'll just C print them. This will force the optimizer to actually do the work. print *, A(ARRAY_SIZE), AA(ARRAY_SIZE) 999 end