<div dir="ltr">On Tue, Jan 15, 2013 at 1:50 PM, Barry Smith <span dir="ltr"><<a href="mailto:bsmith@mcs.anl.gov" target="_blank">bsmith@mcs.anl.gov</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
  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.<br>
</blockquote><div><br></div><div style>I am fine with that.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
   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?<br>
</blockquote><div><br></div><div style>Not unless you have a way to lookup the integer from the string. Some people might only have the string.</div><div style><br></div><div style>   Matt</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

   Barry<br>
<br>
<br>
PetscErrorCode  MatQueryOp(MPI_Comm comm, PetscVoidFunction* function, const char op[], PetscInt numArgs, ...)<br>
{<br>
  PetscErrorCode ierr;<br>
  va_list        ap;<br>
  PetscInt       i;<br>
  const char     *argType;<br>
  char           **argTypes = PETSC_NULL;<br>
<br>
  PetscFunctionBegin;<br>
  va_start(ap,numArgs);<br>
  if (numArgs) {<br>
    ierr = PetscMalloc(sizeof(char*)*numArgs, &argTypes);CHKERRQ(ierr);<br>
  }<br>
  for (i = 0; i < numArgs; ++i) {<br>
    argType = va_arg(ap,const char*);<br>
    ierr = PetscStrallocpy(argType, argTypes+i);CHKERRQ(ierr);<br>
  }<br>
  va_end(ap);<br>
  ierr = PetscOpFListFind(comm, MatOpList, function, op, numArgs, argTypes);CHKERRQ(ierr);<br>
  for (i = 0; i < numArgs; ++i) {<br>
    ierr = PetscFree(argTypes[i]);CHKERRQ(ierr);<br>
  }<br>
  ierr = PetscFree(argTypes);CHKERRQ(ierr);<br>
  PetscFunctionReturn(0);<br>
}<br>
<br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br>What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>
-- Norbert Wiener
</div></div>