Send petsc-users mailing list submissions to
petsc-users@mcs.anl.gov
To subscribe or unsubscribe via the World Wide Web, visit
https://lists.mcs.anl.gov/mailman/listinfo/petsc-users
or, via email, send a message with subject or body 'help' to
petsc-users-request@mcs.anl.gov
You can reach the person managing the list at
petsc-users-owner@mcs.anl.gov
When replying, please edit your Subject line so it is more specific
than "Re: Contents of petsc-users digest..."
Today's Topics:
1. MatGetValues() can't return the correct values (Waltz Jan)
2. Re: MatGetValues() can't return the correct values (Barry Smith)
----------------------------------------------------------------------
Message: 1
Date: Mon, 29 May 2023 16:49:40 +0800
From: Waltz Jan <jl2862237661@gmail.com>
To: petsc-users@mcs.anl.gov
Subject: [petsc-users] MatGetValues() can't return the correct values
Message-ID:
<CAEj=jGKvgY5ys=4_=YoEZrE5Xu4Pj6FVxSq8XgUH=N=QF_C-vA@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
/* Solve J Y = F, where J is Jacobian matrix */
ierr = SNESComputeJacobian(snes, X, snes->jacobian, snes->jacobian_pre);
CHKERRQ(ierr);
PetscInt rstart, rend;
MatGetOwnershipRange(snes->jacobian, &rstart, &rend);
PetscInt row=1000, col=1000;
PetscScalar v;
if (row>=rstart && row<rend)
{
MatGetValues(snes->jacobian, 1, &row, 1, &col, &v);
PetscPrintf(PETSC_COMM_WORLD, "rstart: %d, rend: %d, row: %d, col: %d,
v: %e\n", rstart, rend, row, col, v);
}
It was supposed to return the value of the matrix at row 1001 and column
1001, but it returned the value at row 2001 and column 2001 instead. There
is a two-fold relationship between these coordinates, and I'm not sure if
it's related to the fact that I set the number of processes to 2.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20230529/e6c3eb3b/attachment-0001.html>
------------------------------
Message: 2
Date: Mon, 29 May 2023 11:01:32 -0400
From: Barry Smith <bsmith@petsc.dev>
To: Waltz Jan <jl2862237661@gmail.com>
Cc: petsc-users@mcs.anl.gov
Subject: Re: [petsc-users] MatGetValues() can't return the correct
values
Message-ID: <99A3D1B8-6CA1-41C3-8B19-E68F90A67102@petsc.dev>
Content-Type: text/plain; charset="us-ascii"
Perhaps run a very small problem with 2 ranks and use MatView() to see the matrix before getting the values. Maybe use the debugger (-start_in_debugger) and step through the code as it gets values. I would say there is very little chance it is getting the "wrong values" and is more likely due to a misunderstanding of the matrix usage.
Barry
> On May 29, 2023, at 4:49 AM, Waltz Jan <jl2862237661@gmail.com> wrote:
>
> /* Solve J Y = F, where J is Jacobian matrix */
> ierr = SNESComputeJacobian(snes, X, snes->jacobian, snes->jacobian_pre);
> CHKERRQ(ierr);
>
> PetscInt rstart, rend;
> MatGetOwnershipRange(snes->jacobian, &rstart, &rend);
> PetscInt row=1000, col=1000;
> PetscScalar v;
> if (row>=rstart && row<rend)
> {
> MatGetValues(snes->jacobian, 1, &row, 1, &col, &v);
> PetscPrintf(PETSC_COMM_WORLD, "rstart: %d, rend: %d, row: %d, col: %d, v: %e\n", rstart, rend, row, col, v);
> }
>
> It was supposed to return the value of the matrix at row 1001 and column 1001, but it returned the value at row 2001 and column 2001 instead. There is a two-fold relationship between these coordinates, and I'm not sure if it's related to the fact that I set the number of processes to 2.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20230529/345ddb55/attachment-0001.html>
------------------------------
Subject: Digest Footer
_______________________________________________
petsc-users mailing list
petsc-users@mcs.anl.gov
https://lists.mcs.anl.gov/mailman/listinfo/petsc-users
------------------------------
End of petsc-users Digest, Vol 173, Issue 131
*********************************************