Optimisation of DO LOOP summation

Optimisation of DO LOOP summation

What is the best way to optimise loops like the following, which are from Steam and Water property calculations:

    DO i = 1,34
        DUMMY = DUMMY - nreg1(i) * ireg1(i) * (7.1D0 - pi) ** (ireg1(i) - 1) * &
            (tau - 1.222D0) ** jreg1(i)
    END DO
    gammapireg1 = DUMMY

ireg1 has values from 0 to 32 and jreg1 from 17 to -41

ireg1 and jreg1 are INTEGER PARAMETER arrays, and nreg1 is a REAL*8 PARAMETER array

Is it more efficient to calculate all the elements of the array result and sum at the end?



2 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

I expect ifort would split the loop automatically in cases where there is any chance of improved performance by summing separately.  To prevent this (unlikely in your case), insert "!dir$ distribute point" after the DO.

As the individual exponents are compile time constants, you might try to unroll the loop entirely so that optimizations might be engaged based on expanding e.g. x**i => x*x**(i-1).  An unroll directive e.g. !dir$ unroll(8) preceding DO might have useful effect even if it doesn't accomplish that.

Leave a Comment

Please sign in to add a comment. Not a member? Join today