[petsc-users] Check Vec or Mat for validity

Johannes Huber johannes.huber at unibas.ch
Tue Oct 2 07:26:51 CDT 2012


Hi Jet,
thanks, that helps.
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.
Thanks a lot,
    Hannes
________________________________
From: petsc-users-bounces at mcs.anl.gov [petsc-users-bounces at mcs.anl.gov] on behalf of Jed Brown [jedbrown at mcs.anl.gov]
Sent: Tuesday, October 02, 2012 1:14 PM
To: PETSc users list
Subject: Re: [petsc-users] Check Vec or Mat for validity

On Tue, Oct 2, 2012 at 5:25 AM, Johannes Huber <johannes.huber at unibas.ch<mailto:johannes.huber at unibas.ch>> wrote:
Hi,
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.

You can't check for something like VecCreate because the statement

Vec X;

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

Vec X = PETSC_NULL;

in which case you could check

if (!X) { /* X has not be created yet */ }

but this would be a convention specific to your code.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20121002/a9dcd95b/attachment.html>


More information about the petsc-users mailing list