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

Bin Liu lbllm2018 at hotmail.com
Wed Apr 15 00:24:58 CDT 2020


Thanks Jacob. In my problem the rows/columns are not contiguous. Your suggestions are also very good. I will think about how to make use it somewhere else in my code.

Best
Bin

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

Also if you know that the rows/cols are contiguous (next to each other) in your sparse matrix then it is recommended to use MatSetValuesBlocked as it is more efficient.

Best regards,

Jacob Faibussowitsch
(Jacob Fai - booss - oh - vitch)
Cell: (312) 694-3391


On Apr 13, 2020, at 10:32 AM, Junchao Zhang <junchao.zhang at gmail.com<mailto:junchao.zhang at gmail.com>> wrote:

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.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20200415/82ceac5c/attachment.html>


More information about the petsc-users mailing list