[petsc-users] Check creation of an object

Jed Brown jed at 59A2.org
Tue Jun 21 04:49:11 CDT 2011


On Tue, Jun 21, 2011 at 11:18, Koenraad Janssens <koen.janssens at psi.ch>wrote:

> Is there a way to check whether an object has been created? I noticed PetSc
> crashes when calling PCView on a declared PC that has not been created yet.
>
>
> PC pc1;
> PCView(pc1, PETSC_VIEWER_STDOUT_WORLD);


No, pc1 has not been initialized. Compilers should warn about this, the
latest releases usually do. If you initialize pc1 to NULL (e.g. when it is
declared), then PETSc functions will give you an error message saying that
it is NULL.

If this occurs in main, the stack will usually be cleared, in which case pc1
will automatically be NULL (but don't rely on this). In other functions, you
have to expect that the stack is dirty. You can also run with valgrind which
detects the uninitialized access.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20110621/786fed0f/attachment.htm>


More information about the petsc-users mailing list