Re: Automatically transform or expand do loop in a subroutine
- From: Gordon Sande <g.sande@xxxxxxxxxxxxxxxx>
- Date: Thu, 31 Jan 2008 14:59:40 GMT
On 2008-01-31 00:15:54 -0400, yaqi <yaqiwang@xxxxxxxxx> said:
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?
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
Some compilers have options to unroll loops as part of their stronger
optimization strategies. Read the compiler documentation carefully.
This capability is more likely to be present in commercial compilers that
make a point of providing fast executables. As opposed to being free or
having good debugging. Some compilers will even inline small user functions
as part of their stronger optimization. If optimizing were truly important
for you I would expect that you would have current versions of several
compilers rather than one which has not been supported for several years.
Trying for improved performance by polishing code, whether manually or
by the compiler optimization, is usually a mugs game. The real improvements
come from better algorithms. Those are the 10 or 1000 times faster gains
if they can be done. Polishing is good for 10% gains and makes things so
complicated that you can no longer see the possibilities for better algorithms.
By all means set the optimization switches but put your real effort into
algorithms.
The fastest multiply you will ever do is the one you avoid doing!
.
- References:
- Prev by Date: Re: Fortran 2003: abstract interfaces
- Next by Date: Re: Allocatable Arrays As Outputs
- 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):
Relevant Pages
|