Re: Automatically transform or expand do loop in a subroutine



yaqi <yaqiwang@xxxxxxxxx> wrote:

I want to save computing time as much as I can.
....

do i=1,d
c = c + i
end do

The "obvious" way to save a lot of computing time here is to replace the
loop with

c = c + d*i

While that might seem so obvious as to be not worth saying, I have seen
people overlook more obvious things. One of the first rules of
optimization is to look for algorithm improvements instead of cure
optimization tricks. Multiplication would seem like a substantial
algorithm improvement here.

Other than that, no, there is no concept of a "constant" dummy argument.
A dummy argument is a variable by definition.

I note as an aside that having a function that changes the value of its
argument might possibly inhibit some optimizations. (And it is often
considered a bad idea for other reasons as well).

You can, of course, do all kinds of things outside of the language per
se, using macro preprocessors to generate multiple versions of the
function and calling the appropriate one if the argument value is known
at macro-processing time. There is nothing really Fortran-specific about
that.

--
Richard Maine | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle | -- Mark Twain
.