1
$\begingroup$

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?

$\endgroup$
  • $\begingroup$ This would be more appropriately asked of the petsc-users mailing list. $\endgroup$ – Bill Barth Nov 11 '14 at 14:10
  • $\begingroup$ 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. $\endgroup$ – John M Nov 12 '14 at 1:25
2
$\begingroup$

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.

$\endgroup$
  • 2
    $\begingroup$ How in the world did a PETSc developer get a downvote for this answer? $\endgroup$ – Bill Barth Nov 12 '14 at 1:35
  • $\begingroup$ @BillBarth I did. The answer doesn't look helpful at all to me. It references a "dirty backdoor", but never describes it. It raises a concern that seems only an edge case that can be detected and treated by returning an error. Seems to imply "it doesn't exist because it's a bad idea to do it" but never arguments for it properly. Overall, it feels more like a comment than an answer. I realize that it's a developer, and I thank him for his great job, but that doesn't mean an automatic upvote in my book. $\endgroup$ – Federico Poloni Nov 12 '14 at 9:46
  • 1
    $\begingroup$ 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.] $\endgroup$ – Jed Brown Nov 16 '14 at 5:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.