Re: Automatically transform or expand do loop in a subroutine
- From: *** Hendrickson <***.hendrickson@xxxxxxx>
- Date: Thu, 31 Jan 2008 17:44:04 GMT
yaqi wrote:
Hi All,
I knew following piece of code will not be compiled, at least with
Compaq Visual Fortran. My intention of this code is to let the
compiler automatically transform or expand the loop inside the
function (I do not care the code size) if the caller has a SMALL
CONSTANT integer 'd' in its argument list when the compiler is doing
optimization. Because the function is really crucial for the
performance, I want to save computing time as much as I can. So do not
ask me why I want to do this. Actually I guess this idea is similar as
the template in C++.
Are there any ways to implement this idea easily with Fortran?
Two other things to try. Many commercial compilers have some
sort of option to "inline" external procedures. Often controlled
by a command line switch. Look for this. You'll probably have to
have the program and function in the same file. If the code is
inlined, then the compiler will see the 10. Another way to
do the same thing is to make the function be an internal procedure
to the main program. The compiler is more likely to be able to
do optimizations.
Finally, as others have suggested, it's not a good idea to have
functions modify their arguments. If nothing else, it just gives
the optimizer one more reason to not do things. Make it a
subroutine.
*** Hendrickson
.
Thanks!
--------------------------------------------------------------------------
program main
integer :: e, c
e = ad(c, 10)
stop
end program main
integer function ad(c,d)
implicit none
integer :: c
integer, parameter :: d
integer :: i
do i=1,d
c = c + i
end do
ad = c
return
end function
- Follow-Ups:
- References:
- Prev by Date: Re: computing Bernoulli numbers
- Next by Date: Re: Automatically transform or expand do loop in a subroutine
- Previous by thread: Re: Automatically transform or expand do loop in a subroutine
- Next by thread: Re: Automatically transform or expand do loop in a subroutine
- Index(es):