<div dir="ltr"><div dir="ltr">On Thu, Jan 24, 2019 at 4:53 AM Ali Reza Khaz'ali 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 lang="EN-US"><div class="gmail-m_2569078822082571283WordSection1"><p class="MsoNormal">Hi all,<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">As far as I understand, using MatSetValues for new non-zero entries will cause an error if MAT_NEW_NONZERO_LOCATION_ERR== PETSC_TRUE.  Setting MAT_NEW_NONZERO_LOCATION_ERR to PETSC_FALSE is also undesirable since it will slow down the code, and in some cases, the performance loss will be extreme. However, is there any solution for a matrix that the number of non-zeros on each of its rows is fixed in both diagonal and off-diagonal parts, but the location (the column number) of the non-zero entries may vary during the procedures? I can use MAT_NEW_NONZERO_LOCATION_ERR== PETSC_TRUE, but it is important to me that the code runs as fast as possible.<u></u><u></u></p><p class="MsoNormal">Any help is much appreciated.</p></div></div></blockquote><div><br></div><div>The main reason for slowdown is reallocation. However, MatAssembly will squeeze out extra space in all rows.</div><div>Thus, in order to move entries around without reallocating, you must stick zeros there when they are no used.</div><div>I would do this:<br></div><div><br></div><div>  1) Measure the performance degradation from doing this naively</div><div><br></div><div>  2) If it is noticeable, then go in and write a MatChangeRow() that allows you to alter the column index and value.</div><div><br></div><div>  Thanks,</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 lang="EN-US"><div class="gmail-m_2569078822082571283WordSection1"><p class="MsoNormal"> </p><p class="MsoNormal"><u></u></p><p class="MsoNormal">Best wishes,<u></u><u></u></p><p class="MsoNormal">Ali<u></u><u></u></p></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>