<div dir="ltr">Hello everyone,<div><br></div><div>I have a question on setting matrix entries which are not in the stencil width. Take ksp ex45.c as an example, </div><div><a href="http://www.mcs.anl.gov/petsc/petsc-current/src/ksp/ksp/examples/tutorials/ex45.c.html">http://www.mcs.anl.gov/petsc/petsc-current/src/ksp/ksp/examples/tutorials/ex45.c.html</a></div><div><br></div><div>Instead of setting up the standard 7-point stencil, now for each cell, the matrix also has a additional dependency on the cell (Mx, My, Mz). Namely, for each row, the col corresponding to (Mx, My, Mz) is always nonzero. I modify the example code to add this entries:</div><div><br></div><div><div>+  MatSetOption(B,MAT_NEW_NONZERO_LOCATIONS,PETSC_TRUE);</div><div>+  MatSetOption(jac,MAT_NEW_NONZERO_LOCATIONS,PETSC_TRUE);</div></div><div><br></div><div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">   </span>  v[7] = 100; col[7].i = mx-1; col[7].j = my-1; col[7].k = mz-1;</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">     </span>  ierr = MatSetValuesStencil(B,1,&row,8,col,v,INSERT_VALUES);CHKERRQ(ierr);</div></div><div><br></div><div>It is okay to for np=1, but crash for np>=2 with the error message:</div><div><br></div><div><div>[0]PETSC ERROR: --------------------- Error Message --------------------------------------------------------------</div><div>[0]PETSC ERROR: Argument out of range</div><div>[0]PETSC ERROR: Local index 342 too large 244 (max) at 7</div></div><div><br></div><div><div>[0]PETSC ERROR: #1 ISLocalToGlobalMappingApply() line 423 in petsc-3.7.4/src/vec/is/utils/isltog.c</div><div>[0]PETSC ERROR: #2 MatSetValuesLocal() line 2052 in petsc-3.7.4/src/mat/interface/matrix.c</div><div>[0]PETSC ERROR: #3 MatSetValuesStencil() line 1447 in petsc-3.7.4/src/mat/interface/matrix.c</div><div>[0]PETSC ERROR: #4 ComputeMatrix() line 151 in extest.c</div></div><div><br></div><div>Can I add new entries to the cols not in the stencil width into the dmda matrix or Jacobian?</div><div><br></div><div>Attached please find the modifed ex45 example, the diff file as well as the run log.</div><div><br></div><div>Thanks for your help.</div><div><br></div><div>Best,</div><div>Xiangdong</div><div><br></div></div>