xref: /petsc/include/petscmath.h (revision 7556704393990e9a05104f18399364067eaa5e80)
1e489efc1SBarry Smith /*
2314da920SBarry Smith 
3314da920SBarry Smith       PETSc mathematics include file. Defines certain basic mathematical
4314da920SBarry Smith     constants and functions for working with single and double precision
5314da920SBarry Smith     floating point numbers as well as complex and integers.
6314da920SBarry Smith 
7e7029fe1SSatish Balay     This file is included by petsc.h and should not be used directly.
8e7029fe1SSatish Balay 
9e489efc1SBarry Smith */
10e489efc1SBarry Smith 
11488ecbafSBarry Smith #if !defined(__PETSCMATH_H)
12488ecbafSBarry Smith #define __PETSCMATH_H
130a5f7794SBarry Smith #include <math.h>
14e9fa29b7SSatish Balay PETSC_EXTERN_CXX_BEGIN
150a5f7794SBarry Smith 
16ff73aad6SKris Buschelman extern  MPI_Datatype PETSC_DLLEXPORT MPIU_2SCALAR;
17ff73aad6SKris Buschelman extern  MPI_Datatype PETSC_DLLEXPORT MPIU_2INT;
18314da920SBarry Smith /*
19f4ccad53SBarry Smith 
20f4ccad53SBarry Smith      Defines operations that are different for complex and real numbers;
21f4ccad53SBarry Smith    note that one cannot really mix the use of complex and real in the same
22f4ccad53SBarry Smith    PETSc program. All PETSc objects in one program are built around the object
23ea709b57SSatish Balay    PetscScalar which is either always a double or a complex.
24f4ccad53SBarry Smith 
25e489efc1SBarry Smith */
26b36a9721SBarry Smith 
2759cb5930SBarry Smith #define PetscExpPassiveScalar(a) PetscExpScalar()
2859cb5930SBarry Smith 
29aa482453SBarry Smith #if defined(PETSC_USE_COMPLEX)
30b7940d39SSatish Balay #if defined(PETSC_CLANGUAGE_CXX)
310bfd3fbfSBarry Smith /*
32b7940d39SSatish Balay    C++ support of complex numbers: Original support
330bfd3fbfSBarry Smith */
34df9b3741SSatish Balay #include <complex>
35adc17e78SSatish Balay 
36329f5518SBarry Smith #define PetscRealPart(a)      (a).real()
37329f5518SBarry Smith #define PetscImaginaryPart(a) (a).imag()
383f6de6efSSatish Balay #define PetscAbsScalar(a)     std::abs(a)
393f6de6efSSatish Balay #define PetscConj(a)          std::conj(a)
4018a7d68fSSatish Balay #define PetscSqrtScalar(a)    std::sqrt(a)
41184914b5SBarry Smith #define PetscPowScalar(a,b)   std::pow(a,b)
42184914b5SBarry Smith #define PetscExpScalar(a)     std::exp(a)
4306c1185fSBarry Smith #define PetscLogScalar(a)     std::log(a)
44184914b5SBarry Smith #define PetscSinScalar(a)     std::sin(a)
45184914b5SBarry Smith #define PetscCosScalar(a)     std::cos(a)
460bfd3fbfSBarry Smith 
4765460251SBarry Smith #if defined(PETSC_USE_SCALAR_SINGLE)
484a60b672SMatthew Knepley typedef std::complex<float> PetscScalar;
4965460251SBarry Smith #elif defined(PETSC_USE_SCALAR_LONG_DOUBLE)
504a60b672SMatthew Knepley typedef std::complex<long double> PetscScalar;
5165460251SBarry Smith #elif defined(PETSC_USE_SCALAR_INT)
524a60b672SMatthew Knepley typedef std::complex<int> PetscScalar;
534a60b672SMatthew Knepley #else
54ea709b57SSatish Balay typedef std::complex<double> PetscScalar;
554a60b672SMatthew Knepley #endif
56b7940d39SSatish Balay #else
57b7940d39SSatish Balay #include <complex.h>
58b7940d39SSatish Balay 
59b7940d39SSatish Balay /*
60b7940d39SSatish Balay    C support of complex numbers: Warning it needs a
61b7940d39SSatish Balay    C90 compliant compiler to work...
62b7940d39SSatish Balay  */
63b7940d39SSatish Balay 
6465460251SBarry Smith #if defined(PETSC_USE_SCALAR_SINGLE)
6585b47369SMatthew Knepley typedef float complex PetscScalar;
6685b47369SMatthew Knepley 
6785b47369SMatthew Knepley #define PetscRealPart(a)      crealf(a)
6885b47369SMatthew Knepley #define PetscImaginaryPart(a) cimagf(a)
6985b47369SMatthew Knepley #define PetscAbsScalar(a)     cabsf(a)
7085b47369SMatthew Knepley #define PetscConj(a)          conjf(a)
7185b47369SMatthew Knepley #define PetscSqrtScalar(a)    csqrtf(a)
7285b47369SMatthew Knepley #define PetscPowScalar(a,b)   cpowf(a,b)
7385b47369SMatthew Knepley #define PetscExpScalar(a)     cexpf(a)
7406c1185fSBarry Smith #define PetscLogScalar(a)     clogf(a)
7585b47369SMatthew Knepley #define PetscSinScalar(a)     csinf(a)
7685b47369SMatthew Knepley #define PetscCosScalar(a)     ccosf(a)
7765460251SBarry Smith #elif defined(PETSC_USE_SCALAR_LONG_DOUBLE)
7885b47369SMatthew Knepley typedef long double complex PetscScalar;
7985b47369SMatthew Knepley 
8085b47369SMatthew Knepley #define PetscRealPart(a)      creall(a)
8185b47369SMatthew Knepley #define PetscImaginaryPart(a) cimagl(a)
8285b47369SMatthew Knepley #define PetscAbsScalar(a)     cabsl(a)
8385b47369SMatthew Knepley #define PetscConj(a)          conjl(a)
8485b47369SMatthew Knepley #define PetscSqrtScalar(a)    csqrtl(a)
8585b47369SMatthew Knepley #define PetscPowScalar(a,b)   cpowl(a,b)
8685b47369SMatthew Knepley #define PetscExpScalar(a)     cexpl(a)
8706c1185fSBarry Smith #define PetscLogScalar(a)     clogl(a)
8885b47369SMatthew Knepley #define PetscSinScalar(a)     csinl(a)
8985b47369SMatthew Knepley #define PetscCosScalar(a)     ccosl(a)
9085b47369SMatthew Knepley 
9185b47369SMatthew Knepley #else
9285b47369SMatthew Knepley typedef double complex PetscScalar;
9385b47369SMatthew Knepley 
94b7940d39SSatish Balay #define PetscRealPart(a)      creal(a)
95b7940d39SSatish Balay #define PetscImaginaryPart(a) cimag(a)
96b7940d39SSatish Balay #define PetscAbsScalar(a)     cabs(a)
97b7940d39SSatish Balay #define PetscConj(a)          conj(a)
98b7940d39SSatish Balay #define PetscSqrtScalar(a)    csqrt(a)
99b7940d39SSatish Balay #define PetscPowScalar(a,b)   cpow(a,b)
100b7940d39SSatish Balay #define PetscExpScalar(a)     cexp(a)
10106c1185fSBarry Smith #define PetscLogScalar(a)     clog(a)
102b7940d39SSatish Balay #define PetscSinScalar(a)     csin(a)
103b7940d39SSatish Balay #define PetscCosScalar(a)     ccos(a)
104b7940d39SSatish Balay #endif
1054a60b672SMatthew Knepley #endif
106e489efc1SBarry Smith 
107762437b8SSatish Balay extern  MPI_Datatype PETSC_DLLEXPORT MPIU_COMPLEX;
108762437b8SSatish Balay #define MPIU_SCALAR         MPIU_COMPLEX
10965460251SBarry Smith #if defined(PETSC_USE_SCALAR_MAT_SINGLE)
110762437b8SSatish Balay #define MPIU_MATSCALAR        ??Notdone
111762437b8SSatish Balay #else
112762437b8SSatish Balay #define MPIU_MATSCALAR      MPIU_COMPLEX
113762437b8SSatish Balay #endif
114762437b8SSatish Balay 
115*75567043SBarry Smith 
116e489efc1SBarry Smith /* Compiling for real numbers only */
117e489efc1SBarry Smith #else
11865460251SBarry Smith #  if defined(PETSC_USE_SCALAR_SINGLE)
11987828ca2SBarry Smith #    define MPIU_SCALAR           MPI_FLOAT
12065460251SBarry Smith #  elif defined(PETSC_USE_SCALAR_LONG_DOUBLE)
121f68b968cSBarry Smith #    define MPIU_SCALAR           MPI_LONG_DOUBLE
122*75567043SBarry Smith #  elif defined(PETSC_USE_SCALAR_INT)
123*75567043SBarry Smith #    define MPIU_SCALAR           MPI_INT
124*75567043SBarry Smith #  elif defined(PETSC_USE_SCALAR_QD_DD)
125*75567043SBarry Smith #    define MPIU_SCALAR           MPIU_QD_DD
12687828ca2SBarry Smith #  else
127e489efc1SBarry Smith #    define MPIU_SCALAR           MPI_DOUBLE
12887828ca2SBarry Smith #  endif
12965460251SBarry Smith #  if defined(PETSC_USE_SCALAR_MAT_SINGLE) || defined(PETSC_USE_SCALAR_SINGLE)
1303eda8832SBarry Smith #    define MPIU_MATSCALAR        MPI_FLOAT
13165460251SBarry Smith #  elif defined(PETSC_USE_SCALAR_LONG_DOUBLE)
132f68b968cSBarry Smith #    define MPIU_MATSCALAR        MPI_LONG_DOUBLE
13365460251SBarry Smith #  elif defined(PETSC_USE_SCALAR_INT)
13403c60df9SBarry Smith #    define MPIU_MATSCALAR        MPI_INT
135*75567043SBarry Smith #  elif defined(PETSC_USE_SCALAR_QD_DD)
136*75567043SBarry Smith #    define MPIU_MATSCALAR        MPIU_QD_DD
1373eda8832SBarry Smith #  else
1383eda8832SBarry Smith #    define MPIU_MATSCALAR        MPI_DOUBLE
1393eda8832SBarry Smith #  endif
140329f5518SBarry Smith #  define PetscRealPart(a)      (a)
141*75567043SBarry Smith #  define PetscImaginaryPart(a) (0.)
142e489efc1SBarry Smith #  define PetscAbsScalar(a)     (((a)<0.0)   ? -(a) : (a))
143e489efc1SBarry Smith #  define PetscConj(a)          (a)
14418a7d68fSSatish Balay #  define PetscSqrtScalar(a)    sqrt(a)
145184914b5SBarry Smith #  define PetscPowScalar(a,b)   pow(a,b)
146184914b5SBarry Smith #  define PetscExpScalar(a)     exp(a)
14706c1185fSBarry Smith #  define PetscLogScalar(a)     log(a)
148184914b5SBarry Smith #  define PetscSinScalar(a)     sin(a)
149184914b5SBarry Smith #  define PetscCosScalar(a)     cos(a)
150b0a32e0cSBarry Smith 
15165460251SBarry Smith #  if defined(PETSC_USE_SCALAR_SINGLE)
152ea709b57SSatish Balay   typedef float PetscScalar;
15365460251SBarry Smith #  elif defined(PETSC_USE_SCALAR_LONG_DOUBLE)
154f68b968cSBarry Smith   typedef long double PetscScalar;
15565460251SBarry Smith #  elif defined(PETSC_USE_SCALAR_INT)
15603c60df9SBarry Smith   typedef int PetscScalar;
157*75567043SBarry Smith #  elif defined(PETSC_USE_SCALAR_QD_DD)
158*75567043SBarry Smith #  include "qd/dd_real.h"
159*75567043SBarry Smith   typedef dd_real PetscScalar;
160b0a32e0cSBarry Smith #  else
161ea709b57SSatish Balay   typedef double PetscScalar;
162b0a32e0cSBarry Smith #  endif
163e489efc1SBarry Smith #endif
164e489efc1SBarry Smith 
16565460251SBarry Smith #if defined(PETSC_USE_SCALAR_SINGLE)
166d7d1e502SBarry Smith #  define MPIU_REAL   MPI_FLOAT
16765460251SBarry Smith #elif defined(PETSC_USE_SCALAR_LONG_DOUBLE)
168f68b968cSBarry Smith #  define MPIU_REAL   MPI_LONG_DOUBLE
16965460251SBarry Smith #elif defined(PETSC_USE_SCALAR_INT)
17003c60df9SBarry Smith #  define MPIU_REAL   MPI_INT
171*75567043SBarry Smith #elif defined(PETSC_USE_SCALAR_QD_DD)
172*75567043SBarry Smith #  define MPIU_REAL   MPIU_QD_DD
173d7d1e502SBarry Smith #else
174d7d1e502SBarry Smith #  define MPIU_REAL   MPI_DOUBLE
175d7d1e502SBarry Smith #endif
176d7d1e502SBarry Smith 
177*75567043SBarry Smith #if defined(PETSC_USE_SCALAR_QD_DD)
178*75567043SBarry Smith extern  MPI_Datatype PETSC_DLLEXPORT MPIU_QD_DD;
179*75567043SBarry Smith #endif
180*75567043SBarry Smith 
181da9b6338SBarry Smith #define PetscSign(a) (((a) >= 0) ? ((a) == 0 ? 0 : 1) : -1)
18226aa1773SMatthew Knepley #define PetscAbs(a)  (((a) >= 0) ? (a) : -(a))
1833f1db9ecSBarry Smith /*
1843f1db9ecSBarry Smith        Allows compiling PETSc so that matrix values are stored in
1853f1db9ecSBarry Smith    single precision but all other objects still use double
1863f1db9ecSBarry Smith    precision. This does not work for complex numbers in that case
1873f1db9ecSBarry Smith    it remains double
1883f1db9ecSBarry Smith 
1893f1db9ecSBarry Smith           EXPERIMENTAL! NOT YET COMPLETELY WORKING
1903f1db9ecSBarry Smith */
1913f1db9ecSBarry Smith 
19265460251SBarry Smith #if defined(PETSC_USE_SCALAR_MAT_SINGLE)
193b400db4cSSatish Balay typedef float MatScalar;
1943f1db9ecSBarry Smith #else
195ea709b57SSatish Balay typedef PetscScalar MatScalar;
19611380375SSatish Balay #endif
1973f1db9ecSBarry Smith 
19865460251SBarry Smith #if defined(PETSC_USE_SCALAR_SINGLE)
199b400db4cSSatish Balay   typedef float PetscReal;
20065460251SBarry Smith #elif defined(PETSC_USE_SCALAR_LONG_DOUBLE)
201f68b968cSBarry Smith   typedef long double PetscReal;
20265460251SBarry Smith #elif defined(PETSC_USE_SCALAR_INT)
20303c60df9SBarry Smith   typedef int PetscReal;
204*75567043SBarry Smith #elif defined(PETSC_USE_SCALAR_QD_DD)
205*75567043SBarry Smith   typedef dd_real PetscReal;
206329f5518SBarry Smith #else
207b400db4cSSatish Balay   typedef double PetscReal;
208329f5518SBarry Smith #endif
2093f1db9ecSBarry Smith 
210f68b968cSBarry Smith #if defined(PETSC_USE_COMPLEX)
211f68b968cSBarry Smith typedef PetscReal MatReal;
21265460251SBarry Smith #elif defined(PETSC_USE_SCALAR_MAT_SINGLE) || defined(PETSC_USE_SCALAR_SINGLE)
213f68b968cSBarry Smith typedef float MatReal;
214f68b968cSBarry Smith #else
215f68b968cSBarry Smith typedef PetscReal MatReal;
216f68b968cSBarry Smith #endif
217f68b968cSBarry Smith 
218f68b968cSBarry Smith 
219314da920SBarry Smith /* --------------------------------------------------------------------------*/
220314da920SBarry Smith 
221e489efc1SBarry Smith /*
222e489efc1SBarry Smith    Certain objects may be created using either single
223e489efc1SBarry Smith   or double precision.
224e489efc1SBarry Smith */
225*75567043SBarry Smith typedef enum { PETSC_SCALAR_DOUBLE,PETSC_SCALAR_SINGLE, PETSC_SCALAR_LONG_DOUBLE, PETSC_SCALAR_QD_DD } PetscScalarPrecision;
226e489efc1SBarry Smith 
227e489efc1SBarry Smith /* PETSC_i is the imaginary number, i */
228ff73aad6SKris Buschelman extern  PetscScalar PETSC_DLLEXPORT PETSC_i;
229e489efc1SBarry Smith 
230b6a5bde7SBarry Smith /*MC
231b6a5bde7SBarry Smith    PetscMin - Returns minimum of two numbers
232b6a5bde7SBarry Smith 
233b6a5bde7SBarry Smith    Input Parameter:
234b6a5bde7SBarry Smith +  v1 - first value to find minimum of
235b6a5bde7SBarry Smith -  v2 - second value to find minimum of
236b6a5bde7SBarry Smith 
237b6a5bde7SBarry Smith    Synopsis:
238b6a5bde7SBarry Smith    type PetscMin(type v1,type v2)
239b6a5bde7SBarry Smith 
240b6a5bde7SBarry Smith    Notes: type can be integer or floating point value
241b6a5bde7SBarry Smith 
242b6a5bde7SBarry Smith    Level: beginner
243b6a5bde7SBarry Smith 
244b6a5bde7SBarry Smith 
245b6a5bde7SBarry Smith .seealso: PetscMin(), PetscAbsInt(), PetscAbsReal(), PetscSqr()
246b6a5bde7SBarry Smith 
247b6a5bde7SBarry Smith M*/
248e489efc1SBarry Smith #define PetscMin(a,b)   (((a)<(b)) ?  (a) : (b))
249b6a5bde7SBarry Smith 
250b6a5bde7SBarry Smith /*MC
251b6a5bde7SBarry Smith    PetscMax - Returns maxium of two numbers
252b6a5bde7SBarry Smith 
253b6a5bde7SBarry Smith    Input Parameter:
254b6a5bde7SBarry Smith +  v1 - first value to find maximum of
255b6a5bde7SBarry Smith -  v2 - second value to find maximum of
256b6a5bde7SBarry Smith 
257b6a5bde7SBarry Smith    Synopsis:
258b6a5bde7SBarry Smith    type max PetscMax(type v1,type v2)
259b6a5bde7SBarry Smith 
260b6a5bde7SBarry Smith    Notes: type can be integer or floating point value
261b6a5bde7SBarry Smith 
262b6a5bde7SBarry Smith    Level: beginner
263b6a5bde7SBarry Smith 
264b6a5bde7SBarry Smith .seealso: PetscMin(), PetscAbsInt(), PetscAbsReal(), PetscSqr()
265b6a5bde7SBarry Smith 
266b6a5bde7SBarry Smith M*/
267e489efc1SBarry Smith #define PetscMax(a,b)   (((a)<(b)) ?  (b) : (a))
268b6a5bde7SBarry Smith 
269b6a5bde7SBarry Smith /*MC
270b6a5bde7SBarry Smith    PetscAbsInt - Returns the absolute value of an integer
271b6a5bde7SBarry Smith 
272b6a5bde7SBarry Smith    Input Parameter:
273b6a5bde7SBarry Smith .   v1 - the integer
274b6a5bde7SBarry Smith 
275b6a5bde7SBarry Smith    Synopsis:
276b6a5bde7SBarry Smith    int abs PetscAbsInt(int v1)
277b6a5bde7SBarry Smith 
278b6a5bde7SBarry Smith 
279b6a5bde7SBarry Smith    Level: beginner
280b6a5bde7SBarry Smith 
281b6a5bde7SBarry Smith .seealso: PetscMax(), PetscMin(), PetscAbsReal(), PetscSqr()
282b6a5bde7SBarry Smith 
283b6a5bde7SBarry Smith M*/
284e489efc1SBarry Smith #define PetscAbsInt(a)  (((a)<0)   ? -(a) : (a))
285b6a5bde7SBarry Smith 
286b6a5bde7SBarry Smith /*MC
287b6a5bde7SBarry Smith    PetscAbsReal - Returns the absolute value of an real number
288b6a5bde7SBarry Smith 
289b6a5bde7SBarry Smith    Input Parameter:
290b6a5bde7SBarry Smith .   v1 - the double
291b6a5bde7SBarry Smith 
292b6a5bde7SBarry Smith    Synopsis:
293b6a5bde7SBarry Smith    int abs PetscAbsReal(PetscReal v1)
294b6a5bde7SBarry Smith 
295b6a5bde7SBarry Smith 
296b6a5bde7SBarry Smith    Level: beginner
297b6a5bde7SBarry Smith 
298b6a5bde7SBarry Smith .seealso: PetscMax(), PetscMin(), PetscAbsInt(), PetscSqr()
299b6a5bde7SBarry Smith 
300b6a5bde7SBarry Smith M*/
301f6275e2eSBarry Smith #define PetscAbsReal(a) (((a)<0)   ? -(a) : (a))
302b6a5bde7SBarry Smith 
303b6a5bde7SBarry Smith /*MC
304b6a5bde7SBarry Smith    PetscSqr - Returns the square of a number
305b6a5bde7SBarry Smith 
306b6a5bde7SBarry Smith    Input Parameter:
307b6a5bde7SBarry Smith .   v1 - the value
308b6a5bde7SBarry Smith 
309b6a5bde7SBarry Smith    Synopsis:
310b6a5bde7SBarry Smith    type sqr PetscSqr(type v1)
311b6a5bde7SBarry Smith 
312b6a5bde7SBarry Smith    Notes: type can be integer or floating point value
313b6a5bde7SBarry Smith 
314b6a5bde7SBarry Smith    Level: beginner
315b6a5bde7SBarry Smith 
316b6a5bde7SBarry Smith .seealso: PetscMax(), PetscMin(), PetscAbsInt(), PetscAbsReal()
317b6a5bde7SBarry Smith 
318b6a5bde7SBarry Smith M*/
3194ebda54eSMatthew Knepley #define PetscSqr(a)     ((a)*(a))
320e489efc1SBarry Smith 
321314da920SBarry Smith /* ----------------------------------------------------------------------------*/
322314da920SBarry Smith /*
32303c60df9SBarry Smith      Basic constants - These should be done much better
324314da920SBarry Smith */
325314da920SBarry Smith #define PETSC_PI                 3.14159265358979323846264
326314da920SBarry Smith #define PETSC_DEGREES_TO_RADIANS 0.01745329251994
32771fd2e92SBarry Smith #define PETSC_MAX_INT            2147483647
32871fd2e92SBarry Smith #define PETSC_MIN_INT            -2147483647
329e489efc1SBarry Smith 
33065460251SBarry Smith #if defined(PETSC_USE_SCALAR_SINGLE)
3317e032f8bSBarry Smith #  define PETSC_MAX                     1.e30
3327e032f8bSBarry Smith #  define PETSC_MIN                    -1.e30
333f10639e6SSatish Balay #  define PETSC_MACHINE_EPSILON         1.e-7
334f10639e6SSatish Balay #  define PETSC_SQRT_MACHINE_EPSILON    3.e-4
335cf6e855fSSatish Balay #  define PETSC_SMALL                   1.e-5
33665460251SBarry Smith #elif defined(PETSC_USE_SCALAR_INT)
33703c60df9SBarry Smith #  define PETSC_MAX                     PETSC_MAX_INT
33803c60df9SBarry Smith #  define PETSC_MIN                     PETSC_MIN_INT
33903c60df9SBarry Smith #  define PETSC_MACHINE_EPSILON         1
34003c60df9SBarry Smith #  define PETSC_SQRT_MACHINE_EPSILON    1
34103c60df9SBarry Smith #  define PETSC_SMALL                   0
342*75567043SBarry Smith #elif defined(PETSC_USE_SCALAR_QD_DD)
343*75567043SBarry Smith #  define PETSC_MAX                     1.e300
344*75567043SBarry Smith #  define PETSC_MIN                    -1.e300
345*75567043SBarry Smith #  define PETSC_MACHINE_EPSILON         1.e-30
346*75567043SBarry Smith #  define PETSC_SQRT_MACHINE_EPSILON    1.e-15
347*75567043SBarry Smith #  define PETSC_SMALL                   1.e-25
34882adfdadSBarry Smith #else
3497e032f8bSBarry Smith #  define PETSC_MAX                     1.e300
3507e032f8bSBarry Smith #  define PETSC_MIN                    -1.e300
351f10639e6SSatish Balay #  define PETSC_MACHINE_EPSILON         1.e-14
352f10639e6SSatish Balay #  define PETSC_SQRT_MACHINE_EPSILON    1.e-7
353cf6e855fSSatish Balay #  define PETSC_SMALL                   1.e-10
35482adfdadSBarry Smith #endif
35582adfdadSBarry Smith 
356ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT PetscGlobalMax(PetscReal*,PetscReal*,MPI_Comm);
357ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT PetscGlobalMin(PetscReal*,PetscReal*,MPI_Comm);
358ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT PetscGlobalSum(PetscScalar*,PetscScalar*,MPI_Comm);
3593e523bebSBarry Smith 
3600763cb5fSBarry Smith /*MC
3610763cb5fSBarry Smith       PetscIsInfOrNan - Returns 1 if the input double has an infinity for Not-a-number (Nan) value, otherwise 0.
3623e523bebSBarry Smith 
3630763cb5fSBarry Smith     Input Parameter:
3640763cb5fSBarry Smith .     a - the double
3650763cb5fSBarry Smith 
3660763cb5fSBarry Smith 
3670763cb5fSBarry Smith      Notes: uses the C99 standard isinf() and isnan() on systems where they exist.
36883886165SBarry Smith       Otherwises uses ( (a - a) != 0.0), note that some optimizing compiles compile
3690763cb5fSBarry Smith       out this form, thus removing the check.
3700763cb5fSBarry Smith 
37183672c4dSSatish Balay      Level: beginner
37283672c4dSSatish Balay 
37383672c4dSSatish Balay M*/
3749a25a3ccSBarry Smith #if defined(PETSC_HAVE_ISINF) && defined(PETSC_HAVE_ISNAN)
375f66fdb6dSSatish Balay #define PetscIsInfOrNanScalar(a) (isinf(PetscAbsScalar(a)) || isnan(PetscAbsScalar(a)))
376f66fdb6dSSatish Balay #define PetscIsInfOrNanReal(a) (isinf(a) || isnan(a))
37762b4c0b3SBarry Smith #elif defined(PETSC_HAVE__FINITE) && defined(PETSC_HAVE__ISNAN)
378270b8587SSatish Balay #if defined(PETSC_HAVE_FLOAT_H)
379270b8587SSatish Balay #include "float.h"  /* windows defines _finite() in float.h */
380270b8587SSatish Balay #endif
381961faeafSBarry Smith #if defined(PETSC_HAVE_IEEEFP_H)
382961faeafSBarry Smith #include "ieeefp.h"  /* Solaris prototypes these here */
383961faeafSBarry Smith #endif
384f66fdb6dSSatish Balay #define PetscIsInfOrNanScalar(a) (!_finite(PetscAbsScalar(a)) || _isnan(PetscAbsScalar(a)))
385f66fdb6dSSatish Balay #define PetscIsInfOrNanReal(a) (!_finite(a) || _isnan(a))
3869a25a3ccSBarry Smith #else
387f66fdb6dSSatish Balay #define PetscIsInfOrNanScalar(a) ((a - a) != 0.0)
388f66fdb6dSSatish Balay #define PetscIsInfOrNanReal(a) ((a - a) != 0.0)
3899a25a3ccSBarry Smith #endif
3909a25a3ccSBarry Smith 
3919a25a3ccSBarry Smith 
392314da920SBarry Smith /* ----------------------------------------------------------------------------*/
393e489efc1SBarry Smith /*
394b0a32e0cSBarry Smith     PetscLogDouble variables are used to contain double precision numbers
395e489efc1SBarry Smith   that are not used in the numerical computations, but rather in logging,
396e489efc1SBarry Smith   timing etc.
397e489efc1SBarry Smith */
398b0a32e0cSBarry Smith typedef double PetscLogDouble;
399b9617806SBarry Smith #define MPIU_PETSCLOGDOUBLE MPI_DOUBLE
400e489efc1SBarry Smith 
40187828ca2SBarry Smith #define PassiveReal   PetscReal
402ea709b57SSatish Balay #define PassiveScalar PetscScalar
403d3ecb3a7SBarry Smith 
404e9fa29b7SSatish Balay 
405e9fa29b7SSatish Balay PETSC_EXTERN_CXX_END
406e489efc1SBarry Smith #endif
407