<div class="gmail_quote">On Wed, Nov 17, 2010 at 22:41, Barry Smith <span dir="ltr"><<a href="mailto:bsmith@mcs.anl.gov">bsmith@mcs.anl.gov</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div id=":uj"> I hate beyond words the standard C++ template model</div></blockquote><div><br></div><div>Me too.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div id=":uj">This, I think, can be done using ONLY simple C++ function polymorphism (allowing VecSetValues(double*) and VecSetValues(single *) for example)</div></blockquote><div><br></div><div>If I call VecGetArray(X,&singleptr) and X is "double", would this error or make a copy?  What about "local" callbacks (or any callback that passes scalars)?  And any composed function (that part is not type safe, so C++ name mangling won't save you)?</div>
<div><br></div><div>An acceptable C solution might be to have a PetscShortScalar typedef, VecGetArrayShort(), and maybe also MatSetValuesShort() (integration for assembly can be time consuming, and float is twice as fast if you vectorize well) which would give you no-copy access to short storage.  You could still have C++ overloaded variants, but I usually want some explicit control over types matching.  To allow people to make their Shorts (likely float) into Longs (likely double), have them recompile with a macro defined that causes the Short names to be defined to the long ones.</div>
<div><br></div><div>But this does snowball if you want {Real,Complex}{Short,Long} in the same code.</div><div><br></div><div>Documentation for the Short variants could be organized so that it doesn't cause clutter, but hopefully there aren't a huge number that need this specialization.</div>
<div><br></div><div><br></div><div>Thanks for the summary, I hope it works out.</div><div><br></div><div>Jed</div></div>