[petsc-dev] MatISGetLocalMat: need to MatDestroy the returned local matrice ?

Stefano Zampini stefano.zampini at gmail.com
Fri May 19 10:02:12 CDT 2017


Franck,

if you get the local mat, you are free to do whatever you want with it. One possible case is that you create the MATIS object (i.e., basically a l2g map of dofs + local mat creation) and then do

MatISGetLocalMat(matis,&A);
MatXAIJSetPreallocation(A,…..)
MatSetValues(A,…)

What do you need it for?

Stefano

> On May 19, 2017, at 4:57 PM, Franck Houssen <franck.houssen at inria.fr> wrote:
> 
> Thanks.
> 
> My understanding (?) is that modifying the local mat (with MatMult for instance) changes also the global mat (as the local mat is a part of the global one). Jed, I let you decide if this behavior (which is logical but not always the desired one) is worth to be emphasized in the doc...
> 
> Franck
> 
> ----- Mail original -----
>> De: "Jed Brown" <jed at jedbrown.org>
>> À: "Franck Houssen" <franck.houssen at inria.fr>, petsc-dev at mcs.anl.gov
>> Envoyé: Vendredi 19 Mai 2017 16:20:14
>> Objet: Re: [petsc-dev] MatISGetLocalMat: need to MatDestroy the returned local	matrice ?
>> 
>> Thanks.  I just pushed this.
>> 
>> commit 96a6f12955a790d77f6eb7eb6b1dcf9dd5e1cf30
>> Author: Jed Brown <jed at jedbrown.org>
>> Date:   Fri May 19 08:17:45 2017 -0600
>> 
>>    MatISGetLocalMat: add note on reference counting
>> 
>>    Reported-by: Franck Houssen <franck.houssen at inria.fr>
>> 
>> diff --git a/src/mat/impls/is/matis.c b/src/mat/impls/is/matis.c
>> index dc4a894aae..287c0aa554 100644
>> --- a/src/mat/impls/is/matis.c
>> +++ b/src/mat/impls/is/matis.c
>> @@ -837,6 +837,9 @@ PetscErrorCode MatISGetLocalMat_IS(Mat mat,Mat *local)
>>   matrix and want to provide it to the inner matrix object to improve the
>>   performance
>>   of the MatSetValues() operation.
>> 
>> +  This function does not increase the reference count for the local Mat.  Do
>> not destroy it and do not attempt to use
>> +  your reference after destroying the parent mat.
>> +
>> .seealso: MATIS
>> @*/
>> PetscErrorCode MatISGetLocalMat(Mat mat,Mat *local)
>> 
>> Franck Houssen <franck.houssen at inria.fr> writes:
>> 
>>> Hello,
>>> 
>>> Do I need to MatDestroy the local matrix returned by MatISGetLocalMat ?
>>> (the global matrix has been created with MatCreateIS)
>>> 
>>> Tried to look in the source tree... But I'am not sure to get the answer: in
>>> petsc-3.7.6/src/mat/impls/is/matis.c, MatISGetLocalMat seems to call
>>> MatISGetLocalMat_C, but, I can't find MatISGetLocalMat_C in the source
>>> tree !?...
>>> 
>>> Franck
>> 




More information about the petsc-dev mailing list