<div dir="ltr"><div dir="ltr">On Mon, Oct 21, 2019 at 9:47 PM Zhang, Hong <<a href="mailto:hzhang@mcs.anl.gov">hzhang@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>
<div dir="ltr">
<div dir="ltr">Matt:<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">On Mon, Oct 21, 2019 at 9:30 PM Zhang, Hong via petsc-users <<a href="mailto:petsc-users@mcs.anl.gov" target="_blank">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>
<div dir="ltr">
<div dir="ltr">Shash,<br>
</div>
<div>You may do it without using pc. See petsc/src/mat/examples/tests/ex125.c</div>
<div></div>
</div>
</div>
</blockquote>
<div><br>
</div>
<div>Does this example let you invert the matrix and just apply to get the solve?</div>
</div>
</div>
</blockquote>
<div>No. It gets LU factors stored in F, then call MatSolve(F, b, x) multiple times to get solution x for given b.</div>
<div></div></div></div></div></blockquote><div><br></div><div>Do we have anything in PETSc now that gets the inverse? Storing and applying the inverse can be much faster</div><div>than using the factors (it's done in supernodal methods, and it our patch smoothers). If not, we should talk about</div><div>adding it.</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><div dir="ltr"><div class="gmail_quote"><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">
<div dir="ltr">
<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>
<div dir="ltr"><br>
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">On Mon, Oct 21, 2019 at 4:43 PM Shashwat Sharma via petsc-users <<a href="mailto:petsc-users@mcs.anl.gov" target="_blank">petsc-users@mcs.anl.gov</a>> wrote:<br>
</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div>
<div dir="ltr">
<div dir="ltr">Hello,
<div><br>
</div>
<div>For some small matrices, I'd like to use Petsc to perform direct LU factorization on a sequential dense or AIJ matrix, and then use the factored matrix later on via MatSolve. This occurs multiple times in my code, and each factored matrix is in turn used
multiple times.</div>
<div><br>
</div>
<div>I tried to wrap this factorization process in a function, which should return the factored matrix, as follows:</div>
<div><br>
</div>
<div>
<div>void MatFactorize_Petsc(Mat &mat, Mat &mat_factored)</div>
<div>{</div>
<div><span style="white-space:pre-wrap"></span>PC pc;</div>
<div><span style="white-space:pre-wrap"></span>PCCreate(MPI_COMM_SELF, &pc);</div>
<div><span style="white-space:pre-wrap"></span>PCSetOperators(pc, mat, mat);</div>
<div><span style="white-space:pre-wrap"></span>PCSetType(pc, PCLU);</div>
<div><br>
</div>
<div><span style="white-space:pre-wrap"></span>PCFactorSetMatSolverType(pc, MATSOLVERPETSC); // Or SuperLU</div>
<div><span style="white-space:pre-wrap"></span>PCFactorSetUpMatSolverType(pc);</div>
<div><br>
</div>
<div><span style="white-space:pre-wrap"></span>PCFactorGetMatrix(pc, &mat_factored);<span style="white-space:pre-wrap">
</span></div>
<div><span style="white-space:pre-wrap"></span>PCSetUp(pc);</div>
<div><span style="white-space:pre-wrap"></span></div>
<div><span style="white-space:pre-wrap"></span>// PCDestroy(&pc);</div>
<div><span style="white-space:pre-wrap"></span></div>
<div><span style="white-space:pre-wrap"></span>return;</div>
<div>}</div>
</div>
<div><br>
</div>
<div>The command PCDestroy causes a segmentation fault, which I think happens because retrieving the factored matrix does not increase the reference count. Looking at the Petsc source, it basically returns a pointer to pc->data. So if I want to use mat_factored
outside the function, I cannot destroy the PC object, which leads to memory leaks (as per Valgrind) even if I later call MatDestroy(&mat_factored).</div>
<div><br>
</div>
<div>I tried using a temp matrix to get the factors, and then doing MatDuplicate(temp, MAT_COPY_VALUES, &mat_factored), but MatDuplicate is not allowed on factored matrices; same for MatConvert.</div>
<div><br>
</div>
<div>Is there a way I can achieve the desired behaviour, where mat_factored is not "linked" to the pc or ksp object, keeping in mind that I'd like to be able to choose between SuperLU, Petsc and SuperLU_dist solvers?</div>
<div><br>
</div>
<div>Thanks,</div>
<div>Shash</div>
<div>
<div>
<div dir="ltr">
<div dir="ltr">
<div>
<div dir="ltr">
<div>
<div dir="ltr">
<div dir="ltr"><br>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
</div>
</div>
</div>
</blockquote>
</div>
<br clear="all">
<div><br>
</div>
-- <br>
<div dir="ltr">
<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>
</blockquote>
</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>