On Fri, Sep 28, 2012 at 12:25 PM, Karl Rupp <rupp at mcs.anl.gov> wrote:
> Hi guys, > > 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: > > template <typename MatrixType, typename VecType> > VecType solve(MatrixType const & A, VecType const & b); > > Everything went well if PETSc was not in use. However, I got really weird > compiler errors as soon as I've included petscksp.h. > > Now, fast-forward to today. While browsing through the existing > CUDA-enabled implementations, I found the following in src/ksp/pc/impls/ > sacusp.cu: > #undef VecType > #include <cusp/precond/smoothed_**aggregation.h> > #define VecType char* > While this preprocessor define is inside an implementation file, not in a > header file, one may consider that acceptable. > > However, a quick grep on the main include/ folder reveals > petscvec.h:#define VecType char* > 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: > VecLoad(PetscViewer viewer,VecType outtype,Vec *newvec); > and the associated hyperlink > > http://www.mcs.anl.gov/petsc/**petsc-dev/docs/manualpages/** > Vec/VecLoad.html#VecLoad<http://www.mcs.anl.gov/petsc/petsc-dev/docs/manualpages/Vec/VecLoad.html#VecLoad> > points to an HTML page defining the prototype > #include "petscvec.h" > PetscErrorCode VecLoad(Vec newvec, PetscViewer viewer) > > 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? > You are missing the fact that all PetscObjects have an implementation type and it is a string, and there is one of these #defines for every class. However, I would support namespacing all these Types since they are not in heavy use, e.g. PetscVecType, PetscMatType. Matt > Best regards, > Karli > > > PS: For reference, the following code compiles and prints "Hello World!": > > #include <iostream> > #include "petscksp.h" > > int main(int argc, char **args) > { > VecType test = "Hello world!"; > > std::cout << test << std::endl; > return EXIT_SUCCESS; > } > > To eliminate any warnings about deprecated conversion of strings, just add > 'const' in front of 'VecType'. > -- 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/20120928/caccc179/attachment.html>
