On Wed, 3 Feb 2010, Ryan Yan wrote: > Hi all, > Can someone help me to understand the "Vec"? > > My question is: in the following piece of code, will "a" be changed, if "b" > is changed by the subroutine "SNESComputeFunction"? I did see that both a > and b are both pointers to an object.
Yes - all petsc datatypes [Vec,Mat etc..] are pointers to [opaque] objects. > > Vec a = b; So you can make copy of this pointer - and use it aswell. > Vec c; > > initalize c; > SNESComputeFunction(snes, c, b); > > If the answer is yes, then I guess what is modified is actually "*b" in the > above code, is that right? yes - the object [refered by this pointer] is modified. > BTW, I am wondering is there any explicit way that one can compare two > variables in the instance above in PETSc , especially when the content of > the object is rich. In the above case - if you are carrying multiple copies of pointers arround - you just check the pointers. [ a == b] The alternative is having multiple objects. Vec a, b <create a> <set values in a> VecDuplicate(a,&b) VecCopy(a,b) VecEqual(a,b,flag) Here 'a','b' are different vecs - so if a is modified - it has no relation to values of 'b' Satish