<!-- 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;">
On Mar 18, 2024, at 9: 41 PM, Waltz Jan <jl2862237661@ gmail. com> wrote: Thank you for your response. However, even after reading the Notes in https: //petsc. org/release/manualpages/DM/DMCreateMatrix/, I am still confused. According to the
</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="pfptBanner32zpgs4" 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="pfptBanner32zpgs4" style="all: unset !important; float:left !important; display:block !important; margin: 0px 0px 1px 0px !important; max-width: 600px !important;">
<div id="pfptBanner32zpgs4" 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="pfptBanner32zpgs4" 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 -->
<html><head><!-- BaNnErBlUrFlE-HeAdEr-start -->
<style>
#pfptBanner32zpgs4 { all: revert !important; display: block !important;
visibility: visible !important; opacity: 1 !important;
background-color: #D0D8DC !important;
max-width: none !important; max-height: none !important }
.pfptPrimaryButton32zpgs4:hover, .pfptPrimaryButton32zpgs4:focus {
background-color: #b4c1c7 !important; }
.pfptPrimaryButton32zpgs4:active {
background-color: #90a4ae !important; }
</style>
<!-- BaNnErBlUrFlE-HeAdEr-end -->
<meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body style="overflow-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><div><br></div><div><div><div><div><br><blockquote type="cite"><div>On Mar 18, 2024, at 9:41 PM, Waltz Jan <jl2862237661@gmail.com> wrote:</div><br class="Apple-interchange-newline"><div><div dir="ltr"><div style="outline-color: rgba(34, 197, 94, 0.533); border: 0px solid rgb(229, 231, 235); box-sizing: border-box; margin: 0.25rem 0px; 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"; font-size: 15px; background-color: rgb(245, 245, 245);">Thank you for your response. <br>However, even after reading the Notes in <a href="https://urldefense.us/v3/__https://petsc.org/release/manualpages/DM/DMCreateMatrix/__;!!G_uCfscf7eWS!fTO1ShsqXrxcXKmKrn7uXjX68PlSaKv4RBgRvwP9BUQpeowdAqyQyxq3cSp_3H231u74LG5cJRd24lnABMYgziE$" style="outline-color:rgba(34,197,94,0.533);border:0px solid rgb(229,231,235);box-sizing:border-box;text-decoration:inherit">https://petsc.org/release/manualpages/DM/DMCreateMatrix/</a>, I am still confused.</div><div style="outline-color: rgba(34, 197, 94, 0.533); border: 0px solid rgb(229, 231, 235); box-sizing: border-box; margin: 0.25rem 0px; 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"; font-size: 15px; background-color: rgb(245, 245, 245);">According to the content in <a href="https://urldefense.us/v3/__https://petsc.org/release/manualpages/Mat/MatSetValues/__;!!G_uCfscf7eWS!fTO1ShsqXrxcXKmKrn7uXjX68PlSaKv4RBgRvwP9BUQpeowdAqyQyxq3cSp_3H231u74LG5cJRd24lnAAfForB0$" style="outline-color:rgba(34,197,94,0.533);border:0px solid rgb(229,231,235);box-sizing:border-box;text-decoration:inherit">https://petsc.org/release/manualpages/Mat/MatSetValues/</a>, idxm and idxn represent the global indices of the rows and columns, respectively. I created a matrix using DMDA with a size of 300x300, and I want to insert a value at the 101st row and 101st column. Shouldn't idxm and idxn be 100 in this case? </div></div></div></blockquote><div><br></div><div> It does go into the matrix at I,J of 101 and 101. But MatView() when the matrix comes from a DMDA prints the matrix out with a different ordering (the "natural" ordering for a 2 or 3d grid) thus printed out it is not at the 101, 101 location. </div><div><br></div><div> If you do PetscViewerPushFormat(viewer, PETSC_VIEWER_NATIVE); before calling MatView() then MatView will not print the matrix out in natural order, it will print it out as it is stored in parallel and you will see the location at 101, 101. </div><div><br></div><br><blockquote type="cite"><div><div dir="ltr"><div style="outline-color: rgba(34, 197, 94, 0.533); border: 0px solid rgb(229, 231, 235); box-sizing: border-box; margin: 0.25rem 0px; 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"; font-size: 15px; background-color: rgb(245, 245, 245);"> But when NP=6, the inserted value appears at a different position. <br><br></div></div></div></blockquote> MatSetValuesStencil() allows each process to set entries for its points.<span style="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"; font-size: 15px; background-color: rgb(245, 245, 245);"> You can use </span>DMDAGetGhostCorners() to determine the allowed range of i,j,k that can be used in the MatStencil for each particular MPI process. See for example src/snes/tests/ex20.c the function FormJacobian(). It is for finite difference matrices where points only speak to their neighbors in the matrix. It does not support setting arbitrary I, J locations into a matrix from arbitrary processes.</div><div><br></div><div><br><blockquote type="cite"><div><div dir="ltr"><div style="outline-color: rgba(34, 197, 94, 0.533); border: 0px solid rgb(229, 231, 235); box-sizing: border-box; margin: 0.25rem 0px; 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"; font-size: 15px; background-color: rgb(245, 245, 245);">I tried using MatSetValuesStencil, but the code threw an error with the following message:</div><div style="outline-color: rgba(34, 197, 94, 0.533); border: 0px solid rgb(229, 231, 235); box-sizing: border-box; margin: 0.25rem 0px; 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"; font-size: 15px; background-color: rgb(245, 245, 245);">CODES:</div><div style="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><br><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><br><div> <span style="color:rgb(0,0,255)">MatStencil</span> st{<span style="color:rgb(9,134,88)">5</span>,<span style="color:rgb(9,134,88)">1</span>,<span style="color:rgb(9,134,88)">5</span>,<span style="color:rgb(9,134,88)">0</span>};</div><div> <span style="color:rgb(121,94,38)">MatSetValuesStencil</span>(Jac, <span style="color:rgb(9,134,88)">1</span>, &st, <span style="color:rgb(9,134,88)">1</span>, &st, &<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>}</div></div><div style="outline-color: rgba(34, 197, 94, 0.533); border: 0px solid rgb(229, 231, 235); box-sizing: border-box; margin: 0.25rem 0px; 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"; font-size: 15px; background-color: rgb(245, 245, 245);"><br></div><div style="outline-color: rgba(34, 197, 94, 0.533); border: 0px solid rgb(229, 231, 235); box-sizing: border-box; margin: 0.25rem 0px; 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"; font-size: 15px; background-color: rgb(245, 245, 245);">[0]PETSC ERROR: --------------------- Error Message --------------------------------------------------------------<br>[0]PETSC ERROR: Argument out of range<br>[0]PETSC ERROR: Local index 438 too large 377 (max) at 0<br>[0]PETSC ERROR: See <a href="https://urldefense.us/v3/__https://petsc.org/release/faq/__;!!G_uCfscf7eWS!fTO1ShsqXrxcXKmKrn7uXjX68PlSaKv4RBgRvwP9BUQpeowdAqyQyxq3cSp_3H231u74LG5cJRd24lnAY72xwtI$">https://petsc.org/release/faq/</a> for trouble shooting.<br>[0]PETSC ERROR: Petsc Release Version 3.20.4, Jan 29, 2024 <br>[0]PETSC ERROR: Unknown Name on a arch-linux-cxx-debug named TUF-Gaming by lei Tue Mar 19 09:31:01 2024<br>[0]PETSC ERROR: Configure options --with-cc=gcc --with-cxx=g++ --with-fc=gfortran --download-fblaslapack --download-hypre --with-debugging=yes --download-mpich --with-clanguage=cxx<br>[0]PETSC ERROR: #1 ISLocalToGlobalMappingApply() at /home/lei/Software/PETSc/petsc-3.20.4/src/vec/is/utils/isltog.c:789<br>[0]PETSC ERROR: #2 MatSetValuesLocal() at /home/lei/Software/PETSc/petsc-3.20.4/src/mat/interface/matrix.c:2408<br>[0]PETSC ERROR: #3 MatSetValuesStencil() at /home/lei/Software/PETSc/petsc-3.20.4/src/mat/interface/matrix.c:1762<br>[1]PETSC ERROR: --------------------- Error Message --------------------------------------------------------------<br>[1]PETSC ERROR: Argument out of range<br>[1]PETSC ERROR: Local index 423 too large 377 (max) at 0<br>[1]PETSC ERROR: See <a href="https://urldefense.us/v3/__https://petsc.org/release/faq/__;!!G_uCfscf7eWS!fTO1ShsqXrxcXKmKrn7uXjX68PlSaKv4RBgRvwP9BUQpeowdAqyQyxq3cSp_3H231u74LG5cJRd24lnAY72xwtI$">https://petsc.org/release/faq/</a> for trouble shooting.<br>[1]PETSC ERROR: Petsc Release Version 3.20.4, Jan 29, 2024 <br>[1]PETSC ERROR: Unknown Name on a arch-linux-cxx-debug named TUF-Gaming by lei Tue Mar 19 09:31:01 2024<br>[1]PETSC ERROR: Configure options --with-cc=gcc --with-cxx=g++ --with-fc=gfortran --download-fblaslapack --download-hypre --with-debugging=yes --download-mpich --with-clanguage=cxx<br>[1]PETSC ERROR: #1 ISLocalToGlobalMappingApply() at /home/lei/Software/PETSc/petsc-3.20.4/src/vec/is/utils/isltog.c:789<br>[1]PETSC ERROR: #2 MatSetValuesLocal() at /home/lei/Software/PETSc/petsc-3.20.4/src/mat/interface/matrix.c:2408<br>[1]PETSC ERROR: #3 MatSetValuesStencil() at /home/lei/Software/PETSc/petsc-3.20.4/src/mat/interface/matrix.c:1762</div><div style="outline-color: rgba(34, 197, 94, 0.533); border: 0px solid rgb(229, 231, 235); box-sizing: border-box; margin: 0.25rem 0px; 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"; font-size: 15px; background-color: rgb(245, 245, 245);"><br></div><div style="outline-color: rgba(34, 197, 94, 0.533); border: 0px solid rgb(229, 231, 235); box-sizing: border-box; margin: 0.25rem 0px; 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"; font-size: 15px; background-color: rgb(245, 245, 245);">Is it not possible to set values across processors using MatSetValuesStencil? If I want to set values of the matrix across processors, what should I do? <br>I am really confused, and I would greatly appreciate your help.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Mar 18, 2024 at 9:28 PM Barry Smith <<a href="mailto:bsmith@petsc.dev">bsmith@petsc.dev</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div><br></div> The output is correct (only confusing). For PETSc DMDA by default viewing a parallel matrix converts it to the "natural" ordering instead of the PETSc parallel ordering.<div><br></div><div> See the Notes in <a href="https://urldefense.us/v3/__https://petsc.org/release/manualpages/DM/DMCreateMatrix/__;!!G_uCfscf7eWS!fTO1ShsqXrxcXKmKrn7uXjX68PlSaKv4RBgRvwP9BUQpeowdAqyQyxq3cSp_3H231u74LG5cJRd24lnABMYgziE$" target="_blank">https://petsc.org/release/manualpages/DM/DMCreateMatrix/</a></div><div><br></div><div> Barry</div><div><br id="m_-6939064004502860608lineBreakAtBeginningOfMessage"><div><br><blockquote type="cite"><div>On Mar 18, 2024, at 8:06 AM, Waltz Jan <<a href="mailto:jl2862237661@gmail.com" target="_blank">jl2862237661@gmail.com</a>> wrote:</div><br><div><div dir="ltr" id="m_-6939064004502860608pfptBannerrlbnvg2" style="writing-mode:revert;color:revert;font-family:revert;font-feature-settings:revert;font-kerning:revert;font-size:revert;font-stretch:revert;font-variant-alternates:revert;font-variant-caps:revert;font-variant-east-asian:revert;font-variant-ligatures:revert;font-variant-numeric:revert;font-weight:revert;text-orientation:revert;zoom:revert;letter-spacing:revert;background-blend-mode:revert;background-image:revert;background-position:revert;background-repeat:revert;background-size:revert;border-collapse:revert;box-sizing:revert;break-after:revert;break-before:revert;break-inside:revert;caption-side:revert;clear:revert;columns:revert;column-fill:revert;column-gap:revert;column-rule:revert;column-span:revert;empty-cells:revert;float:revert;image-orientation:revert;isolation:revert;line-break:revert;line-height:revert;list-style:revert;mix-blend-mode:revert;object-fit:revert;object-position:revert;outline:revert;overflow:revert;quotes:revert;table-layout:revert;text-align:left;text-align-last:revert;text-decoration:revert;text-emphasis:revert;text-indent:revert;text-overflow:revert;text-transform:revert;text-underline-position:revert;white-space:revert;vertical-align:revert;word-break:revert;word-spacing:revert;border-spacing:revert;background-clip:revert;background-origin:revert;text-combine-upright:revert;display:block;opacity:revert;background-color:rgb(208,216,220);border-bottom:revert;border-left:revert;border-right:revert;height:revert;max-height:revert;max-width:revert;min-height:revert;width:revert;margin:16px 0px;padding:8px 16px;border-radius:4px;min-width:200px;border-top:4px solid rgb(144,164,174)"><div id="m_-6939064004502860608pfptBannerrlbnvg2" style="writing-mode:unset;color:unset;font-family:unset;font-feature-settings:unset;font-kerning:unset;font-size:unset;font-stretch:unset;font-variant-alternates:unset;font-variant-caps:unset;font-variant-east-asian:unset;font-variant-ligatures:unset;font-variant-numeric:unset;font-weight:unset;text-orientation:unset;zoom:unset;letter-spacing:unset;background:unset;background-blend-mode:unset;border-collapse:unset;border:unset;box-sizing:unset;break-after:unset;break-before:unset;break-inside:unset;caption-side:unset;clear:unset;columns:unset;column-fill:unset;column-gap:unset;column-rule:unset;column-span:unset;empty-cells:unset;float:left;image-orientation:unset;isolation:unset;line-break:unset;line-height:unset;list-style:unset;mix-blend-mode:unset;object-fit:unset;object-position:unset;outline:unset;overflow:unset;quotes:unset;table-layout:unset;text-align:unset;text-align-last:unset;text-decoration:unset;text-emphasis:unset;text-indent:unset;text-overflow:unset;text-transform:unset;text-underline-position:unset;white-space:unset;vertical-align:unset;word-break:unset;word-spacing:unset;border-spacing:unset;text-combine-upright:unset;display:block;opacity:unset;border-radius:unset;height:unset;max-height:unset;min-height:unset;min-width:unset;padding:unset;width:unset;margin:0px 0px 1px;max-width:600px"><div id="m_-6939064004502860608pfptBannerrlbnvg2" style="writing-mode:unset;font-family:Arial,sans-serif;font-feature-settings:unset;font-kerning:unset;font-size:14px;font-stretch:unset;font-variant-alternates:unset;font-variant-caps:unset;font-variant-east-asian:unset;font-variant-ligatures:unset;font-variant-numeric:unset;font-weight:bold;text-orientation:unset;zoom:unset;letter-spacing:unset;background-blend-mode:unset;background-image:unset;background-position:unset;background-repeat:unset;background-size:unset;border-collapse:unset;border:unset;box-sizing:unset;break-after:unset;break-before:unset;break-inside:unset;caption-side:unset;clear:unset;columns:unset;column-fill:unset;column-gap:unset;column-rule:unset;column-span:unset;empty-cells:unset;float:unset;image-orientation:unset;isolation:unset;line-break:unset;line-height:18px;list-style:unset;mix-blend-mode:unset;object-fit:unset;object-position:unset;outline:unset;overflow:unset;quotes:unset;table-layout:unset;text-align:unset;text-align-last:unset;text-decoration:unset;text-emphasis:unset;text-indent:unset;text-overflow:unset;text-transform:unset;text-underline-position:unset;white-space:unset;vertical-align:unset;word-break:unset;word-spacing:unset;border-spacing:unset;background-clip:unset;background-origin:unset;text-combine-upright:unset;display:block;opacity:unset;background-color:rgb(208,216,220);border-radius:unset;height:unset;margin:unset;max-height:unset;max-width:unset;min-height:unset;min-width:unset;padding:unset;width:unset">This Message Is From an External Sender</div><div id="m_-6939064004502860608pfptBannerrlbnvg2" style="writing-mode:unset;font-family:Arial,sans-serif;font-feature-settings:unset;font-kerning:unset;font-size:12px;font-stretch:unset;font-variant-alternates:unset;font-variant-caps:unset;font-variant-east-asian:unset;font-variant-ligatures:unset;font-variant-numeric:unset;font-weight:unset;text-orientation:unset;zoom:unset;letter-spacing:unset;background-blend-mode:unset;background-image:unset;background-position:unset;background-repeat:unset;background-size:unset;border-collapse:unset;border:unset;box-sizing:unset;break-after:unset;break-before:unset;break-inside:unset;caption-side:unset;clear:unset;columns:unset;column-fill:unset;column-gap:unset;column-rule:unset;column-span:unset;empty-cells:unset;float:unset;image-orientation:unset;isolation:unset;line-break:unset;line-height:18px;list-style:unset;mix-blend-mode:unset;object-fit:unset;object-position:unset;outline:unset;overflow:unset;quotes:unset;table-layout:unset;text-align:unset;text-align-last:unset;text-decoration:unset;text-emphasis:unset;text-indent:unset;text-overflow:unset;text-transform:unset;text-underline-position:unset;white-space:unset;vertical-align:unset;word-break:unset;word-spacing:unset;border-spacing:unset;background-clip:unset;background-origin:unset;text-combine-upright:unset;display:block;opacity:unset;background-color:rgb(208,216,220);border-radius:unset;height:unset;margin-bottom:unset;margin-left:unset;margin-right:unset;max-height:unset;max-width:unset;min-height:unset;min-width:unset;padding:unset;width:unset;margin-top:2px">This message came from outside your organization.</div></div><div style="height:0px;clear:both;display:block;line-height:0;font-size:0.01px"></div></div><div dir="ltr" style="font-family:Helvetica;font-size:18px;font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none">PETSc version: 3.20.4<br>Program:<br><div style="font-family:Consolas,"Courier New",monospace;font-size:16px;line-height:22px;white-space:pre-wrap"><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
<span id="m_-6939064004502860608cid:ii_ltwwf6520"><image.png></span><br>It's obviously wrong.
When I ran the program with np = 1 or 8, I got the right result as
<span id="m_-6939064004502860608cid:ii_ltwwgzjg1"><image.png></span></div></div></div></div></blockquote></div><br></div></div></blockquote></div>
</div></blockquote></div><br></div></div></div></body></html>