[petsc-users] check if object was created

Dominik Szczerba domel07 at gmail.com
Sun Oct 2 12:04:09 CDT 2011


Ok these answer my question. Many thanks!
On Oct 2, 2011 6:07 PM, "Barry Smith" <bsmith at mcs.anl.gov> wrote:
>
> 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
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20111002/2e71ccf1/attachment.htm>


More information about the petsc-users mailing list