[petsc-users] check if object was created

Barry Smith bsmith at mcs.anl.gov
Sun Oct 2 11:07:26 CDT 2011


On Oct 2, 2011, at 10:35 AM, Jed Brown wrote:

> On Sun, Oct 2, 2011 at 04:46, Dominik Szczerba <dominik at itis.ethz.ch> wrote:
> if(object)
>   KSP/Mat/Vec/etcDestroy(object)
> 
> Just call KSPDestroy(&ksp);
> 
> It doesn't matter if KSP is NULL or a valid object because this function checks. But note that if you just write
> 
> KSP ksp;
> 
> or allocate similarly in part of malloc() --- with no memzero() or similar --- then the value of ksp is undefined.


   In other words, if you are sometimes not sure if you will ever create a certain object make sure you initialize it to 0 with

   Vec vec = 0;

    .......


    VecDestroy(&vec);

     .....


     Note that we pass &vec as the argument and all the destroys set the value to 0 so it cannot be accidently used again.

   Barry

    



More information about the petsc-users mailing list