[pooma-dev] Yes, Vector temporaries do appear in every operation...!!

Radek Pecher radek.pecher at eng.ox.ac.uk
Fri May 28 11:20:18 UTC 2004


| Note that without your debugging stuff in the constructors, these
| get inlined and optimized away by the optimizer.  Of course one
| could argue creating the copies should be avoided in the first
| place, but I cannot see how this can be done, as, f.i. for
| BinaryOp<Vector1, Vector2, OpMultiply>::operator() we clearly need
| to return a _new_ Vector as result.  To avoid this one would have
| to expression-template the vector itself, so only primitive
| variable types are ever copied.  But I don't think this will work
| or pay off.


I actually compiled the code with the original (unmodified) version of 
Vector.h first and used GDB to run it and disassemble it. Without 
much analysing, I noticed several looping jumps at the place of the 
algebraic expression which only confirms that the optimising compiler 
did not produce the required code:
v2(0) = v1(0)*v1(0) + v1(0)*v1(0);
v2(1) = v1(1)*v1(1) + v1(1)*v1(1);
as was supposed to. (And I also tried several other optimisation 
configurations, of course.)

As to the need for the return of a Vector, I suppose that
Vector<2, double, BinaryVectorOp<...> > is all is needed (with the 
references to its two operands). There is no need at all to take this 
object and make its Full-engine copy for any subsequent operations.




More information about the pooma-dev mailing list