[petsc-users] How can I do matrix addition with different nonzeros patterns correctly?
Barry Smith
bsmith at mcs.anl.gov
Fri Mar 3 15:55:23 CST 2017
> On Mar 3, 2017, at 3:31 PM, Fangbo Wang <fangbowa at buffalo.edu> wrote:
>
> Hi,
>
> I am a little bit confused on how to appropriately do matrix addition with different nonzeros patterns.
>
> Suppose I want to do D=2*A+3*B+4*C, A, B and C all have different nonzero patterns.
> I know I can use MatDuplicate, MatCopy, MatConvert to create a matrix D, which way is the right way?
There is no particular "right way". You could use a MatDuplicate() then a MatScale and then two MatAXPY()
D=2*A+3*B+4*C looks like a MATLAB thing, not something you would need to do when solving PDEs, where do you get this need? Perhaps there is an alternative way to get what you want.
>
> What's the difference between MatDuplicate and MatCopy?
MatDuplicate() CREATES a new matrix while MatCopy() copies values from an already existing matrix to another already existing matrix.
>
> Thank you very much!
>
> Best regards,
>
> Fangbo
>
>
> --
> Fangbo Wang, PhD student
> Stochastic Geomechanics Research Group
> Department of Civil, Structural and Environmental Engineering
> University at Buffalo
> Email: fangbowa at buffalo.edu
More information about the petsc-users
mailing list