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

Waltz Jan jl2862237661 at gmail.com
Mon May 29 03:49:40 CDT 2023


/* 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.html>


More information about the petsc-users mailing list