[petsc-users] efficiency of MatSetValues

Margarita Satraki margarita.satraki at gmail.com
Fri Feb 3 16:46:54 CST 2012


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.

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.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20120203/7a08dddd/attachment.htm>


More information about the petsc-users mailing list