On 2012-02-19 11:31-0000 arjenmar...@users.sourceforge.net wrote:

> Revision: 12170
>          http://plplot.svn.sourceforge.net/plplot/?rev=12170&view=rev
> Author:   arjenmarkus
> Date:     2012-02-19 11:31:08 +0000 (Sun, 19 Feb 2012)
> Log Message:
> -----------
> Change the local declaration of "square* s" - the original was not accepted 
> by MS VC/C++.

Hi Arjen:

The new declaration location is still inside two for loops so doesn't
that mean at run time the memory required for s is put on the
stack/removed from the stack (a->ni)*(a->nj) times, i.e., the number
of iterations of the inner loop times the number of iterations of the
outer loop?  For large a->ni and a->nj this could become a run-time
efficiency concern.

In other words, isn't this an example of the general case of a
statement that should be be moved outside a loop (or loops) since it
doesn't depend on anything happening within the loop?  I suppose a
good optimizing compiler would effectively move all such statements
outside of loops, but I never completely trust such optimizations. (I
still vividly remember the case of the IBM fortran compiler in the
70's that calmly removed statements that _did_ depend on the loop
outside of the loop when you told it to "optimize".  So the programmer
lore then was to never ever use the optimizer for that compiler, and
it took IBM years to fix that bug.) In any case, I think it is simply
a matter of good programming practice to place statements in the right
location outside a loop or loops whenever we notice (as now) such
statements don't depend on anything in the loop.

I know this code was not your original responsibility, but since your
change to separate the declaration from the assignment has made a
further efficiency change possible, I think we should do that (and
also in any other case where we have an obvious case of a statement in
a loop that depends on nothing in the loop).

Alan
__________________________
Alan W. Irwin

Astronomical research affiliation with Department of Physics and Astronomy,
University of Victoria (astrowww.phys.uvic.ca).

Programming affiliations with the FreeEOS equation-of-state
implementation for stellar interiors (freeeos.sf.net); the Time
Ephemerides project (timeephem.sf.net); PLplot scientific plotting
software package (plplot.sf.net); the libLASi project
(unifont.org/lasi); the Loads of Linux Links project (loll.sf.net);
and the Linux Brochure Project (lbproject.sf.net).
__________________________

Linux-powered Science
__________________________

------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing 
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
Plplot-devel mailing list
Plplot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/plplot-devel

Reply via email to