[petsc-dev] Simultaneous use of different precisions

Jed Brown jed at 59A2.org
Wed Nov 17 16:06:33 CST 2010


On Wed, Nov 17, 2010 at 22:41, Barry Smith <bsmith at mcs.anl.gov> wrote:

> I hate beyond words the standard C++ template model
>

Me too.


> This, I think, can be done using ONLY simple C++ function polymorphism
> (allowing VecSetValues(double*) and VecSetValues(single *) for example)
>

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)?

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.

But this does snowball if you want {Real,Complex}{Short,Long} in the same
code.

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.


Thanks for the summary, I hope it works out.

Jed
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-dev/attachments/20101117/1546d844/attachment.html>


More information about the petsc-dev mailing list