[petsc-dev] multiple dispatch code currently in PETSc

Matthew Knepley knepley at gmail.com
Tue Jan 15 14:06:38 CST 2013


On Tue, Jan 15, 2013 at 1:50 PM, Barry Smith <bsmith at mcs.anl.gov> wrote:

>
>   Do we really want mallocs for EVERY single multiple-dispatch function
> call in PETSc? I suggest not having MatQueryOp() but calling directly
> PetscOpFListFind() (with the MatOpFList argument) and changing
> PetscOpFListAdd/Find() to use variable args directly.
>

I am fine with that.


>    Finally do we really want string comparisons at all here? Or do we want
> XXXRegister() (for example, MatRegister()) to compute an integer type id to
> go with each char *type_name and do the search off the integer type id
> instead of strings? Thus making PetscOpFListFind() super light weight?
>

Not unless you have a way to lookup the integer from the string. Some
people might only have the string.

   Matt


>    Barry
>
>
> PetscErrorCode  MatQueryOp(MPI_Comm comm, PetscVoidFunction* function,
> const char op[], PetscInt numArgs, ...)
> {
>   PetscErrorCode ierr;
>   va_list        ap;
>   PetscInt       i;
>   const char     *argType;
>   char           **argTypes = PETSC_NULL;
>
>   PetscFunctionBegin;
>   va_start(ap,numArgs);
>   if (numArgs) {
>     ierr = PetscMalloc(sizeof(char*)*numArgs, &argTypes);CHKERRQ(ierr);
>   }
>   for (i = 0; i < numArgs; ++i) {
>     argType = va_arg(ap,const char*);
>     ierr = PetscStrallocpy(argType, argTypes+i);CHKERRQ(ierr);
>   }
>   va_end(ap);
>   ierr = PetscOpFListFind(comm, MatOpList, function, op, numArgs,
> argTypes);CHKERRQ(ierr);
>   for (i = 0; i < numArgs; ++i) {
>     ierr = PetscFree(argTypes[i]);CHKERRQ(ierr);
>   }
>   ierr = PetscFree(argTypes);CHKERRQ(ierr);
>   PetscFunctionReturn(0);
> }
>
>


-- 
What most experimenters take for granted before they begin their
experiments is infinitely more interesting than any results to which their
experiments lead.
-- Norbert Wiener
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-dev/attachments/20130115/f1ee543e/attachment.html>


More information about the petsc-dev mailing list