[petsc-users] Question on non-zero pattern

Barry Smith bsmith at mcs.anl.gov
Thu Mar 14 15:36:05 CDT 2013


On Mar 14, 2013, at 3:17 PM, Sanjay Govindjee <s_g at berkeley.edu> wrote:

> Thanks.  I think I will just destroy and reallocat when the pattern changes since
> filling with zeros will force me into a bit of awkward programming.

   Before you ever generate the "real" values for the matrix, but after the preallocation call you could run over ALL the preallocated locations setting zeros and them call MatAssemblyBegin/End().  Now it is ready be be filled with any combination of "true" nonzero locations and you can call MatSetValues() on the just the first set of "true" non zeros and the MatAssemblyBegin/End() then repeat for the second set of "true" non zeros etc.

   Barry

> 
> On 3/14/13 12:59 PM, Satish Balay wrote:
>> Only if you did MatSetValues(val=0) for those extra locations - the
>> subsequent assembly will be efficient.
>> 
>> You can alway verify with -info
>> 
>> Satish
>> 
>> On Thu, 14 Mar 2013, Sanjay Govindjee wrote:
>> 
>>> When I pre-allocated, I preallocated sufficient on and off and off processor
>>> memory for
>>> all possible non-zero patterns.  So I assume that there will not be any
>>> mallocs necessary.
>>> Or am I mis-understanding how the preallocation works?
>>> 
>>> -sanjay
>>> 
>>> 
>>> 
>>> On 3/14/13 12:52 PM, Satish Balay wrote:
>>>> But you might have mallocs with the new nonzero structure. Its proably
>>>> more efficient to destroy/create a new mat with the new structure.
>>>> 
>>>> Satish
>>>> 
>>>> On Thu, 14 Mar 2013, Sanjay Govindjee wrote:
>>>> 
>>>>> Found my answer, use
>>>>> 
>>>>>            call
>>>>> MatSetOption(Kmat,MAT_NEW_NONZERO_LOCATIONS,PETSC_TRUE,ierr)
>>>>> 
>>>>> after the MatAssemblyEnd( ).
>>>>> 
>>>>> 
>>>>> On 3/14/13 11:28 AM, Sanjay Govindjee wrote:
>>>>>> Is there a mechanism for resetting a matrix's non-zero pattern?
>>>>>> 
>>>>>> In particular,  I have a preallocated a matrix, set the values, and
>>>>>> assembled it.
>>>>>> And used it to solve a problem.
>>>>>> 
>>>>>> Now I would like to zero it, and reassemble it with a different non-zero
>>>>>> pattern.
>>>>>> Note the matrix has been preallocated so that it can accommodate both
>>>>>> non-zero
>>>>>> patterns.
>>>>>> 
>>>>>> -sanjay
>>> 
> 



More information about the petsc-users mailing list