[petsc-users] Another question about MatAXPY

Barry Smith bsmith at mcs.anl.gov
Mon Jun 29 13:38:12 CDT 2015


> On Jun 29, 2015, at 1:28 PM, Michael Povolotskyi <mpovolot at purdue.edu> wrote:
> 
> Thank you.
> Is there a way to disable the squeeze?

  Not directly (it won't know what to do with the empty space). If you want to insure that a sparse matrix has a particular nonzero structure then just set values of 0.0 into the "extra" locations you want represented in the "nonzero pattern".  One simple way to do this is call MatSetValues() for the nonzero structure you want with all zero entries, then call MatAssemblyBegin/End(mat,MAT_FINAL_ASSEMBLY) and then call MatSetValues() to put the numerical values you want to set (which will be a subset of the location you put in with zeros) then call MatAssemblyBegin/End(mat,MAT_FINAL_ASSEMBLY) again.

  Barry

> Michael.
> 
> On 06/29/2015 01:58 PM, Barry Smith wrote:
>>> On Jun 29, 2015, at 10:49 AM, Michael Povolotskyi <mpovolot at purdue.edu> wrote:
>>> 
>>> Dear developers,
>>> I have the following question:
>>> 
>>> Imagine that I have two matrices A and B
>>> Both are created using MatCreateSeqAIJ(MPI_Comm comm,PetscInt m,PetscInt n,PetscInt nz,const PetscInt nnz[],Mat *A)
>>> with the same first 5 arguments.
>>> In addition, for both matrices I call
>>>  MatSetOption(A,MAT_NEW_NONZERO_ALLOCATION_ERR,PETSC_TRUE);
>>> 
>>> After this I set some entries to both A and B matrices and assemble them.
>>> Question: can I use MatAXPY with SAME_NONZERO_PATTERN argument?
>>    Only if you KNOW that they have the exact same nonzero pattern. The MatAssembly "squeezes" out any "extra" space that was preallocated but was not actually used when calling MatSetValues() so even if two matrices have the same preallocation it doesn't mean they have the same nonzero pattern.
>> 
>>   Barry
>> 
>> 
>>> Thank you,
>>> Michael.
>>> -- 
>>> Michael Povolotskyi, PhD
>>> Research Assistant Professor
>>> Network for Computational Nanotechnology
>>> Hall for Discover and Learning Research, Room 441
>>> West Lafayette, IN 47907
>>> Phone (765) 4949396
>>> 
> 



More information about the petsc-users mailing list