<html dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style id="owaParaStyle" type="text/css">P {margin-top:0;margin-bottom:0;}</style>
</head>
<body ocsi="0" fpstyle="1">
<div style="direction: ltr;font-family: Tahoma;color: #000000;font-size: 10pt;">Hi Jet,<br>
thanks, that helps. <br>
I forgot, that there is no construtor and thus what I asked for is just not possible to achieve. So I've got to go with your solution, which is fine for me.
<br>
Thanks a lot,<br>
    Hannes<br>
<div style="font-family: Times New Roman; color: #000000; font-size: 16px">
<hr tabindex="-1">
<div style="direction: ltr;" id="divRpF195107"><font color="#000000" face="Tahoma" size="2"><b>From:</b> petsc-users-bounces@mcs.anl.gov [petsc-users-bounces@mcs.anl.gov] on behalf of Jed Brown [jedbrown@mcs.anl.gov]<br>
<b>Sent:</b> Tuesday, October 02, 2012 1:14 PM<br>
<b>To:</b> PETSc users list<br>
<b>Subject:</b> Re: [petsc-users] Check Vec or Mat for validity<br>
</font><br>
</div>
<div></div>
<div>On Tue, Oct 2, 2012 at 5:25 AM, Johannes Huber <span dir="ltr"><<a href="mailto:johannes.huber@unibas.ch" target="_blank">johannes.huber@unibas.ch</a>></span> wrote:<br>
<div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex; border-left:1px #ccc solid; padding-left:1ex">
<div>
<div style="direction:ltr; font-size:10pt; font-family:Tahoma">Hi,<br>
I'd like to check, whether for a Vec or a Mat the creation process (VecCrteate, VecSetSize, VecSetFromOptions or VecDuplicate or ...) has already been done or not, i.e. I'd like to check, wether the Vec or Mat is a valid object.<br>
</div>
</div>
</blockquote>
<div><br>
</div>
<div>You can't check for something like VecCreate because the statement</div>
<div><br>
</div>
<div>Vec X;</div>
<div><br>
</div>
<div>does not initialize X, thus X _could_ point to valid memory (even possibly containing a valid classid, for example, if the last stack frame had allocated a vector and malloc has not given the memory back to the system and has not reused it yet), though
 it may also point to some garbage address that cannot be dereferenced without seg-faulting your application. You could, as a matter of practice, always write</div>
<div><br>
</div>
<div>Vec X = PETSC_NULL;</div>
<div><br>
</div>
<div>in which case you could check</div>
<div><br>
</div>
<div>if (!X) { /* X has not be created yet */ }</div>
<div><br>
</div>
<div>but this would be a convention specific to your code.</div>
</div>
</div>
</div>
</div>
</body>
</html>