[petsc-users] MatSetValues in runtime

Dave May dave.mayhem23 at gmail.com
Mon Dec 5 10:57:17 CST 2016


On 5 December 2016 at 16:49, Massoud Rezavand <msdrezavand at gmail.com> wrote:

> Dear Petsc team,
>
> In order to create a parallel matrix and solve by KSP, is it possible to
> directly use MatSetValues() in runtime when each matrix entry is just
> created  without MatMPIAIJSetPreallocation()?
>

Yes, but performance will be terrible without specify any preallocation
info.
See this note
http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatMPIAIJSetPreallocation.html

For a code example of for how to do the assembly without preallocation (not
recommended), you can refer to this (its the same pattern for MPIAIJ)

http://www.mcs.anl.gov/petsc/petsc-current/src/ksp/ksp/examples/tutorials/ex1.c.html


>
> I mean, when you only know the global size of Mat, and the number of
> nonzeros per row is not constant neither for all rows nor during time, is
> it possible to set the singular entries into Mat one by one after creating
> each one?
>

Why don't you just destroy the matrix and create a new one every time the
non-zero structure changes?
That's what I recommended last time.


Thanks,
  Dave


> Thanks
> Massoud
>
>
>
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20161205/3d4cbeab/attachment.html>


More information about the petsc-users mailing list