# How to find the determinant or condition number of the stiffness matrix?

**URL:** <https://community.freefem.org/t/how-to-find-the-determinant-or-condition-number-of-the-stiffness-matrix/1506>\
**Category:** General Discussion\
**Created:** [February 19, 2022, 5:37am UTC](https://community.freefem.org/t/how-to-find-the-determinant-or-condition-number-of-the-stiffness-matrix/1506 "2022-02-19T05:37:46Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Qianrui](https://avatars.discourse-cdn.com/v4/letter/q/9fc348/32.png) [@Qianrui](https://community.freefem.org/u/Qianrui)\
**Post date:** [February 19, 2022, 5:37am UTC](https://community.freefem.org/t/how-to-find-the-determinant-or-condition-number-of-the-stiffness-matrix/1506/1 "2022-02-19T05:37:46Z")

</div>

Hi,profeesor How to find the determinant or condition number of the stiffness matrix?

---

<div class="post-metadata">

**Author:** ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)\
**Post date:** [February 19, 2022, 8:44am UTC](https://community.freefem.org/t/how-to-find-the-determinant-or-condition-number-of-the-stiffness-matrix/1506/2 "2022-02-19T08:44:46Z")

</div>

You can use MUMPS, see [MATSOLVERMUMPS](https://petsc.org/main/docs/manualpages/Mat/MATSOLVERMUMPS.html) `mat_mumps_icntl_33` for the determinant. For the condition number, you can use SLEPc or ARPACK, or if the problem is not too ill-conditioned, `-ksp_monitor_singular_value`.

---

<div class="post-metadata">

**Author:** ![frederichecht](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/frederichecht/32/15_2.png) [@frederichecht](https://community.freefem.org/u/frederichecht)\
**Post date:** [February 19, 2022, 5:03pm UTC](https://community.freefem.org/t/how-to-find-the-determinant-or-condition-number-of-the-stiffness-matrix/1506/3 "2022-02-19T17:03:17Z")

</div>

Be careful with the boundary condition, the tgv technique break the condition number .  
And The example eigen/condition-number.edp given an example:  
[condition-number.edp](https://community.freefem.org/uploads/short-url/zS6ptl09n6MF8dNImyBY3GRMKsR.edp) (718 Bytes)

---

<div class="post-metadata">

**Author:** ![Qianrui](https://avatars.discourse-cdn.com/v4/letter/q/9fc348/32.png) [@Qianrui](https://community.freefem.org/u/Qianrui)\
**Post date:** [February 26, 2022, 11:42am UTC](https://community.freefem.org/t/how-to-find-the-determinant-or-condition-number-of-the-stiffness-matrix/1506/4 "2022-02-26T11:42:10Z")

</div>

Hi,professor, I used the following command,  
set(dA, sparams ="-pc\_factor\_mat\_solver\_type superlu -mat\_mumps\_icntl\_33");  
but how do I output this determinant?

---

<div class="post-metadata">

**Author:** ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)\
**Post date:** [February 26, 2022, 8:49pm UTC](https://community.freefem.org/t/how-to-find-the-determinant-or-condition-number-of-the-stiffness-matrix/1506/5 "2022-02-26T20:49:26Z")

</div>

You need to use MUMPS, not SuperLU. The determinant is displayed if you further add `-ksp_view`.

---

<div class="post-metadata">

**Author:** ![Qianrui](https://avatars.discourse-cdn.com/v4/letter/q/9fc348/32.png) [@Qianrui](https://community.freefem.org/u/Qianrui)\
**Post date:** [February 27, 2022, 6:48am UTC](https://community.freefem.org/t/how-to-find-the-determinant-or-condition-number-of-the-stiffness-matrix/1506/7 "2022-02-27T06:48:23Z")

</div>

> [@prj](#):
>
> determinant

Hi，professor, I used the following command, but there is no determinant，why?  
set(A, sparams =“-pc\_factor\_mat\_solver\_type mumps -mat\_mumps\_icntl\_33 -ksp\_view\_determinant”);

---

<div class="post-metadata">

**Author:** ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)\
**Post date:** [February 27, 2022, 7:11am UTC](https://community.freefem.org/t/how-to-find-the-determinant-or-condition-number-of-the-stiffness-matrix/1506/8 "2022-02-27T07:11:19Z")

</div>

What is `-ksp_view_determinant`?

---

<div class="post-metadata">

**Author:** ![Qianrui](https://avatars.discourse-cdn.com/v4/letter/q/9fc348/32.png) [@Qianrui](https://community.freefem.org/u/Qianrui)\
**Post date:** [February 27, 2022, 7:16am UTC](https://community.freefem.org/t/how-to-find-the-determinant-or-condition-number-of-the-stiffness-matrix/1506/9 "2022-02-27T07:16:05Z")

</div>

I want to output determinants, but I use the following command to output conditional numbers,why？ The command “mumps -mat\_mumps\_icntl\_33 " should the determinant.  
set(A, sparams =”-pc\_factor\_mat\_solver\_type mumps -mat\_mumps\_icntl\_33 -ksp\_view\_singularvalues")

---

<div class="post-metadata">

**Author:** ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)\
**Post date:** [February 27, 2022, 7:29am UTC](https://community.freefem.org/t/how-to-find-the-determinant-or-condition-number-of-the-stiffness-matrix/1506/10 "2022-02-27T07:29:48Z")

</div>

Why are you not using the flag I told you to use in the first place?

---

<div class="post-metadata">

**Author:** ![Qianrui](https://avatars.discourse-cdn.com/v4/letter/q/9fc348/32.png) [@Qianrui](https://community.freefem.org/u/Qianrui)\
**Post date:** [February 27, 2022, 1:25pm UTC](https://community.freefem.org/t/how-to-find-the-determinant-or-condition-number-of-the-stiffness-matrix/1506/12 "2022-02-27T13:25:52Z")

</div>

Hi, however, I used the command  
set(A, sparams ="-pc\_factor\_mat\_solver\_type mumps -mat\_mumps\_icntl\_33 -ksp\_view"), but Still there is any output about the determinant.

---

<div class="post-metadata">

**Author:** ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)\
**Post date:** [February 27, 2022, 1:58pm UTC](https://community.freefem.org/t/how-to-find-the-determinant-or-condition-number-of-the-stiffness-matrix/1506/13 "2022-02-27T13:58:21Z")

</div>

This is what I get, for example running `diffusion-2d-PETSc.edp` from `examples/hpddm`:

```auto
[...]
              RINFOG(3) (global estimated flops for the elimination after factorization): 1.93421e+06 
              (RINFOG(12) RINFOG(13))*2^INFOG(34) (determinant): (0.713452,0.)*(2^6709)
              INFOG(3) (estimated real workspace for factors on all processors after analysis): 65153
[...]

```

Determinant is the second line in the above snippet.

---

<div class="post-metadata">

**Author:** ![Qianrui](https://avatars.discourse-cdn.com/v4/letter/q/9fc348/32.png) [@Qianrui](https://community.freefem.org/u/Qianrui)\
**Post date:** [March 6, 2022, 11:56am UTC](https://community.freefem.org/t/how-to-find-the-determinant-or-condition-number-of-the-stiffness-matrix/1506/14 "2022-03-06T11:56:25Z")

</div>

Hello, I tried some examples from\> examples/hpddm  
, but I still didn’t output the result of determinant. The output content is basically as follows. Why？

> C:\Users\weiqi\>FreeFem+±mpi stokes-2d-PETSc.edp -v 0  
> KSP Object: 1 MPI processes  
> type: gmres  
> restart=30, using Classical (unmodified) Gram-Schmidt Orthogonalization with no iterative refinement  
> happy breakdown tolerance 1e-30  
> maximum iterations=10000, initial guess is zero  
> tolerances: relative=1e-05, absolute=1e-50, divergence=10000.  
> left preconditioning  
> using PRECONDITIONED norm type for convergence test  
> PC Object: 1 MPI processes  
> type: bjacobi  
> number of blocks = 1  
> Local solver information for first block is in the following KSP and PC objects on rank 0:  
> Use -ksp\_view ::ascii\_info\_detail to display information for all blocks  
> KSP Object: (sub\_) 1 MPI processes  
> type: preonly  
> maximum iterations=10000, initial guess is zero  
> tolerances: relative=1e-05, absolute=1e-50, divergence=10000.  
> left preconditioning  
> using NONE norm type for convergence test  
> PC Object: (sub\_) 1 MPI processes  
> type: ilu  
> out-of-place factorization  
> 0 levels of fill  
> tolerance for zero pivot 2.22045e-14  
> matrix ordering: natural  
> factor fill ratio given 1., needed 1.  
> Factored matrix follows:  
> Mat Object: 1 MPI processes  
> type: seqaij  
> rows=22203, cols=22203  
> package used to perform factorization: petsc  
> total: nonzeros=647409, allocated nonzeros=647409  
> using I-node routines: found 9835 nodes, limit used is 5  
> linear system matrix = precond matrix:  
> Mat Object: (sub\_) 1 MPI processes  
> type: seqaij  
> rows=22203, cols=22203  
> total: nonzeros=647409, allocated nonzeros=647409  
> total number of mallocs used during MatSetValues calls=0  
> using I-node routines: found 9835 nodes, limit used is 5  
> linear system matrix = precond matrix:  
> Mat Object: 1 MPI processes  
> type: mpiaij  
> rows=22203, cols=22203  
> total: nonzeros=647409, allocated nonzeros=647409  
> total number of mallocs used during MatSetValues calls=0  
> using I-node (on process 0) routines: found 9835 nodes, limit used is 5

---

<div class="post-metadata">

**Author:** ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)\
**Post date:** [March 6, 2022, 12:37pm UTC](https://community.freefem.org/t/how-to-find-the-determinant-or-condition-number-of-the-stiffness-matrix/1506/15 "2022-03-06T12:37:40Z")

</div>

You are not using the proper preconditioner (`-pc_type`).

---

<div class="post-metadata">

**Author:** ![Qianrui](https://avatars.discourse-cdn.com/v4/letter/q/9fc348/32.png) [@Qianrui](https://community.freefem.org/u/Qianrui)\
**Post date:** [March 6, 2022, 12:46pm UTC](https://community.freefem.org/t/how-to-find-the-determinant-or-condition-number-of-the-stiffness-matrix/1506/16 "2022-03-06T12:46:28Z")

</div>

Hello, professor, I still don’t quite understand what you mean. Could you please explain it in detail?

---

<div class="post-metadata">

**Author:** ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)\
**Post date:** [March 6, 2022, 7:52pm UTC](https://community.freefem.org/t/how-to-find-the-determinant-or-condition-number-of-the-stiffness-matrix/1506/17 "2022-03-06T19:52:04Z")

</div>

Explain what? `-pc_type` and `-ksp_view` are explained in the screencast I sent earlier.

---

<div class="post-metadata">

**Author:** ![Qianrui](https://avatars.discourse-cdn.com/v4/letter/q/9fc348/32.png) [@Qianrui](https://community.freefem.org/u/Qianrui)\
**Post date:** [March 7, 2022, 8:52am UTC](https://community.freefem.org/t/how-to-find-the-determinant-or-condition-number-of-the-stiffness-matrix/1506/18 "2022-03-07T08:52:10Z")

</div>

Thank you. I see what you mean, but the determinant （ **examples/hpddm/bilaplace-2d-PETSc.edp** )is (0, 0) \* (2 ^ 0)，why？

> C:\Users\weiqi\>FreeFem+±mpi bilaplace-2d-PETSc.edp -v 0  
> KSP Object: 1 MPI processes  
> type: gmres  
> restart=30, using Classical (unmodified) Gram-Schmidt Orthogonalization with no iterative refinement  
> happy breakdown tolerance 1e-30  
> maximum iterations=10000, initial guess is zero  
> tolerances: relative=1e-05, absolute=1e-50, divergence=10000.  
> left preconditioning  
> using PRECONDITIONED norm type for convergence test  
> PC Object: 1 MPI processes  
> type: cholesky  
> out-of-place factorization  
> tolerance for zero pivot 2.22045e-14  
> matrix ordering: external  
> factor fill ratio given 0., needed 0.  
> Factored matrix follows:  
> Mat Object: 1 MPI processes  
> type: mumps  
> rows=6561, cols=6561  
> package used to perform factorization: mumps  
> total: nonzeros=201780, allocated nonzeros=201780  
> MUMPS run parameters:  
> SYM (matrix type): 2  
> PAR (host participation): 1  
> ICNTL(1) (output for error): 6  
> ICNTL(2) (output of diagnostic msg): 0  
> ICNTL(3) (output for global info): 0  
> ICNTL(4) (level of printing): 0  
> ICNTL(5) (input mat struct): 0  
> ICNTL(6) (matrix prescaling): 7  
> ICNTL(7) (sequential matrix ordering):7  
> ICNTL(8) (scaling strategy): 77  
> ICNTL(10) (max num of refinements): 0  
> ICNTL(11) (error analysis): 0  
> ICNTL(12) (efficiency control): 0  
> ICNTL(13) (sequential factorization of the root node): 0  
> ICNTL(14) (percentage of estimated workspace increase): 20  
> ICNTL(18) (input mat struct): 0  
> ICNTL(19) (Schur complement info): 0  
> ICNTL(20) (RHS sparse pattern): 0  
> ICNTL(21) (solution struct): 0  
> ICNTL(22) (in-core/out-of-core facility): 0  
> ICNTL(23) (max size of memory can be allocated locally):0  
> ICNTL(24) (detection of null pivot rows): 0  
> ICNTL(25) (computation of a null space basis): 0  
> ICNTL(26) (Schur options for RHS or solution): 0  
> ICNTL(27) (blocking size for multiple RHS): -32  
> ICNTL(28) (use parallel or sequential ordering): 1  
> ICNTL(29) (parallel ordering): 0  
> ICNTL(30) (user-specified set of entries in inv(A)): 0  
> ICNTL(31) (factors is discarded in the solve phase): 0  
> ICNTL(33) (compute determinant): 0  
> ICNTL(35) (activate BLR based factorization): 0  
> ICNTL(36) (choice of BLR factorization variant): 0  
> ICNTL(38) (estimated compression rate of LU factors): 333  
> CNTL(1) (relative pivoting threshold): 0.01  
> CNTL(2) (stopping criterion of refinement): 1.49012e-08  
> CNTL(3) (absolute pivoting threshold): 0.  
> CNTL(4) (value of static pivoting): -1.  
> CNTL(5) (fixation for null pivots): 0.  
> CNTL(7) (dropping parameter for BLR): 0.  
> RINFO(1) (local estimated flops for the elimination after analysis):  
> [0] 1.1037e+07  
> RINFO(2) (local estimated flops for the assembly after factorization):  
> [0] 339313.  
> RINFO(3) (local estimated flops for the elimination after factorization):  
> [0] 1.1037e+07  
> INFO(15) (estimated size of (in MB) MUMPS internal data for running numerical factorization):  
> [0] 4  
> INFO(16) (size of (in MB) MUMPS internal data used during numerical factorization):  
> [0] 4  
> INFO(23) (num of pivots eliminated on this processor after factorization):  
> [0] 6561  
> RINFOG(1) (global estimated flops for the elimination after analysis): 1.1037e+07  
> RINFOG(2) (global estimated flops for the assembly after factorization): 339313.  
> RINFOG(3) (global estimated flops for the elimination after factorization): 1.1037e+07  
> (RINFOG(12) RINFOG(13))_2^INFOG(34) (determinant): (0.,0.)_(2^0)  
> INFOG(3) (estimated real workspace for factors on all processors after analysis): 228803  
> INFOG(4) (estimated integer workspace for factors on all processors after analysis): 121006  
> INFOG(5) (estimated maximum front size in the complete tree): 144  
> INFOG(6) (number of nodes in the complete tree): 2392  
> INFOG(7) (ordering option effectively used after analysis): 2  
> INFOG(8) (structural symmetry in percent of the permuted matrix after analysis): 100  
> INFOG(9) (total real/complex workspace to store the matrix factors after factorization): 228803  
> INFOG(10) (total integer space store the matrix factors after factorization): 121006  
> INFOG(11) (order of largest frontal matrix after factorization): 144  
> INFOG(12) (number of off-diagonal pivots): 0  
> INFOG(13) (number of delayed pivots after factorization): 0  
> INFOG(14) (number of memory compress after factorization): 0  
> INFOG(15) (number of steps of iterative refinement after solution): 0  
> INFOG(16) (estimated size (in MB) of all MUMPS internal data for factorization after analysis: value on the most memory consuming processor): 4  
> INFOG(17) (estimated size of all MUMPS internal data for factorization after analysis: sum over all processors): 4  
> INFOG(18) (size of all MUMPS internal data allocated during factorization: value on the most memory consuming processor): 4  
> INFOG(19) (size of all MUMPS internal data allocated during factorization: sum over all processors): 4  
> INFOG(20) (estimated number of entries in the factors): 201780  
> INFOG(21) (size in MB of memory effectively used during factorization - value on the most memory consuming processor): 4  
> INFOG(22) (size in MB of memory effectively used during factorization - sum over all processors): 4  
> INFOG(23) (after analysis: value of ICNTL(6) effectively used): 0  
> INFOG(24) (after analysis: value of ICNTL(12) effectively used): 1  
> INFOG(25) (after factorization: number of pivots modified by static pivoting): 0  
> INFOG(28) (after factorization: number of null pivots encountered): 0  
> INFOG(29) (after factorization: effective number of entries in the factors (sum over all processors)): 201780  
> INFOG(30, 31) (after solution: size in Mbytes of memory used during solution phase): 3, 3  
> INFOG(32) (after analysis: type of analysis done): 1  
> INFOG(33) (value used for ICNTL(8)): 7  
> INFOG(34) (exponent of the determinant if determinant is requested): 0  
> INFOG(35) (after factorization: number of entries taking into account BLR factor compression - sum over all processors): 201780  
> INFOG(36) (after analysis: estimated size of all MUMPS internal data for running BLR in-core - value on the most memory consuming processor): 0  
> INFOG(37) (after analysis: estimated size of all MUMPS internal data for running BLR in-core - sum over all processors): 0  
> INFOG(38) (after analysis: estimated size of all MUMPS internal data for running BLR out-of-core - value on the most memory consuming processor): 0  
> INFOG(39) (after analysis: estimated size of all MUMPS internal data for running BLR out-of-core - sum over all processors): 0  
> linear system matrix = precond matrix:  
> Mat Object: 1 MPI processes  
> type: mpiaij  
> rows=6561, cols=6561  
> total: nonzeros=74241, allocated nonzeros=74241  
> total number of mallocs used during MatSetValues calls=0  
> not using I-node (on process 0) routines

---

<div class="post-metadata">

**Author:** ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)\
**Post date:** [March 7, 2022, 9:03am UTC](https://community.freefem.org/t/how-to-find-the-determinant-or-condition-number-of-the-stiffness-matrix/1506/19 "2022-03-07T09:03:20Z")

</div>

Here is what I get with `-mat_mumps_icntl_33 1`:

```auto
              (RINFOG(12) RINFOG(13))*2^INFOG(34) (determinant): (0.622873,0.)*(2^79647)

```

---

<div class="post-metadata">

**Author:** ![Qianrui](https://avatars.discourse-cdn.com/v4/letter/q/9fc348/32.png) [@Qianrui](https://community.freefem.org/u/Qianrui)\
**Post date:** [March 7, 2022, 9:12am UTC](https://community.freefem.org/t/how-to-find-the-determinant-or-condition-number-of-the-stiffness-matrix/1506/20 "2022-03-07T09:12:06Z")

</div>

On line 26 of this code, re-enter the following language:

> set(A, sparams = “-pc\_type cholesky -pc\_factor\_mat\_solver\_type mumps -mat\_mumps\_icntl\_33 -ksp\_view”);

next, Enter the following command in the command window

> C:\Users\weiqi\>FreeFem+±mpi bilaplace-2d-PETSc.edp -v 0

---

<div class="post-metadata">

**Author:** ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)\
**Post date:** [March 7, 2022, 9:26am UTC](https://community.freefem.org/t/how-to-find-the-determinant-or-condition-number-of-the-stiffness-matrix/1506/21 "2022-03-07T09:26:39Z")

</div>

It is `-mat_mumps_icntl_33 1`, you are missing the one.

---

<div class="post-metadata">

**Author:** ![Qianrui](https://avatars.discourse-cdn.com/v4/letter/q/9fc348/32.png) [@Qianrui](https://community.freefem.org/u/Qianrui)\
**Post date:** [March 7, 2022, 10:39am UTC](https://community.freefem.org/t/how-to-find-the-determinant-or-condition-number-of-the-stiffness-matrix/1506/22 "2022-03-07T10:39:02Z")

</div>

> [@prj](#):
>
> -mat\_mumps\_icntl\_33 1

Thank you very much indeed. It’s very patient of you. Thank you

[Next page](https://community.freefem.org/t/how-to-find-the-determinant-or-condition-number-of-the-stiffness-matrix/1506.md?page=2)
