GCC Code Coverage Report


Directory: ./
File: include/slepcmath.h
Date: 2026-11-30 06:30:50
Exec Total Coverage
Lines: 17 17 100.0%
Functions: 4 4 100.0%
Branches: 33 52 63.5%

Line Branch Exec Source
1 /*
2 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3 SLEPc - Scalable Library for Eigenvalue Problem Computations
4 Copyright (c) 2002-, Universitat Politecnica de Valencia, Spain
5
6 This file is part of SLEPc.
7 SLEPc is distributed under a 2-clause BSD license (see LICENSE).
8 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
9 */
10 /*
11 SLEPc mathematics include file. Defines basic operations and functions.
12 This file is included by slepcsys.h and should not be used directly.
13 */
14
15 #pragma once
16
17 #include <petscsys.h>
18
19 /* SUBMANSEC = Sys */
20
21 /*
22 Default tolerance for the different solvers, depending on the precision
23 */
24 #if PetscDefined(USE_REAL_SINGLE)
25 # define SLEPC_DEFAULT_TOL 1e-5
26 #elif PetscDefined(USE_REAL_DOUBLE)
27 # define SLEPC_DEFAULT_TOL 1e-8
28 #elif PetscDefined(USE_REAL___FLOAT128)
29 # define SLEPC_DEFAULT_TOL 1e-16
30 #elif PetscDefined(USE_REAL___FP16)
31 # define SLEPC_DEFAULT_TOL 1e-2
32 #endif
33
34 28877 static inline PetscReal SlepcDefaultTol(PetscReal tol)
35 {
36
5/6
✓ Branch 0 taken 186 times.
✓ Branch 1 taken 189 times.
✓ Branch 2 taken 20 times.
✓ Branch 3 taken 26 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 10 times.
28877 return tol == (PetscReal)PETSC_DETERMINE ? SLEPC_DEFAULT_TOL : tol;
37 }
38
39 /*@
40 SlepcAbs - Returns $\sqrt{x^2+y^2}$, taking care not to cause unnecessary
41 overflow. It is based on LAPACK's `DLAPY2`.
42
43 Not Collective
44
45 Input parameters:
46 + x - the first real number
47 - y - the second real number
48
49 Output parameter:
50 . return - the result
51
52 Fortran Note:
53 This function is not available from Fortran.
54
55 Level: developer
56 @*/
57 22662911 static inline PetscReal SlepcAbs(PetscReal x,PetscReal y)
58 {
59
4/4
✓ Branch 0 taken 220 times.
✓ Branch 1 taken 321 times.
✓ Branch 2 taken 150 times.
✓ Branch 3 taken 321 times.
22662911 PetscReal w,z,t,xabs=PetscAbs(x),yabs=PetscAbs(y);
60
61
2/2
✓ Branch 0 taken 256 times.
✓ Branch 1 taken 198 times.
22662911 w = PetscMax(xabs,yabs);
62
2/2
✓ Branch 0 taken 256 times.
✓ Branch 1 taken 198 times.
22662911 z = PetscMin(xabs,yabs);
63
2/2
✓ Branch 0 taken 256 times.
✓ Branch 1 taken 226 times.
22662911 if (PetscUnlikely(z == (PetscReal)0.0)) return w;
64 1590750 t = z/w;
65 1590750 return w*PetscSqrtReal((PetscReal)1.0+t*t);
66 }
67
68 /*MC
69 SlepcAbsEigenvalue - Returns the absolute value of a complex number given
70 its real and imaginary parts.
71
72 Synopsis:
73 #include <slepcmath.h>
74 PetscReal SlepcAbsEigenvalue(PetscScalar x, PetscScalar y)
75
76 Not Collective
77
78 Input parameters:
79 + x - the real part of the complex number
80 - y - the imaginary part of the complex number
81
82 Notes:
83 This function computes $\sqrt{x^2+y^2}$, taking care not to cause unnecessary
84 overflow. It is based on LAPACK's `DLAPY2`.
85
86 In complex scalars, only the first argument is used, i.e., the result is $|x|$.
87
88 Fortran Note:
89 This function is not available from Fortran.
90
91 Level: developer
92
93 .seealso: `PetscAbsScalar()`
94 M*/
95 #if !PetscDefined(USE_COMPLEX)
96 #define SlepcAbsEigenvalue(x,y) SlepcAbs((x),(y))
97 #else
98 #define SlepcAbsEigenvalue(x,y) PetscAbsScalar(x)
99 #endif
100
101 /*@
102 SlepcSetFlushToZero - Set the FTZ flag in floating-point arithmetic.
103
104 Logically Collective
105
106 Output Parameter:
107 . state - the value before setting the flag
108
109 Level: developer
110
111 .seealso: `SlepcResetFlushToZero()`
112 @*/
113 222 static inline PetscErrorCode SlepcSetFlushToZero(unsigned int *state)
114 {
115
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
222 PetscFunctionBegin;
116 #if PetscDefined(HAVE_XMMINTRIN_H) && defined(_MM_FLUSH_ZERO_ON) && defined(__SSE__)
117 *state = _MM_GET_FLUSH_ZERO_MODE();
118 _MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON);
119 #else
120 756 *state = 0;
121 #endif
122
7/14
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 4 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 4 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✓ Branch 13 taken 4 times.
222 PetscFunctionReturn(PETSC_SUCCESS);
123 }
124
125 /*@
126 SlepcResetFlushToZero - Reset the FTZ flag in floating-point arithmetic.
127
128 Logically Collective
129
130 Input Parameter:
131 . state - the value to be restored
132
133 Level: developer
134
135 .seealso: `SlepcResetFlushToZero()`
136 @*/
137 144 static inline PetscErrorCode SlepcResetFlushToZero(unsigned int *state)
138 {
139
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
144 PetscFunctionBegin;
140 #if PetscDefined(HAVE_XMMINTRIN_H) && defined(_MM_FLUSH_ZERO_MASK) && defined(__SSE__)
141 _MM_SET_FLUSH_ZERO_MODE(*state & _MM_FLUSH_ZERO_MASK);
142 #else
143 756 *state = 0;
144 #endif
145
7/14
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 4 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 4 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✓ Branch 13 taken 4 times.
144 PetscFunctionReturn(PETSC_SUCCESS);
146 }
147