# Re: Possible F77 Code Improvement ??

Gus Gassmann wrote:

On Mar 4, 5:42 pm, monir <mon...@xxxxxxxxxxxx> wrote:
(snip)
DO 25 JVORT= 1, NF !max 62
Kount = Kount + 1
C.......my code 2
SSX= valueXX
SSR= valueRR
SST= valueTT
C.......my code 3
ValX(Kount) = SSX*GAM(JVORT)*R(JVORT,1)
ValAbsX(Kount)=ABS(ValX(Kount))
ValR(Kount) = SSR*GAM(JVORT)*R(JVORT,1)
ValAbsR(Kount)=ABS(ValR(Kount))
ValT(Kount) = SST*GAM(JVORT)*R(JVORT,1)
ValAbsT(Kount)=ABS(ValT(Kount))
(snip)

I came to this thread late, but nobody has yet commented on the fact
that GAM(JVORT) and R(JVORT,1) do not depend on the outer loop
counter, NB. It would therefore make sense to switch the order of
these two loops. Are optimisers clever enough these days to figure
that out?

I think so, but it might be better to write it

ValX(Kount) = GAM(JVORT)*R(JVORT,1)*SSX

such that, evaluated left to right, the compiler sees the
common subexpression.

The OS/360 Fortran H compiler would have found that. Assuming
optimizers haven't gotten worse over the last 40 years, compilers
should still find it.

-- glen

.

## Relevant Pages

• Re: Possible F77 Code Improvement ??
... Kount = Kount + 1 ... and then sum the actual values in the new order ... Do you mean using higher than double precision ?? ... Can I do that with F77/g95 compiler ?? ...
(comp.lang.fortran)
• Re: Possible F77 Code Improvement ??
... Kount = Kount + 1 ... SST= valueTT ... that GAMand Rdo not depend on the outer loop ...
(comp.lang.fortran)