[petsc-users] is there a function to append matrix

Karl Lin karl.linkui at gmail.com
Mon Aug 31 22:51:59 CDT 2020


Thanks for the quick reply. The reason why I want to do this is because I
would like to build A and B separately first. Then do something with B by
itself. Then scale B by a constant. Then append B to A to make C and
continue some other matrix operations. I took a look at
MatGetLocalSubMatrix() and there is this line:

Depending on the format of mat, the returned submat may not implement
MatMult
<https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatMult.html#MatMult>().
Its communicator may be the same as mat, it may be PETSC_COMM_SELF
<https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/PETSC_COMM_SELF.html#PETSC_COMM_SELF>,
or some other subcomm of mat's.

what is the format that will make submat not being able to do MatMult()?
Thank you very much.

On Mon, Aug 31, 2020 at 10:29 PM Jed Brown <jed at jedbrown.org> wrote:

> Karl Lin <karl.linkui at gmail.com> writes:
>
> > If I have two matrix A and B with the same number of columns, same
> > distribution pattern (column ownership pattern) among processes but
> > different number of rows, is there a function to append B to A to make a
> > new matrix C = [A; B]? Thanks.
>
> Sort of; you can create a MatNest with the two matrices and (optionally)
> convert to AIJ format.
>
> Better, you can take the code that builds A and B, but call it on "local"
> submatrices; see MatGetLocalSubMatrix() or an example like
> src/snes/tutorials/ex28.c.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20200831/9e079a1a/attachment.html>


More information about the petsc-users mailing list