GCC Code Coverage Report


Directory: ./
File: include/slepcmath.h
Date: 2026-09-29 04:16:25
Exec Total Coverage
Lines: 17 17 100.0%
Functions: 4 4 100.0%
Branches: 29 44 65.9%

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