[petsc-users] MatGetValues() can't return the correct values

Barry Smith bsmith at petsc.dev
Mon May 29 10:01:32 CDT 2023


    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 at 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.html>


More information about the petsc-users mailing list