[petsc-users] efficiency of MatSetValues

Margarita Satraki margarita.satraki at gmail.com
Fri Feb 3 17:05:27 CST 2012


Does the same happen with MatDuplicate? It overwrites the
MatSeqAIJSetPreallocation?
In this case, can I redefine the nonzero places?

I need it for the case of creating the preconditioner by changing the
jacobian slightly.

Margarita

On 3 February 2012 22:58, Matthew Knepley <knepley at gmail.com> wrote:

> On Fri, Feb 3, 2012 at 4:46 PM, Margarita Satraki <
> margarita.satraki at gmail.com> wrote:
>
>> Hi Jed,
>>
>> Thanks for the reply.
>> I've defined 2 nonzeros per row so it should consider them to be in the
>> correct place (1 for diagonal and 1 for the 1st off diagonal). I do not
>> want to delete anything, just experiment with inserting new entries. This
>> is a simple example to demonstrate my problem with a more complicated code
>> of nonlinear elasticity.
>
>
> Assembly of a matrix compresses it, throwing away extra allocated places
> that were not used.
>
>    Matt
>
>
>
>> Margarita
>>
>>
>> On 3 February 2012 22:41, Jed Brown <jedbrown at mcs.anl.gov> wrote:
>>
>>> On Sat, Feb 4, 2012 at 01:35, Margarita Satraki <
>>> margarita.satraki at gmail.com> wrote:
>>>
>>>> It seems that only the 1st case gives good results in the sense that by
>>>> increasing the size of the matrix you increase the time needed by
>>>> MatSetValues linearly. Both the 2nd and the 3rd case give similar results,
>>>> much worse than the 1st. I understand that the 1st case has the advantage
>>>> because of accurate memory allocation but shouldn't the 2ndcase be better
>>>> than the 3rd since it at least defines the number of nonzeros per row so it
>>>> again allocates memory more accurately?
>>>
>>>
>>> Those nonzeros are in the wrong place and PETSc does not know that you
>>> want to "delete" the old entries.
>>>
>>> Just preallocate the correct number of nonzeros and it will be fast,
>>> don't bother with copying in a "similar" matrix.
>>>
>>
>>
>
>
> --
> What most experimenters take for granted before they begin their
> experiments is infinitely more interesting than any results to which their
> experiments lead.
> -- Norbert Wiener
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20120203/8697f7d8/attachment.htm>


More information about the petsc-users mailing list