Thanks a lot for your prompt reply and useful advice. I have another question. In my current case, I don't change any value in the sub-vector and in another words I used it as read-only. What should I do after I don't need it anymore? Should I call VecRestoreSubVector method or it is faster if I call the Destroy method on the sub-vector ?
If I understand you correctly, the subvector doesn't have any space for itself, in that case Destroy method does not release the memory. And finally, I destroy the original vector after I call either Restore or Destroy on the sub-vector. Best, Ehsan On Wed, Jun 22, 2016 at 12:44 PM, Matthew Knepley <[email protected]> wrote: > On Wed, Jun 22, 2016 at 9:21 AM, ehsan sadrfaridpour <[email protected]> > wrote: > >> Hi, >> >> If I use VecGetSubVector to get a subvector it works fine as far as I >> don't destroy the original vector. >> But, if I destroy the original vector, I get NaN values. So, it is my >> misunderstanding of what the function suppose to do, or is it a problem? >> > > You cannot destroy the original vector since you still need to call > > > http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Vec/VecRestoreSubVector.html#VecRestoreSubVector > > >> I do the same thing with MatGetSubMatrix >> <http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatGetSubMatrix.html#MatGetSubMatrix> >> and I haven't had any problem with it. >> > > MatGetSubMatrix() is a hybrid since for INITIAL_MATRIX it creates a new > matrix, whereas for REUSE_MATRIX it refills and existing > one. However there is not Restore(). > > > http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatGetSubMatrix.html > > Matt > > Best, >> Ehsan >> > > > > -- > What most experimenters take for granted before they begin their > experiments is infinitely more interesting than any results to which their > experiments lead. > -- Norbert Wiener >
