<div dir="ltr">On Fri, Sep 27, 2013 at 11:00 AM, Lulu Liu <span dir="ltr"><<a href="mailto:lulu.liu@kaust.edu.sa" target="_blank">lulu.liu@kaust.edu.sa</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Try to build analytical <span>Jacobian</span> with 4 blocks, I modify the code <span>src</span>/<span>snes</span>/examples/tutorials/ex28.c (1D problem, however, my problem is 2D). When building one block of <span>Jacobian</span>, I got the errors like this:<br>

</div><div>0]<span>PETSC</span> ERROR: --------------------- Error Message ------------------------------------</div><div>[0]<span>PETSC</span> ERROR: Argument out of range!</div><div>[0]<span>PETSC</span> ERROR: New nonzero at (28,58) caused a <span>malloc</span>!</div>

<div>[0]<span>PETSC</span> ERROR: <span>MatSetValues</span>_<span>SeqAIJ</span>() line 353 in <span>src</span>/mat/<span>impls</span>/<span>aij</span>/seq/<span>aij</span>.c</div>
<div>[0]<span>PETSC</span> ERROR: <span>MatSetValues</span>() line 1124 in <span>src</span>/mat/interface/matrix.c</div><div>[0]<span>PETSC</span> ERROR: <span>MatSetValuesLocal</span>() line 2012 in <span>src</span>/mat/interface/matrix.c</div>

<div>[0]<span>PETSC</span> ERROR: <span>FormJacobianLocal</span>_P() line 556 in /Users/<span>liul</span>/Desktop/FieldSplitcase2.c</div><div>[0]<span>PETSC</span> ERROR: <span>FormJacobian</span>_All() line 847 in /Users/<span>liul</span>/Desktop/FieldSplitcase2.c</div>

<div>[0]<span>PETSC</span> ERROR: <span>SNESComputeJacobian</span>() line 2227 in <span>src</span>/<span>snes</span>/interface/<span>snes</span>.c</div>
<div>[0]<span>PETSC</span> ERROR: <span>SNESSolve</span>_<span>NEWTONLS</span>() line 233 in <span>src</span>/<span>snes</span>/<span>impls</span>/ls/ls.c</div>
<div>[0]<span>PETSC</span> ERROR: <span>SNESSolve</span>() line 3789 in <span>src</span>/<span>snes</span>/interface/<span>snes</span>.c</div><div>
[0]<span>PETSC</span> ERROR: main() line 1062 in /Users/<span>liul</span>/Desktop/FieldSplitcase2.c</div><div>application called <span>MPI</span>_Abort(<span>MPI</span>_COMM_WORLD, 63) - process 0</div>
<div>[unset]: aborting job:</div><div>application called <span>MPI</span>_Abort(<span>MPI</span>_COMM_WORLD, 63) - process 0  </div></div></blockquote><div><br></div><div>1) Obviously your index calculation is off somewhere</div>
<div><br></div><div>2) This is exactly why we introduced the FormFunctionLocal() where you get multi-dimensional arrays</div><div>     and out of range access is obvious. Why are you not using that?</div><div><br></div><div>
  Matt</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>I think that I am not call <span>MatSetValuesLocal</span> correctly, right? How to fix it? Thanks!</div>

<div>for (j=<span>yints</span>; j<<span>yinte</span>; j++) {<br></div><div><div>    for (i=<span>xints</span>; i<<span>xinte</span>; i++) {</div><div> //        row.i = i; row.j = j;</div>
<div>           row = i+j*info-><span>xm</span>;</div><div><br></div><div>           if (i==0 || j==0 || i==<span>mx</span>-1 || j==my-1) {</div><div>          <span>num</span> = 0; v_l=0.0; v_r=0.0; v_t=0.0; v_b=0.0;</div>

<div>          if (j!=0) {</div><div>            v=-1;v_b=1;</div><div>            J=row-info-><span>xm</span>;              </div><div>            <span>ierr</span> = <span>MatSetValuesLocal</span>(<span>Bpp</span>,1,&row,1,&J,&v,INSERT_VALUES);<span>CHKERRQ</span>(<span>ierr</span>);               </div>

<div>          }</div><div>          if (i!=0) {</div><div>            v = -1; v_l=1;</div><div>            J=row-1; </div><div>            <span>ierr</span> = <span>MatSetValuesLocal</span>(<span>Bpp</span>,1,&row,1,&J,&v,INSERT_VALUES);<span>CHKERRQ</span>(<span>ierr</span>);  </div>

<div>            </div><div>          }</div><div>          if (i!=<span>mx</span>-1) {</div><div>            v = -1;v_r=1;</div><div>            J=row+1;      </div><div>            <span>ierr</span> = <span>MatSetValuesLocal</span>(<span>Bpp</span>,1,&row,1,&J,&v,INSERT_VALUES);<span>CHKERRQ</span>(<span>ierr</span>);            </div>

<div>          }</div><div>          if (j!=my-1) {   </div><div>            v = -1;v_t=1;</div><div>             J=row+info-><span>xm</span>;</div><div>            <span>ierr</span> = <span>MatSetValuesLocal</span>(<span>Bpp</span>,1,&row,1,&J,&v,INSERT_VALUES);<span>CHKERRQ</span>(<span>ierr</span>);            </div>

<div>          }</div><div>          v   = v_l+v_r+v_t+v_b;</div><div><br></div><div>         if(i==0&&j==0){ v+=2;}</div><div>          J=row;</div><div>         <span>ierr</span> = <span>MatSetValuesLocal</span>(<span>Bpp</span>,1,&row,1,&J,&v,INSERT_VALUES);<span>CHKERRQ</span>(<span>ierr</span>);</div>

<div>         }else{</div><div>  </div><div>          <span>PetscInt</span> cols[]={row-info-><span>xm</span>,row-1,row+1,row+info-><span>xm</span>,row};</div><div>          <span>PetscScalar</span> <span>vals</span>[]= {-1,-1,-1,-1,4};</div>

<div>          <span>ierr</span> = <span>MatSetValuesLocal</span>(<span>Bpp</span>,1,&row,5,cols,<span>vals</span>,INSERT_VALUES);<span>CHKERRQ</span>(<span>ierr</span>);  </div>
<div><br></div><div>         }</div><div>      </div><div>    }</div><div>  }</div></div><div><br></div><div><br></div><br>
</div>

<br>
<div><hr></div><font face="Arial" size="1">This message and its contents, including attachments are intended solely for the original recipient. If you are not the intended recipient or have received this message in error, please notify me immediately and delete this message from your computer system. Any unauthorized use or distribution is prohibited. Please consider the environment before printing this email.</font></blockquote>
</div><br><br clear="all"><div><br></div>-- <br>What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>-- Norbert Wiener
</div></div>