<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<p>Hi Hong,</p>
<p>Thank you that was unclear to me, now I understand its purpose!</p>
<p>Thibaut<br>
</p>
<div class="moz-cite-prefix">On 08/10/2019 16:18, Zhang, Hong wrote:<br>
</div>
<blockquote type="cite"
cite="mid:CAGCphBukG=Vm9+hbxWVGZOgQOD1dGcV2zCbvZ9Vi0Kwco0Uxwg@mail.gmail.com">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<div dir="ltr">
<div dir="ltr">Thibaut :<br>
</div>
<div>Sorry, I did not explain it clearly. You call </div>
<div>MatSetOption(A,MAT_NEW_NONZERO_LOCATION_ERR,PETSC_TRUE);<br>
</div>
<div>AFTER matrix is assembled. Then no more new zero is allowed
to add/insert. For example, I add following in</div>
<div>petsc/src/ksp/ksp/examples/tutorials/ex1.c:<br>
</div>
<div><br>
ierr =
MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);<br>
ierr = MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);<br>
<br>
+ ierr =
MatSetOption(A,MAT_NEW_NONZERO_LOCATION_ERR,PETSC_TRUE);CHKERRQ(ierr);<br>
+ i = 0; col[0] = 2; <br>
+ ierr =
MatSetValues(A,1,&i,2,col,value,INSERT_VALUES);CHKERRQ(ierr);<br>
+ ierr =
MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);<br>
+ ierr = MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);<br>
+<br>
</div>
<div>Then the code crashes with</div>
<div>0]PETSC ERROR: Argument out of range<br>
[0]PETSC ERROR: Inserting a new nonzero at (0,2) in the
matrix.<br>
</div>
<div><br>
</div>
<div>Adding entries to the tridiagonal works. </div>
<div>Hong</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 bgcolor="#FFFFFF">
<p>Well, try and create a small SEQAIJ/MPIAIJ matrix and
preallocate memory for the diagonal.<br>
</p>
<p>When I try to call MatSetValues to fill the diagonal,
on the first row I get <br>
</p>
<p>[0]PETSC ERROR: Argument out of range<br>
[0]PETSC ERROR: Inserting a new nonzero at (0,0) in the
matrix</p>
<p>Which is within my preallocated non-zero structure.</p>
<p>This is why I'm confused.<br>
</p>
<p>Thibaut</p>
<p><br>
</p>
<div>On 08/10/2019 15:31, Zhang, Hong wrote:<br>
</div>
<blockquote type="cite">
<div dir="ltr">
<div dir="ltr">Thibaut:<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">
Hi,<br>
<br>
Just out of curiosity, I'm a bit confused by the
parameter option <br>
MAT_NEW_NONZERO_LOCATION_ERR.<br>
<br>
It triggers an error if you try to insert/add a
value in the non-zero <br>
structure, regardless of the matrix preallocation
status. In what case </blockquote>
<blockquote class="gmail_quote" style="margin:0px
0px 0px 0.8ex;border-left:1px solid
rgb(204,204,204);padding-left:1ex">
would such an option be useful?<br>
</blockquote>
<div> </div>
<div> It triggers an error if you try to insert/add
a NEW value outside of your preallocated non-zero
structure.</div>
<div>Hong</div>
<blockquote class="gmail_quote" style="margin:0px
0px 0px 0.8ex;border-left:1px solid
rgb(204,204,204);padding-left:1ex">
<br>
</blockquote>
</div>
</div>
</blockquote>
</div>
</blockquote>
</div>
</div>
</blockquote>
</body>
</html>