On Fri, Sep 28, 2012 at 12:25 PM, Karl Rupp <span dir="ltr"><<a href="mailto:rupp@mcs.anl.gov" target="_blank">rupp@mcs.anl.gov</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi guys,<br>
<br>
a long time ago, I stumbled upon one thing that caused a lot of headaches when interfacing my code with PETSc. Stripping away all the details, my solver interface looked about like this:<br>
<br>
template <typename MatrixType, typename VecType><br>
VecType solve(MatrixType const & A, VecType const & b);<br>
<br>
Everything went well if PETSc was not in use. However, I got really weird compiler errors as soon as I've included petscksp.h.<br>
<br>
Now, fast-forward to today. While browsing through the existing CUDA-enabled implementations, I found the following in src/ksp/pc/impls/<a href="http://sacusp.cu" target="_blank">sacusp.cu</a>:<br>
  #undef VecType<br>
  #include <cusp/precond/smoothed_<u></u>aggregation.h><br>
  #define VecType char*<br>
While this preprocessor define is inside an implementation file, not in a header file, one may consider that acceptable.<br>
<br>
However, a quick grep on the main include/ folder reveals<br>
 petscvec.h:#define VecType char*<br>
which is ultimately the reason why my template code went nuts. While I do understand that name clashes can appear, I tried to find the deeper meaning of VecType. The manual lists only one reference on page 170:<br>
 VecLoad(PetscViewer viewer,VecType outtype,Vec *newvec);<br>
and the associated hyperlink<br>
<br>
<a href="http://www.mcs.anl.gov/petsc/petsc-dev/docs/manualpages/Vec/VecLoad.html#VecLoad" target="_blank">http://www.mcs.anl.gov/petsc/<u></u>petsc-dev/docs/manualpages/<u></u>Vec/VecLoad.html#VecLoad</a><br>
points to an HTML page defining the prototype<br>
 #include "petscvec.h"<br>
 PetscErrorCode  VecLoad(Vec newvec, PetscViewer viewer)<br>
<br>
This suggests that VecType is not in use here, and it may not be in serious use at all. I can find about five uses of VecType in the whole include/-folder, so it shouldn't be too hard to get rid of that (e.g. by renaming to PetscVecType or any other more descriptive name), should it? Do I miss something?<br>
</blockquote><div><br></div><div>You are missing the fact that all PetscObjects have an implementation type and it is a string, and there is</div><div>one of these #defines for every class.</div><div><br></div><div>However, I would support namespacing all these Types since they are not in heavy use, e.g. PetscVecType, PetscMatType.</div>
<div><br></div><div>   Matt</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Best regards,<br>
Karli<br>
<br>
<br>
PS: For reference, the following code compiles and prints "Hello World!":<br>
<br>
#include <iostream><br>
#include "petscksp.h"<br>
<br>
int main(int argc, char **args)<br>
{<br>
  VecType test = "Hello world!";<br>
<br>
  std::cout << test << std::endl;<br>
  return EXIT_SUCCESS;<br>
}<br>
<br>
To eliminate any warnings about deprecated conversion of strings, just add 'const' in front of 'VecType'.<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<br>