[petsc-dev] threadcomm memory leak

Barry Smith bsmith at mcs.anl.gov
Mon Jul 16 22:51:35 CDT 2012


On Jul 16, 2012, at 10:48 PM, Jed Brown wrote:

> On Mon, Jul 16, 2012 at 10:44 PM, Barry Smith <bsmith at mcs.anl.gov> wrote:
>   /* PETSC_COMM_SELF = PETSC_COMM_WORLD for MPIUNI */
> #if !defined(PETSC_HAVE_MPIUNI)
>   ierr = PetscCommDuplicate(PETSC_COMM_WORLD,&icomm,PETSC_NULL);CHKERRQ(ierr);
>   ierr = MPI_Attr_put(icomm,Petsc_ThreadComm_keyval,(void*)tcomm);CHKERRQ(ierr);
>   tcomm->refct++;               /* Share the threadcomm with PETSC_COMM_SELF */
> #endif
> 
>   ierr = PetscCommDuplicate(PETSC_COMM_SELF,&icomm,PETSC_NULL);CHKERRQ(ierr);
>   ierr = MPI_Attr_put(icomm,Petsc_ThreadComm_keyval,(void*)tcomm);CHKERRQ(ierr);
> 
> 
>   I would not do it this way. Instead I would write a general routine that attached a threadcomm to a MPI_Comm; this routine would get the threadcomm_keyval and if it did NOT find it then would be put the attribute, otherwise it would know one was already there. Say it is called PetscThreadCommAttach(MPI_Comm, threadcomm); then in this routine you would just write
> 
>     PetscThreadCommAttach(PETSC_COMM_WORLD, tcomm);
>     PetscThreadCommAttach(PETSC_COMM_SELF,tcomm);        /* won't attr it again for MPIUni because it is already there */
> 
> This looks good, but there is also a ref-counting check needed in PetscThreadCommDetach/Destroy because the thread pool (presumably) needs to be closed before PetscFinalize 
> returns.

   I'm not looking at the details now but PetscThreadCommFinalizePackage() is called and would do the shut down regardless of counts  I assume and possibly bitch and moan if all the other MPI_Comm's that have been attached to haven't been destroyed. (Which would come up as memory leaks anyways).

   Barry





More information about the petsc-dev mailing list