Hi Satish,<br>Thank you very much for the crystal clear explanation.<br><br>Yan<br><br><br><div class="gmail_quote">On Thu, Feb 4, 2010 at 12:24 AM, Satish Balay <span dir="ltr"><<a href="mailto:balay@mcs.anl.gov">balay@mcs.anl.gov</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div class="im">On Wed, 3 Feb 2010, Ryan Yan wrote:<br>
<br>
> Hi all,<br>
> Can someone help me to understand the "Vec"?<br>
><br>
> My question is: in the following piece of code, will "a" be changed, if "b"<br>
> is changed by the subroutine "SNESComputeFunction"? I did see that both a<br>
> and b are both pointers to an object.<br>
<br>
</div>Yes - all petsc datatypes [Vec,Mat etc..] are pointers to [opaque] objects.<br>
<br>
><br>
> Vec a = b;<br>
<br>
So you can make copy of this pointer - and use it aswell.<br>
<div class="im"><br>
> Vec c;<br>
><br>
> initalize c;<br>
> SNESComputeFunction(snes, c, b);<br>
><br>
> If the answer is yes, then I guess what is modified is actually "*b" in the<br>
> above code, is that right?<br>
<br>
</div>yes - the object [refered by this pointer] is modified.<br>
<div class="im"><br>
> BTW, I am wondering is there any explicit way that one can compare two<br>
> variables in the instance above in PETSc , especially when the content of<br>
> the object is rich.<br>
<br>
</div>In the above case - if you are carrying multiple copies of pointers<br>
arround - you just check the pointers. [ a == b]<br>
<br>
The alternative is having multiple objects.<br>
<br>
Vec a, b<br>
<br>
<create a><br>
<set values in a><br>
<br>
VecDuplicate(a,&b)<br>
VecCopy(a,b)<br>
VecEqual(a,b,flag)<br>
<br>
Here 'a','b' are different vecs - so if a is modified - it has no relation to values of 'b'<br>
<font color="#888888"><br>
Satish<br>
<br>
</font></blockquote></div><br>