Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Optimisation of DO LOOP summation

DavidWhite
Valued Contributor II
231 Views

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

    DUMMY=0
    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?

Thanks,

David

0 Kudos
1 Reply
TimP
Honored Contributor III
231 Views

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.
 

0 Kudos
Reply