C****************************************************************************** C FILE: loop05.f C DESCRIPTION: C Demonstrates invarient IF code optimization C****************************************************************************** program loop05 IMPLICIT NONE integer ARRAY_SIZE parameter(ARRAY_SIZE = 1000) integer I, J real A(ARRAY_SIZE), AA(ARRAY_SIZE) real B(ARRAY_SIZE), BB(ARRAY_SIZE) real X, Y, XX integer(8) T1, T2, IRTC C***************************************************************************** C* Untuned Loop * C***************************************************************************** T1 = IRTC() DO I=1, ARRAY_SIZE DO J=1, ARRAY_SIZE IF (A(I).GT.100.0) THEN B(I) = A(I) - 3.7 ENDIF X = X + A(J) + B(I) ENDDO ENDDO T2 = IRTC() write(*,*)'Untuned loop took', (T2-T1)/1000000, 'msec' C***************************************************************************** C* Tuned Loop * C***************************************************************************** T1 = IRTC() DO I=1, ARRAY_SIZE IF (AA(I).GT.100.0) THEN BB(I) = AA(I) -3.7 ENDIF DO J=1, ARRAY_SIZE XX = XX + AA(J) + BB(I) ENDDO 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,XX 999 end