Efficiently swap vectors in PETSC

The PETSC function VecSwap after a few layers of abstraction calls the BLAS primitive swap, which essentially copies data around (unless I am missing something).

It seems to me that there should be a O(1) implementation that can be obtained just by exchanging pointers, at least if the vectors are identical in all their characteristics (underlying storage and distribution between the nodes).

So, is there a way to swap vectors without a deep copy in PETSC?

• This would be more appropriately asked of the petsc-users mailing list. – Bill Barth Nov 11 '14 at 14:10
• I disagree Bill, PETSc is open source and used in many different solving programs. Since stackoverflow is more for coding, I think this is the perfect place to come for PETSc help and it is the primary reason I made an account for this specific stackexchange site. – John M Nov 12 '14 at 1:25

What if one Vec was created by VecCreateSeqWithArray and the other not? How would the user know which Vec holds the memory they allocated? There is a dirty backdoor in VecPlaceArray, but using it is typically bad design.
• FWIW, I answered why such a function does not exist and cannot be implemented without either creating a monster (inconsistent behavior) or removing functionality that we feel is more important. You should write your code to either swap the handles as in Vec tmp; tmp = x; x = y; y = tmp; or call VecSwap. (It's unlikely the performance cost is significant unless you do it in an inner loop.) [I don't care about the votes, but I want to be helpful.] – Jed Brown Nov 16 '14 at 5:29