C****************************************************************************** C FILE: loop02.f C DESCRIPTION: C Demonstrates loop fusion C****************************************************************************** program loop02 IMPLICIT NONE integer ARRAY_SIZE parameter(ARRAY_SIZE = 16384) integer I, J real A(ARRAY_SIZE), AA(ARRAY_SIZE) real B(ARRAY_SIZE), BB(ARRAY_SIZE) real C(ARRAY_SIZE), CC(ARRAY_SIZE) real D(ARRAY_SIZE), DD(ARRAY_SIZE) real E(ARRAY_SIZE), EE(ARRAY_SIZE) real X, Y, Z, XX, YY, ZZ integer(8) T1, T2, IRTC C***************************************************************************** C* Unfused Loop * C***************************************************************************** T1 = IRTC() DO I=1, ARRAY_SIZE X = X * A(I) + B(I) ENDDO DO I=1, ARRAY_SIZE Y = Y * C(I) + D(I) ENDDO DO I=1, ARRAY_SIZE Z = Z * E(I) ENDDO T2 = IRTC() write(*,*)'Untuned loop took', (T2-T1)/1000000, 'msec' C***************************************************************************** C* Fused Loop * C***************************************************************************** T1 = IRTC() DO I=1, ARRAY_SIZE XX = XX * AA(I) + BB(I) YY = YY * CC(I) + DD(I) ZZ = ZZ * EE(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 *, X,Y,Z,XX,YY,ZZ 999 end