<head><!-- BaNnErBlUrFlE-HeAdEr-start -->
<style>
#pfptBannerrlbnvg2 { all: revert !important; display: block !important;
visibility: visible !important; opacity: 1 !important;
background-color: #D0D8DC !important;
max-width: none !important; max-height: none !important }
.pfptPrimaryButtonrlbnvg2:hover, .pfptPrimaryButtonrlbnvg2:focus {
background-color: #b4c1c7 !important; }
.pfptPrimaryButtonrlbnvg2:active {
background-color: #90a4ae !important; }
</style>
<!-- BaNnErBlUrFlE-HeAdEr-end -->
</head><!-- BaNnErBlUrFlE-BoDy-start -->
<!-- Preheader Text : BEGIN -->
<div style="display:none !important;display:none;visibility:hidden;mso-hide:all;font-size:1px;color:#ffffff;line-height:1px;height:0px;max-height:0px;opacity:0;overflow:hidden;">
PETSc version: 3. 20. 4 Program: #include <petscdmda. h> #include <petscsys. h> #include <petscdm. h> #include <petscdmda. h> #include <petscsys. h> #include <petscdm. h> #include <petsc/private/snesimpl. h>int
</div>
<!-- Preheader Text : END -->
<!-- Email Banner : BEGIN -->
<div style="display:none !important;display:none;visibility:hidden;mso-hide:all;font-size:1px;color:#ffffff;line-height:1px;height:0px;max-height:0px;opacity:0;overflow:hidden;">ZjQcmQRYFpfptBannerStart</div>
<!--[if ((ie)|(mso))]>
<table border="0" cellspacing="0" cellpadding="0" width="100%" style="padding: 16px 0px 16px 0px; direction: ltr" ><tr><td>
<table border="0" cellspacing="0" cellpadding="0" style="padding: 0px 10px 5px 6px; width: 100%; border-radius:4px; border-top:4px solid #90a4ae;background-color:#D0D8DC;"><tr><td valign="top">
<table align="left" border="0" cellspacing="0" cellpadding="0" style="padding: 4px 8px 4px 8px">
<tr><td style="color:#000000; font-family: 'Arial', sans-serif; font-weight:bold; font-size:14px; direction: ltr">
This Message Is From an External Sender
</td></tr>
<tr><td style="color:#000000; font-weight:normal; font-family: 'Arial', sans-serif; font-size:12px; direction: ltr">
This message came from outside your organization.
</td></tr>
</table>
</td></tr></table>
</td></tr></table>
<![endif]-->
<![if !((ie)|(mso))]>
<div dir="ltr" id="pfptBannerrlbnvg2" style="all: revert !important; display:block !important; text-align: left !important; margin:16px 0px 16px 0px !important; padding:8px 16px 8px 16px !important; border-radius: 4px !important; min-width: 200px !important; background-color: #D0D8DC !important; background-color: #D0D8DC; border-top: 4px solid #90a4ae !important; border-top: 4px solid #90a4ae;">
<div id="pfptBannerrlbnvg2" style="all: unset !important; float:left !important; display:block !important; margin: 0px 0px 1px 0px !important; max-width: 600px !important;">
<div id="pfptBannerrlbnvg2" style="all: unset !important; display:block !important; visibility: visible !important; background-color: #D0D8DC !important; color:#000000 !important; color:#000000; font-family: 'Arial', sans-serif !important; font-family: 'Arial', sans-serif; font-weight:bold !important; font-weight:bold; font-size:14px !important; line-height:18px !important; line-height:18px">
This Message Is From an External Sender
</div>
<div id="pfptBannerrlbnvg2" style="all: unset !important; display:block !important; visibility: visible !important; background-color: #D0D8DC !important; color:#000000 !important; color:#000000; font-weight:normal; font-family: 'Arial', sans-serif !important; font-family: 'Arial', sans-serif; font-size:12px !important; line-height:18px !important; line-height:18px; margin-top:2px !important;">
This message came from outside your organization.
</div>
</div>
<div style="clear: both !important; display: block !important; visibility: hidden !important; line-height: 0 !important; font-size: 0.01px !important; height: 0px"> </div>
</div>
<![endif]>
<div style="display:none !important;display:none;visibility:hidden;mso-hide:all;font-size:1px;color:#ffffff;line-height:1px;height:0px;max-height:0px;opacity:0;overflow:hidden;">ZjQcmQRYFpfptBannerEnd</div>
<!-- Email Banner : END -->
<!-- BaNnErBlUrFlE-BoDy-end -->
<div dir="ltr">PETSc version: 3.20.4<br>Program:<br><div style="color:rgb(0,0,0);font-family:Consolas,"Courier New",monospace;font-size:16px;line-height:22px;white-space:pre"><div><span style="color:rgb(175,0,219)">#include</span><span style="color:rgb(0,0,255)"> </span><span style="color:rgb(163,21,21)"><petscdmda.h></span></div><div><span style="color:rgb(175,0,219)">#include</span><span style="color:rgb(0,0,255)"> </span><span style="color:rgb(163,21,21)"><petscsys.h></span></div><div><span style="color:rgb(175,0,219)">#include</span><span style="color:rgb(0,0,255)"> </span><span style="color:rgb(163,21,21)"><petscdm.h></span></div><div><span style="color:rgb(175,0,219)">#include</span><span style="color:rgb(0,0,255)"> </span><span style="color:rgb(163,21,21)"><petscdmda.h></span></div><div><span style="color:rgb(175,0,219)">#include</span><span style="color:rgb(0,0,255)"> </span><span style="color:rgb(163,21,21)"><petscsys.h></span></div><div><span style="color:rgb(175,0,219)">#include</span><span style="color:rgb(0,0,255)"> </span><span style="color:rgb(163,21,21)"><petscdm.h></span></div><div><span style="color:rgb(175,0,219)">#include</span><span style="color:rgb(0,0,255)"> </span><span style="color:rgb(163,21,21)"><petsc/private/snesimpl.h></span></div><br><div><span style="color:rgb(0,0,255)">int</span> <span style="color:rgb(121,94,38)">main</span>()</div><div>{</div><div> <span style="color:rgb(121,94,38)">PetscInitialize</span>(<span style="color:rgb(0,0,255)">NULL</span>, <span style="color:rgb(0,0,255)">NULL</span>, <span style="color:rgb(0,0,255)">NULL</span>, <span style="color:rgb(0,0,255)">NULL</span>);</div><div> <span style="color:rgb(0,0,255)">DM</span> da;</div><div> <span style="color:rgb(121,94,38)">DMDACreate3d</span>(PETSC_COMM_WORLD, DM_BOUNDARY_GHOSTED, DM_BOUNDARY_GHOSTED, DM_BOUNDARY_GHOSTED, DMDA_STENCIL_STAR,</div><div> <span style="color:rgb(9,134,88)">10</span>, <span style="color:rgb(9,134,88)">1</span>, <span style="color:rgb(9,134,88)">10</span>, PETSC_DECIDE, PETSC_DECIDE, PETSC_DECIDE, <span style="color:rgb(9,134,88)">3</span>, <span style="color:rgb(9,134,88)">1</span>, <span style="color:rgb(0,0,255)">NULL</span>, <span style="color:rgb(0,0,255)">NULL</span>, <span style="color:rgb(0,0,255)">NULL</span>, &da);</div><div> <span style="color:rgb(121,94,38)">DMSetFromOptions</span>(da);</div><div> <span style="color:rgb(121,94,38)">DMSetUp</span>(da);</div><div> <span style="color:rgb(0,0,255)">Mat</span> Jac;</div><div> <span style="color:rgb(121,94,38)">DMCreateMatrix</span>(da, &Jac);</div><div> <span style="color:rgb(0,0,255)">int</span> <span style="color:rgb(0,16,128)">row</span> = <span style="color:rgb(9,134,88)">100</span>, <span style="color:rgb(0,16,128)">col</span> = <span style="color:rgb(9,134,88)">100</span>;</div><div> <span style="color:rgb(0,0,255)">double</span> <span style="color:rgb(0,16,128)">val</span> = <span style="color:rgb(9,134,88)">1.</span>;</div><div> <span style="color:rgb(121,94,38)">MatSetValues</span>(Jac, <span style="color:rgb(9,134,88)">1</span>, &<span style="color:rgb(0,16,128)">row</span>, <span style="color:rgb(9,134,88)">1</span>, &<span style="color:rgb(0,16,128)">col</span>, &<span style="color:rgb(0,16,128)">val</span>, INSERT_VALUES);</div><div> <span style="color:rgb(121,94,38)">MatAssemblyBegin</span>(Jac, <span style="color:rgb(0,112,193)">MAT_FINAL_ASSEMBLY</span>);</div><div> <span style="color:rgb(121,94,38)">MatAssemblyEnd</span>(Jac, <span style="color:rgb(0,112,193)">MAT_FINAL_ASSEMBLY</span>);</div><br><div> <span style="color:rgb(0,0,255)">PetscViewer</span> viewer;</div><div> <span style="color:rgb(121,94,38)">PetscViewerASCIIOpen</span>(PETSC_COMM_WORLD, <span style="color:rgb(163,21,21)">"./jacobianmatrix.m"</span>, &viewer);</div><div> <span style="color:rgb(121,94,38)">PetscViewerPushFormat</span>(viewer, PETSC_VIEWER_ASCII_MATLAB);</div><div> <span style="color:rgb(121,94,38)">MatView</span>(Jac, viewer);</div><div> <span style="color:rgb(121,94,38)">PetscViewerDestroy</span>(&viewer);</div><br><div> <span style="color:rgb(121,94,38)">PetscFinalize</span>();</div><div>}
When I ran the program with np = 6, I got the result as the below
<img src="cid:ii_ltwwf6520" alt="image.png" width="451" height="542"><br>It's obviously wrong.
When I ran the program with np = 1 or 8, I got the right result as
<img src="cid:ii_ltwwgzjg1" alt="image.png" width="452" height="542"><br>
</div></div></div>