[petsc-users] more flexible MatSetValues?

Jed Brown jed at 59A2.org
Sat Feb 19 03:21:09 CST 2011


Values in each location are often set many times. Once per element in FEM,
so about 20 times for P1 tets. That uses a lot more memory and you need to
sort that beast to count correctly. Using a separate dynamic data structure
for each row would be a lot more mallocs, but you could keep the rows sorted
and avoid storing 20 copies, however insertion is still expensive. A heap is
nice for insertion, but not for searching.

So dynamic data structures could help, but they still cost quite a bit. The
preallocation problem is trivial for finite difference methods so any useful
solution needs to handle many insertions to the same location.

On Feb 19, 2011 9:35 AM, "Gong Ding" <gdiso at ustc.edu> wrote:

Hi,
After reading the source code of aij.c, I think the MatSetValues function
can be more flexible when preallocation is not correct.

Why not use a dynamic array such as c++ vector of triple(a, i, j) to buffer
the operation?
And flush the buffer to real a,i,j array when MatAssemblyEnd is called?

Gong Ding
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20110219/c65a1fb2/attachment.htm>


More information about the petsc-users mailing list