[petsc-users] Allocating for existing space on Mat

Matthew Knepley knepley at gmail.com
Thu Jan 24 05:23:31 CST 2019


On Thu, Jan 24, 2019 at 4:53 AM Ali Reza Khaz'ali via petsc-users <
petsc-users at mcs.anl.gov> wrote:

> Hi all,
>
>
>
> As far as I understand, using MatSetValues for new non-zero entries will
> cause an error if MAT_NEW_NONZERO_LOCATION_ERR== PETSC_TRUE.  Setting
> MAT_NEW_NONZERO_LOCATION_ERR to PETSC_FALSE is also undesirable since it
> will slow down the code, and in some cases, the performance loss will be
> extreme. However, is there any solution for a matrix that the number of
> non-zeros on each of its rows is fixed in both diagonal and off-diagonal
> parts, but the location (the column number) of the non-zero entries may
> vary during the procedures? I can use MAT_NEW_NONZERO_LOCATION_ERR==
> PETSC_TRUE, but it is important to me that the code runs as fast as
> possible.
>
> Any help is much appreciated.
>

The main reason for slowdown is reallocation. However, MatAssembly will
squeeze out extra space in all rows.
Thus, in order to move entries around without reallocating, you must stick
zeros there when they are no used.
I would do this:

  1) Measure the performance degradation from doing this naively

  2) If it is noticeable, then go in and write a MatChangeRow() that allows
you to alter the column index and value.

  Thanks,

     Matt


>
>
> Best wishes,
>
> Ali
>


-- 
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

https://www.cse.buffalo.edu/~knepley/ <http://www.cse.buffalo.edu/~knepley/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20190124/e112b5cb/attachment.html>


More information about the petsc-users mailing list