<div dir="ltr"><div dir="ltr">On Tue, Apr 23, 2019 at 9:57 PM Maahi Talukder via petsc-users <<a href="mailto:petsc-users@mcs.anl.gov">petsc-users@mcs.anl.gov</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div dir="ltr">Dear All,<br><div><br></div><div><br></div><div>I am trying to preallocate the no of nonzeros in my matrix using the parameter 'nnz'. Here 'row' is the parameter 'nnz'. The part of the code that does that is the following- </div><div><br></div><div>..........................................................................................................................................................................................</div><div><div><i>Do j = 2,xmax-1</i></div><div><i><br></i></div><div><i>Do i = 2,ymax-1</i></div><div><i><br></i></div><div><i>a = (ymax-2)*(j-2)+i-1-1</i></div><div><i><br></i></div><div><i>If(j.eq.2 .and. i .ge. 3 .and. i .le. (ymax-2))then</i></div><div><i>row(a) = 6</i></div><div><i><br></i></div><div><i>else if (j.eq.(xmax-1) .and. i.ge.3 .and. i .le. (ymax-2)) then</i></div><div><i>row(a) = 6</i></div><div><i><br></i></div><div><i>else if(i.eq.2 .and. j.ge.3 .and. j.le.(xmax-2))then</i></div><div><i>row(a) = 6</i></div><div><i><br></i></div><div><i>else if(i.eq.(ymax-1) .and. j.ge.3 .and. j.le.(xmax-2)) then</i></div><div><i>row(a) = 6</i></div><div><i><br></i></div><div><i>else if(i.eq.2 .and. j.eq.2) then</i></div><div><i>row(a) = 4</i></div><div><i><br></i></div><div><i>else if (i.eq.2 .and. j .eq. (xmax-1)) then</i></div><div><i>row(a)= 4</i></div><div><i><br></i></div><div><i>else if (i.eq.(ymax-1) .and. j .eq. 2) then</i></div><div><i>row(a) = 4</i></div><div><i><br></i></div><div><i>else if (i .eq. (ymax-1) .and. j .eq. (xmax-1)) then</i></div><div><i>row(a) = 4</i></div><div><i><br></i></div><div><i>else</i></div><div><i>row(a) = 9</i></div><div><i><br></i></div><div><i>end if</i></div><div><i><br></i></div><div><i><br></i></div><div><i>end do </i></div><div><i><br></i></div><div><i>end do </i></div><div><i><br></i></div><div><i><br></i></div><div><b><i>call MatCreateSeqAIJ(PETSC_COMM_SELF,N,N,ze,row,Mp,ierr)</i></b></div></div><div><b><br></b></div><div>.................................................................................................................................................................................................</div><div><br></div><div>But I get the following 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: New nonzero at (61,124) caused a malloc</div><div>Use MatSetOption(A, MAT_NEW_NONZERO_ALLOCATION_ERR, PETSC_FALSE) to turn off this check</div><div>[0]PETSC ERROR: See <a href="http://www.mcs.anl.gov/petsc/documentation/faq.html" target="_blank">http://www.mcs.anl.gov/petsc/documentation/faq.html</a> for trouble shooting.</div><div>[0]PETSC ERROR: Petsc Release Version 3.10.2, unknown </div><div>[0]PETSC ERROR: ./Test5 on a arch-opt named CB272PP-THINK1 by maahi Tue Apr 23 21:39:26 2019</div><div>[0]PETSC ERROR: Configure options --with-debugging=0 --download-fblaslapack=1 PETSC_ARCH=arch-opt</div><div>[0]PETSC ERROR: #1 MatSetValues_SeqAIJ() line 481 in /home/maahi/petsc/src/mat/impls/aij/seq/aij.c</div><div>[0]PETSC ERROR: #2 MatSetValues() line 1349 in /home/maahi/petsc/src/mat/interface/matrix.c</div><div>[0]PETSC ERROR: --------------------- Error Message --------------------------------------------------------------</div><div>[0]PETSC ERROR: Argument out of range</div><div>[0]PETSC ERROR: New nonzero at (124,186) caused a malloc</div><div>Use MatSetOption(A, MAT_NEW_NONZERO_ALLOCATION_ERR, PETSC_FALSE) to turn off this check</div><div>[0]PETSC ERROR: See <a href="http://www.mcs.anl.gov/petsc/documentation/faq.html" target="_blank">http://www.mcs.anl.gov/petsc/documentation/faq.html</a> for trouble shooting.</div><div>[0]PETSC ERROR: Petsc Release Version 3.10.2, unknown </div><div>[0]PETSC ERROR: ./Test5 on a arch-opt named CB272PP-THINK1 by maahi Tue Apr 23 21:39:26 2019</div><div>[0]PETSC ERROR: Configure options --with-debugging=0 --download-fblaslapack=1 PETSC_ARCH=arch-opt</div><div>[0]PETSC ERROR: #3 MatSetValues_SeqAIJ() line 481 in /home/maahi/petsc/src/mat/impls/aij/seq/aij.c</div><div>[0]PETSC ERROR: #4 MatSetValues() line 1349 in /home/maahi/petsc/src/mat/interface/matrix.c</div><div>[0]PETSC ERROR: --------------------- Error Message --------------------------------------------------------------</div></div><div>.................................................................................................................................................................................</div><div><br></div><div>But instead of using 'nnz', if I put a upper bound for 'nz', the code works fine.</div><div><br></div><div>Any idea what went wrong?</div></div></div></div></blockquote><div><br></div><div>I am guessing you are not converting to the global row index the same as PETSc.</div><div><br></div><div> Matt</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div>Thanks,</div><div>Maahi Talukder</div><div><br></div></div></div></div>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div>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><br></div><div><a href="http://www.cse.buffalo.edu/~knepley/" target="_blank">https://www.cse.buffalo.edu/~knepley/</a><br></div></div></div></div></div></div></div></div>