[petsc-users] inserting multiple rows together into a matrix

Bin Liu lbllm2018 at hotmail.com
Wed Apr 15 20:54:02 CDT 2020


Sure. Noted. Thank you very much for your help.

From: Matthew Knepley [mailto:knepley at gmail.com]
Sent: Thursday, 16 April 2020 9:51 AM
To: Bin Liu <lbllm2018 at hotmail.com>
Cc: Junchao Zhang <junchao.zhang at gmail.com>; petsc-users at mcs.anl.gov
Subject: Re: [petsc-users] inserting multiple rows together into a matrix

On Wed, Apr 15, 2020 at 9:30 PM Bin Liu <lbllm2018 at hotmail.com<mailto:lbllm2018 at hotmail.com>> wrote:
Sure. Thanks for your information.  Actually, I used to call MatSetValues for each column. Since my matrix is sparse and I am not sure whether the non-zeros along each column are identical for each row, I am currently wondering if it is possible to insert the entire local dense matrix into the global sparse matrix using a single MatSetValues routine. Would it be more efficient than I identify the nonzeros and inserting them row-by-row? I may also set the “IGNORE_ZERO_ENTRIES” for the global sparse matrix before “MatSetValues”. Would it be helpful?

Inserting a dense matrix is likely the wrong thing to do. Generally row-by-row insertion is good.

  Thanks,

    Matt

Thanks for your helps.

From: Matthew Knepley [mailto:knepley at gmail.com<mailto:knepley at gmail.com>]
Sent: Wednesday, 15 April 2020 7:01 PM
To: Bin Liu <lbllm2018 at hotmail.com<mailto:lbllm2018 at hotmail.com>>
Cc: Junchao Zhang <junchao.zhang at gmail.com<mailto:junchao.zhang at gmail.com>>; petsc-users at mcs.anl.gov<mailto:petsc-users at mcs.anl.gov>
Subject: Re: [petsc-users] inserting multiple rows together into a matrix

On Wed, Apr 15, 2020 at 1:24 AM Bin Liu <lbllm2018 at hotmail.com<mailto:lbllm2018 at hotmail.com>> wrote:
Thanks for your example. My problem is resolved. Meanwhile I am wondering, if it is possible to make this example more flexible. I mean what if the columns in each row are different? Is there any way to insert them all together?

No. If the columns are different, you make a separate calls to MatSetValues().

  Thanks,

    Matt


Regards
Bin

From: Junchao Zhang [mailto:junchao.zhang at gmail.com<mailto:junchao.zhang at gmail.com>]
Sent: Monday, 13 April 2020 11:33 PM
To: Bin Liu <lbllm2018 at hotmail.com<mailto:lbllm2018 at hotmail.com>>
Cc: petsc-users at mcs.anl.gov<mailto:petsc-users at mcs.anl.gov>
Subject: Re: [petsc-users] inserting multiple rows together into a matrix

Add two rows 2 ,4,  and each row has three nonzeros at column 3, 7, 9
m=2;
n=3;
idxm[] = {2, 4};
idxn[] = {3, 7, 9};
v[6]   = {0.1, 0.2, ....};
MatSetValues(mat, m, idxm, n, idxn,v, INSERT_VALUES);

--Junchao Zhang


On Mon, Apr 13, 2020 at 9:59 AM Bin Liu <lbllm2018 at hotmail.com<mailto:lbllm2018 at hotmail.com>> wrote:
Hi all,

I know how to insert values in one row into the matrix via routine “MatSetValues”. I understand I logically should be able to insert multiple rows into the matrix with one call of “MatSetValues”. However, I am not sure how to do it. I searched in the PETSc mail list and did not find a relevant question answered before. Could anyone help me and give me a simple example code?

Regards
B.


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


--
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/20200416/7a13e595/attachment.html>


More information about the petsc-users mailing list