<div dir="ltr">This may help in this situation. <a href="http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatResetPreallocation.html">http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatResetPreallocation.html</a><div><br></div><div><br></div><div>Fande,</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jun 14, 2018 at 1:08 PM, Smith, Barry F. <span dir="ltr"><<a href="mailto:bsmith@mcs.anl.gov" target="_blank">bsmith@mcs.anl.gov</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
I am guessing your matrix has an "envelope" of nonzero values but the first time you fill the matrix you do not fill up the entire envelope? Hence internally within the matrix we squeeze out those nonexistent locations so next time you fill the matrix the new location you need is not available.<br>
<br>
There is really only one way to deal with this. Initially build the entire envelope of values (putting zeros in certain locations is fine they won't get squuzed out) then for future calls the locations are already there and so you will have no problems with new nonzero.<br>
<br>
On the other hand if the envelope is much much larger than any particular set of nonzero locations then it is better to create a new matrix each time because all the solves with the first approach treats all the matrix entries in the envelope as nonzero (even if they happen to be zero).<br>
<span class="HOEnZb"><font color="#888888"><br>
Barry<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
<br>
> On Jun 14, 2018, at 1:17 PM, Qicang Shen <<a href="mailto:qicangsh@umich.edu">qicangsh@umich.edu</a>> wrote:<br>
> <br>
> Hi Guys,<br>
> <br>
> I'm now confronting a problem.<br>
> <br>
> I'm using PETSC to construct a SPARSE Matrix. And I'm sure that the matrix has been allocated correctly using MatMPIAIJSetPreallocation with the upper limit of the size.<br>
> <br>
> The code works well when I just solve the system once.<br>
> <br>
> However, after the system been solved. And I want to use the original non-zero structure, but change the elements inside the matrix. The petsc will show the error message as:<br>
> <br>
> [14]PETSC ERROR: Argument out of range<br>
> [14]PETSC ERROR: New nonzero at (58,56) caused a malloc<br>
> Use MatSetOption(A, MAT_NEW_NONZERO_ALLOCATION_<wbr>ERR, PETSC_FALSE) to turn off this check<br>
> <br>
> My current the solution is destroy the system and reallocate with the same size. But I believe there should be more efficient way, i.e. just use the original structure.<br>
> <br>
> I would like search for help to confirm that whether PETSC will compress/delete the zero entries during the MatAssemblyBegin/<wbr>MatAssemblyEnd/KSPSolve, or other possible places.<br>
> <br>
> And how to avoid deleting zero elements during the process?<br>
> <br>
> Thanks very much.<br>
> <br>
> <br>
> <br>
> <br>
> Qicang SHEN<br>
> PhD Candidate<br>
> Nuclear Engineering and Radiological Sciences, University of Michigan, Ann Arbor<br>
> Email: <a href="mailto:qicangsh@umich.edu">qicangsh@umich.edu</a><br>
<br>
</div></div></blockquote></div><br></div>