"Garth N. Wells" <gn...@cam.ac.uk> writes: > Hi Jed, > > I've been poking around the PETSc code to see how objects manage the MPI > communicator that is passed in, and running some simple tests using > MPI_Comm_compare. Does a PETSc object (say a Vec) always duplicate the > communicator? From tests with MPI_Comm_compare this looks to be the > case.
The first time a communicator is encountered by a PETSc object, PetscCommDuplicate dups it, yielding an "inner" communicator. It attaches the inner communicator, a reference count, and a tag dispenser to the outer communicator that you just passed in. We always use the tag dispenser to get new tags, always perform operations on the inner communicator. The user never handles the inner communicator. Subsequent calls to PetscCommDuplicate will find the attribute and just pull out the inner communicator. The outer communicator can be passed around, including through other libraries, and back into PETSc, yet there will still only ever be one inner comm per outer comm. When an object is destroyed, the reference count decreases and the inner communicator is destroyed when the reference count drops to zero. Barry, this code has been around for ages, but we should write a short report explaining what we do and why.
pgpE3UP5OduNK.pgp
Description: PGP signature