[petsc-dev] marking objects as const in PETSc methods

Barry Smith bsmith at mcs.anl.gov
Wed Dec 1 13:27:24 CST 2010


  After wasting a bunch of Shri's time with my stupidity I realized it would be great if we could somehow mark PETSc objects to PETSc methods as "const" in either the source code and/or the manual pages. Or better yet, "not const".

  For example the first Vec argument to MatMult() is const but not the second. A more difficult example is that the Jacobian matrix argument to SNES is const (in some sense) but it is not to TS (since TS "adjusts" it before passing to SNES). I wasted Shri's time because the Jacobian in SNES for VI problems isn't const.

  Note that "const" here may not have the strict C meaning of not changing anything in the object. For example VecNorm() is const on the vector elements but caches the computed norm so does change the data inside the object.

  Comments, suggestions, more knowledge than I have on the whole const business?

   Thanks

     Barry

Note: The use of const for arguments to VecGetArrayRead() is slighly related to the Vec in the method being "const" but we've done a pretty good job of fixing most of them and this email isn't directly related to that.




More information about the petsc-dev mailing list