<html><head><meta http-equiv="content-type" content="text/html; charset=us-ascii"></head><body style="overflow-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><div><br></div> 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.<div><br></div><div> Barry</div><div><br><div><div><br></div><div> <br><div><br><blockquote type="cite"><div>On May 29, 2023, at 4:49 AM, Waltz Jan <jl2862237661@gmail.com> wrote:</div><br class="Apple-interchange-newline"><div><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div style="font-family:Consolas,"Courier New",monospace;font-size:16px;line-height:22px;white-space:pre"><div style=""><span style="color:rgb(0,128,0)">/* Solve J Y = F, where J is Jacobian matrix */</span></div><div style=""><span style="color:rgb(0,16,128)">ierr</span> = <span style="color:rgb(121,94,38)">SNESComputeJacobian</span>(<span style="color:rgb(0,16,128)">snes</span>, <span style="color:rgb(0,16,128)">X</span>, <span style="color:rgb(0,16,128)">snes</span>-><span style="color:rgb(0,16,128)">jacobian</span>, <span style="color:rgb(0,16,128)">snes</span>-><span style="color:rgb(0,16,128)">jacobian_pre</span>);</div><div style=""><span style="color:rgb(0,0,255)">CHKERRQ</span>(<span style="color:rgb(0,16,128)">ierr</span>);</div><div style=""><br></div><div><div style="line-height:22px"><div style=""><span style="color:rgb(38,127,153)">PetscInt</span> <span style="color:rgb(0,16,128)">rstart</span>, <span style="color:rgb(0,16,128)">rend</span>;</div><div style=""><span style="color:rgb(121,94,38)">MatGetOwnershipRange</span>(<span style="color:rgb(0,16,128)">snes</span>-><span style="color:rgb(0,16,128)">jacobian</span>, &<span style="color:rgb(0,16,128)">rstart</span>, &<span style="color:rgb(0,16,128)">rend</span>);</div><div><span style="color:rgb(38,127,153)">PetscInt</span><font> </font><span style="color:rgb(0,16,128)">row</span><font>=</font><font color="#098658">1000</font><font>, </font><span style="color:rgb(0,16,128)">col</span><font>=</font><font color="#098658">1000</font><font>;</font></div><div style=""><span style="color:rgb(38,127,153)">PetscScalar</span> <span style="color:rgb(0,16,128)">v</span>;</div><div style="">if (row>=rstart && row<rend)</div><div style="">{</div><div><span style=""> <span style="color:rgb(121,94,38)">MatGetValues</span>(<span style="color:rgb(0,16,128)">snes</span>-><span style="color:rgb(0,16,128)">jacobian</span>, <span style="color:rgb(9,134,88)">1</span>, </span><font color="#001080">&row</font><font>, </font><span style="color:rgb(9,134,88)">1</span><font>, </font><font color="#001080">&col</font><font>, &</font><span style="color:rgb(0,16,128)">v</span><font>);</font></div><div style=""> <span style="color:rgb(121,94,38)">PetscPrintf</span>(<span style="color:rgb(0,16,128)">PETSC_COMM_WORLD</span>, <span style="color:rgb(163,21,21)">"rstart: </span><span style="color:rgb(0,16,128)">%d</span><span style="color:rgb(163,21,21)">, rend: </span><span style="color:rgb(0,16,128)">%d</span><span style="color:rgb(163,21,21)">, row: </span><span style="color:rgb(0,16,128)">%d</span><span style="color:rgb(163,21,21)">, col: </span><span style="color:rgb(0,16,128)">%d</span><span style="color:rgb(163,21,21)">, v: </span><span style="color:rgb(0,16,128)">%e</span><span style="color:rgb(238,0,0)">\n</span><span style="color:rgb(163,21,21)">"</span>, <span style="color:rgb(0,16,128)">rstart</span>, <span style="color:rgb(0,16,128)">rend</span>, <span style="color:rgb(0,16,128)">row</span>, <span style="color:rgb(0,16,128)">col</span>, <span style="color:rgb(0,16,128)">v</span>);</div></div></div><div style="">}</div><div style=""><br></div><div style=""><span style="color:rgb(15,23,42);font-family:ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,"Noto Sans",sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji";white-space:pre-wrap;background-color:rgb(252,252,252)">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.</span><br></div></div></div></div></div></div>
</div></blockquote></div><br></div></div></div></body></html>