<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /></head><body style='font-size: 10pt; font-family: Verdana,Geneva,sans-serif'>
<p>Thank you very much, this seems to work well.</p>
<p>I have another question linked to this which is probably a bit basic so I apologize.</p>
<p>At the end of my program, I want to destroy all the petsc objects. I start by destroying the matrixes, then the ksp and pc objects similarly to how it's done in the examples. However I get an error when attempting to destroy the KSP and PC objects :</p>
<p><span>[0]PETSC ERROR: Invalid argument</span></p>
<p><span>[0]PETSC ERROR: Wrong type of object: Parameter # 1</span></p>
<p><span>I've tried switching the order around, but I still get the same errors. </span></p>
<p><span>And if I don't destroy these objects I get a memory leak, which I'd like to avoid.</span></p>
<p><span>My question is I don't really understand when and how I'm supposed to destroy the KSP and PC objects? </span></p>
<p><span>Thanks again,</span></p>
<p><span>Best regards,</span></p>
<p><span>Perceval,</span></p>
<p><br /></p>
<p><br /></p>
<blockquote type="cite" style="padding: 0 0.4em; border-left: #1010ff 2px solid; margin: 0">
<div class="pre" style="margin: 0; padding: 0; font-family: monospace">You can do this directly in PETSc. Create a KSP object with PREONLY and PCCHOLESKY (or just a PC object). Then call KSPSetUp (or PCSetUp) and extract the factored matrix with PCFactorGetMatrix(). Then call MatGetInertia() on the factored matrix. Repeat this for each value of E.<br /><br />I guess it can be even shorter if you call MatCholeskyFactor() directly.<br /><br />Jose<br /><br /><br />
<blockquote type="cite" style="padding: 0 0.4em; border-left: #1010ff 2px solid; margin: 0">El 24 mar 2020, a las 11:07, Perceval Desforges <<a href="mailto:perceval.desforges@polytechnique.edu">perceval.desforges@polytechnique.edu</a>> escribió:<br /><br />Dear petsc developers,<br /><br />I am interested in calculating the inertias of matrixes. Specifically, for a certain matrix A, and for different real numbers E, I want to calculate the inertias of (A - E * I), in order to get the number of eigenvalues less than E. <br /><br />In order to do this I have been setting up a slepc EPS object with spectrum slicing, and using EPSKrylovSchurGetInertias. I realize this is a bit convoluted, and was wondering if there is a better way to do this?<br /><br />Best regards,<br /><br />Perceval,<br /><br />P.S. my last email seems to not have been sent (I couldn't find it in the archives) so I am trying again...<br /><br /></blockquote>
</div>
</blockquote>
<p><br /></p>

</body></html>