At 02:15 on 15 January, Werner Schulz wrote:
> Anthony Stone wrote:
>
> > > So what particular *kind* of problem is it? Can you give us a
> > > rough idea as to what the code is doing?
> >
> >It is accumulating contributions to multipole moments. Each set of
> >contributions is known to be zero above a maximum rank, evaluated for
> >each set and specified by "index" in the code. Although the
> >higher-rank contributions are known to be zero, one doesn't want
> >to execute the code for them, not only because it wastes cpu time but
> >because intermediate values used in the calculation have been
> >evaluated only for the non-zero ranks.
> >
> >
> Rather than arguing over the merits of the computed GOTO, I think this
> smells strongly
> of the need for a better algorithm implementation that better reflects
> the problem at hand.
> Multipol moment calculations (in spherical coordinates) imply that the
> following loops
> have to be executed:
> sum = ...
> do l=0,LMAX
> do m=-l,l
> ...
> end do
> end do
>
> Re-organising the code along these lines may get rid of any IF
> THEN/SELECT CASE structure
> altogether. I often find that adhering to the mathematical formalism
> yields simpler code than
> "optimisation" attempts (is the code trying to avoid complex calculations?).
Such a reformulation of the problem might indeed be helpful in some
cases. In my case it would involve repeating a great deal of code in
the body of the loop every time, and would unquestionably be a great
deal less efficient. The alternative to repeating the code would be to
compute and store a great deal of intermediate information before
executing the loop, and would be much more cumbersome. Both approaches
would be quite unnatural ways to tackle the problem, in which the
multipole contributions are readily obtained in batches by exact
numerical quadrature.
I remain of the view that the computed GOTO is a natural solution to
this admittedly rather special case. Evidently there are ways to avoid
it, and I thank everyone for their suggestions, but none of them, in
my view, offers any particular advantage except the avoidance of
labels. For some that might be an over-riding consideration, of
course, but let's not get into that discussion.
--
Anthony Stone http://www-stone.ch.cam.ac.uk/
University Chemical Laboratory, Email: [log in to unmask]
Lensfield Road, Phone: +44 1223 336375
Cambridge CB2 1EW Fax: +44 1223 336362
|