[petsc-users] Calculating inertias

Jose E. Roman jroman at dsic.upv.es
Tue Mar 24 11:22:27 CDT 2020


If you obtained the PC object with KSPGetPC() then you do not have to destroy it, only the KSP object. KSPGetPC() only gives a pointer to the internal object, which is managed by the KSP.
Jose


> El 24 mar 2020, a las 17:18, Perceval Desforges <perceval.desforges at polytechnique.edu> escribió:
> 
> Thank you very much, this seems to work well.
> 
> I have another question linked to this which is probably a bit basic so I apologize.
> 
> 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 :
> 
> [0]PETSC ERROR: Invalid argument
> 
> [0]PETSC ERROR: Wrong type of object: Parameter # 1
> 
> I've tried switching the order around, but I still get the same errors. 
> 
> And if I don't destroy these objects I get a memory leak, which I'd like to avoid.
> 
> My question is I don't really understand when and how I'm supposed to destroy the KSP and PC objects? 
> 
> Thanks again,
> 
> Best regards,
> 
> Perceval,
> 
> 
> 
> 
> 
>> 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.
>> 
>> I guess it can be even shorter if you call MatCholeskyFactor() directly.
>> 
>> Jose
>> 
>> 
>>> El 24 mar 2020, a las 11:07, Perceval Desforges <perceval.desforges at polytechnique.edu> escribió:
>>> 
>>> Dear petsc developers,
>>> 
>>> 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. 
>>> 
>>> 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?
>>> 
>>> Best regards,
>>> 
>>> Perceval,
>>> 
>>> P.S. my last email seems to not have been sent (I couldn't find it in the archives) so I am trying again...
>>> 
> 
> 



More information about the petsc-users mailing list