[petsc-users] MatCreateMPIAIJWithSplitArrays

Barry Smith bsmith at mcs.anl.gov
Tue Aug 2 12:30:13 CDT 2011


On Aug 2, 2011, at 11:09 AM, Kuhlemann, Verena wrote:

> HI,
> 
> I am creating a matrix with MatCreateMPIAIJWithSplitArrays, but I would like the arrays that I am using
> to create the matrix to be freed once the matrix is destroyed. Is this the correct way to do this?
> 
>    MatCreateMPIAIJWithSplitArrays(PETSC_COMM_WORLD,ne,nf,PETSC_DETERMINE,PETSC_DETERMINE,ia_E_d,ja_E_d,v_E_d,ia_E_o,ja_E_o,v_E_o,E);
> //set flags so that arrays are freed once the matrix is destroyed
>  mpimat= (Mat_MPIAIJ*)(*E)->data;
>  a=(Mat_SeqAIJ*)(mpimat->A)->data;
>  b=(Mat_SeqAIJ*)(mpimat->B)->data;
>  a->free_a  = PETSC_TRUE;
>  a->free_ij = PETSC_TRUE;
>  b->free_a  = PETSC_TRUE;
>  b->free_ij = PETSC_TRUE;
> 
   Try it.  BUT the original arrays must be obtained with PetscMalloc() not plain malloc().  If you cannot use PetscMalloc() then you can use PetscContainerCreate(), PetscContainerSetUserDestroy() and then PetscObjectCompose() to attach the container to the original matrix (MPIAIJ) then when the matrix is destroyed the user provided container destroy function is automatically called and in it you can free the individual pointers anyway you like.,

   Barry


> 
> Thanks,
> 
> Verena
> 
> 
> This e-mail message (including any attachments) is for the sole use of
> the intended recipient(s) and may contain confidential and privileged
> information. If the reader of this message is not the intended
> recipient, you are hereby notified that any dissemination, distribution
> or copying of this message (including any attachments) is strictly
> prohibited.
> 
> If you have received this message in error, please contact
> the sender by reply e-mail message and destroy all copies of the
> original message (including attachments).



More information about the petsc-users mailing list