C****************************************************************************** C FILE: loop01.f C DESCRIPTION: C Demonstrates loop fusion C****************************************************************************** program loop01 IMPLICIT NONE integer ARRAY_SIZE parameter(ARRAY_SIZE = 100000) 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 X, Y, XX, YY 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 * A(I) + C(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 * 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 *, X,Y,XX,YY 999 end