1e489efc1SBarry Smith /* 2314da920SBarry Smith 3314da920SBarry Smith PETSc mathematics include file. Defines certain basic mathematical 4a5057860SBarry Smith constants and functions for working with single, double, and quad precision 5a5057860SBarry Smith floating point numbers as well as complex single and double. 6314da920SBarry Smith 7d382aafbSBarry Smith This file is included by petscsys.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> 140a5f7794SBarry Smith 15014dd563SJed Brown PETSC_EXTERN MPI_Datatype MPIU_2SCALAR; 16014dd563SJed Brown PETSC_EXTERN MPI_Datatype MPIU_2INT; 17c90a1750SBarry Smith 18314da920SBarry Smith /* 19f4ccad53SBarry Smith 20f4ccad53SBarry Smith Defines operations that are different for complex and real numbers; 21a5057860SBarry Smith note that one cannot 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 2398725619SBarry Smith PetscScalar which is either always a real or a complex. 24f4ccad53SBarry Smith 25e489efc1SBarry Smith */ 26b36a9721SBarry Smith 2759cb5930SBarry Smith #define PetscExpPassiveScalar(a) PetscExpScalar() 28c1d390e3SJed Brown #if defined(PETSC_USE_REAL_SINGLE) 29c1d390e3SJed Brown #define MPIU_REAL MPI_FLOAT 30c1d390e3SJed Brown typedef float PetscReal; 318f1a2a5eSBarry Smith #define PetscSqrtReal(a) sqrt(a) 32*9a07f4dfSJed Brown #define PetscExpReal(a) exp(a) 33*9a07f4dfSJed Brown #define PetscLogReal(a) log(a) 34*9a07f4dfSJed Brown #define PetscSinReal(a) sin(a) 35*9a07f4dfSJed Brown #define PetscCosReal(a) cos(a) 36c1d390e3SJed Brown #elif defined(PETSC_USE_REAL_DOUBLE) 37c1d390e3SJed Brown #define MPIU_REAL MPI_DOUBLE 38c1d390e3SJed Brown typedef double PetscReal; 398f1a2a5eSBarry Smith #define PetscSqrtReal(a) sqrt(a) 40*9a07f4dfSJed Brown #define PetscExpReal(a) exp(a) 41*9a07f4dfSJed Brown #define PetscLogReal(a) log(a) 42*9a07f4dfSJed Brown #define PetscSinReal(a) sin(a) 43*9a07f4dfSJed Brown #define PetscCosReal(a) cos(a) 44c1d390e3SJed Brown #elif defined(PETSC_USE_REAL___FLOAT128) 45574fde7bSSatish Balay #if defined(__cplusplus) 46574fde7bSSatish Balay extern "C" { 47574fde7bSSatish Balay #endif 48574fde7bSSatish Balay #include <quadmath.h> 49574fde7bSSatish Balay #if defined(__cplusplus) 50574fde7bSSatish Balay } 51574fde7bSSatish Balay #endif 52c1d390e3SJed Brown #define MPIU_REAL MPIU___FLOAT128 53c1d390e3SJed Brown typedef __float128 PetscReal; 548f1a2a5eSBarry Smith #define PetscSqrtReal(a) sqrtq(a) 55*9a07f4dfSJed Brown #define PetscExpReal(a) expq(a) 56*9a07f4dfSJed Brown #define PetscLogReal(a) logq(a) 57*9a07f4dfSJed Brown #define PetscSinReal(a) sinq(a) 58*9a07f4dfSJed Brown #define PetscCosReal(a) cosq(a) 59c1d390e3SJed Brown #endif /* PETSC_USE_REAL_* */ 6059cb5930SBarry Smith 611093a601SBarry Smith /* 621093a601SBarry Smith Complex number definitions 631093a601SBarry Smith */ 6450f81f78SJed Brown #if defined(PETSC_CLANGUAGE_CXX) && defined(PETSC_HAVE_CXX_COMPLEX) 659f20b660SSatish Balay #if defined(PETSC_USE_COMPLEX) || defined(PETSC_DESIRE_COMPLEX) 6650f81f78SJed Brown #define PETSC_HAVE_COMPLEX 1 671093a601SBarry Smith /* C++ support of complex number */ 68debe9ee2SPaul Mullowney #if defined(PETSC_HAVE_CUSP) 69debe9ee2SPaul Mullowney #define complexlib cusp 709ae82921SPaul Mullowney #include <cusp/complex.h> 71debe9ee2SPaul Mullowney #else 72debe9ee2SPaul Mullowney #define complexlib std 73debe9ee2SPaul Mullowney #include <complex> 749ae82921SPaul Mullowney #endif 75b7940d39SSatish Balay 7650f81f78SJed Brown #define PetscRealPartComplex(a) (a).real() 7750f81f78SJed Brown #define PetscImaginaryPartComplex(a) (a).imag() 7850f81f78SJed Brown #define PetscAbsComplex(a) complexlib::abs(a) 7950f81f78SJed Brown #define PetscConjComplex(a) complexlib::conj(a) 8050f81f78SJed Brown #define PetscSqrtComplex(a) complexlib::sqrt(a) 8150f81f78SJed Brown #define PetscPowComplex(a,b) complexlib::pow(a,b) 8250f81f78SJed Brown #define PetscExpComplex(a) complexlib::exp(a) 8350f81f78SJed Brown #define PetscLogComplex(a) complexlib::log(a) 8450f81f78SJed Brown #define PetscSinComplex(a) complexlib::sin(a) 8550f81f78SJed Brown #define PetscCosComplex(a) complexlib::cos(a) 86debe9ee2SPaul Mullowney 87debe9ee2SPaul Mullowney #if defined(PETSC_USE_REAL_SINGLE) 8850f81f78SJed Brown typedef complexlib::complex<float> PetscComplex; 89debe9ee2SPaul Mullowney #elif defined(PETSC_USE_REAL_DOUBLE) 9050f81f78SJed Brown typedef complexlib::complex<double> PetscComplex; 918c764dc5SJose Roman #elif defined(PETSC_USE_REAL___FLOAT128) 9250f81f78SJed Brown typedef complexlib::complex<__float128> PetscComplex; /* Notstandard and not expected to work, use __complex128 */ 93debe9ee2SPaul Mullowney #endif /* PETSC_USE_REAL_ */ 949f20b660SSatish Balay #endif /* PETSC_USE_COMPLEX && PETSC_DESIRE_COMPLEX */ 95debe9ee2SPaul Mullowney 9650f81f78SJed Brown #elif defined(PETSC_CLANGUAGE_C) && defined(PETSC_HAVE_C99_COMPLEX) 9750f81f78SJed Brown /* Use C99 _Complex for the type. Do not include complex.h by default to define "complex" because of symbol conflicts in Hypre. */ 9850f81f78SJed Brown /* Compilation units that can safely use complex should define PETSC_DESIRE_COMPLEX before including any headers */ 9950f81f78SJed Brown #if defined(PETSC_USE_COMPLEX) || defined(PETSC_DESIRE_COMPLEX) 1009f20b660SSatish Balay #define PETSC_HAVE_COMPLEX 1 101519e2a1fSPaul Mullowney #include <complex.h> 102519e2a1fSPaul Mullowney 103ce63c4c1SBarry Smith #if defined(PETSC_USE_REAL_SINGLE) 10450f81f78SJed Brown typedef float _Complex PetscComplex; 10585b47369SMatthew Knepley 10650f81f78SJed Brown #define PetscRealPartComplex(a) crealf(a) 10750f81f78SJed Brown #define PetscImaginaryPartComplex(a) cimagf(a) 10850f81f78SJed Brown #define PetscAbsComplex(a) cabsf(a) 10950f81f78SJed Brown #define PetscConjComplex(a) conjf(a) 11050f81f78SJed Brown #define PetscSqrtComplex(a) csqrtf(a) 11150f81f78SJed Brown #define PetscPowComplex(a,b) cpowf(a,b) 11250f81f78SJed Brown #define PetscExpComplex(a) cexpf(a) 11350f81f78SJed Brown #define PetscLogComplex(a) clogf(a) 11450f81f78SJed Brown #define PetscSinComplex(a) csinf(a) 11550f81f78SJed Brown #define PetscCosComplex(a) ccosf(a) 1161093a601SBarry Smith 117ce63c4c1SBarry Smith #elif defined(PETSC_USE_REAL_DOUBLE) 11850f81f78SJed Brown typedef double _Complex PetscComplex; 1191093a601SBarry Smith 12050f81f78SJed Brown #define PetscRealPartComplex(a) creal(a) 12150f81f78SJed Brown #define PetscImaginaryPartComplex(a) cimag(a) 12250f81f78SJed Brown #define PetscAbsComplex(a) cabs(a) 12350f81f78SJed Brown #define PetscConjComplex(a) conj(a) 12450f81f78SJed Brown #define PetscSqrtComplex(a) csqrt(a) 12550f81f78SJed Brown #define PetscPowComplex(a,b) cpow(a,b) 12650f81f78SJed Brown #define PetscExpComplex(a) cexp(a) 12750f81f78SJed Brown #define PetscLogComplex(a) clog(a) 12850f81f78SJed Brown #define PetscSinComplex(a) csin(a) 12950f81f78SJed Brown #define PetscCosComplex(a) ccos(a) 1301093a601SBarry Smith 1318c764dc5SJose Roman #elif defined(PETSC_USE_REAL___FLOAT128) 13250f81f78SJed Brown typedef __complex128 PetscComplex; 1338c764dc5SJose Roman PETSC_EXTERN MPI_Datatype MPIU___FLOAT128; 1348c764dc5SJose Roman PETSC_EXTERN MPI_Datatype MPIU___COMPLEX128; 1358c764dc5SJose Roman 13650f81f78SJed Brown #define PetscRealPartComplex(a) crealq(a) 13750f81f78SJed Brown #define PetscImaginaryPartComplex(a) cimagq(a) 13850f81f78SJed Brown #define PetscAbsComplex(a) cabsq(a) 13950f81f78SJed Brown #define PetscConjComplex(a) conjq(a) 14050f81f78SJed Brown #define PetscSqrtComplex(a) csqrtq(a) 14150f81f78SJed Brown #define PetscPowComplex(a,b) cpowq(a,b) 14250f81f78SJed Brown #define PetscExpComplex(a) cexpq(a) 14350f81f78SJed Brown #define PetscLogComplex(a) clogq(a) 14450f81f78SJed Brown #define PetscSinComplex(a) csinq(a) 14550f81f78SJed Brown #define PetscCosComplex(a) ccosq(a) 146ce63c4c1SBarry Smith #endif /* PETSC_USE_REAL_* */ 14750f81f78SJed Brown #elif defined(PETSC_USE_COMPLEX) 14850f81f78SJed Brown #error "PETSc was configured --with-scalar-type=complex, but a language-appropriate complex library is not available" 1499f20b660SSatish Balay #endif /* PETSC_USE_COMPLEX || PETSC_DESIRE_COMPLEX */ 1509f20b660SSatish Balay #endif /* (PETSC_CLANGUAGE_CXX && PETSC_HAVE_CXX_COMPLEX) else-if (PETSC_CLANGUAGE_C && PETSC_HAVE_C99_COMPLEX) */ 151e489efc1SBarry Smith 15270da9c3bSJed Brown #if defined(PETSC_HAVE_MPI_C_DOUBLE_COMPLEX) 153500d8756SSatish Balay #define MPIU_C_DOUBLE_COMPLEX MPI_C_DOUBLE_COMPLEX 154500d8756SSatish Balay #define MPIU_C_COMPLEX MPI_C_COMPLEX 15570da9c3bSJed Brown #else 156014dd563SJed Brown PETSC_EXTERN MPI_Datatype MPIU_C_DOUBLE_COMPLEX; 157014dd563SJed Brown PETSC_EXTERN MPI_Datatype MPIU_C_COMPLEX; 1581b65fc54SMatthew G Knepley #endif /* PETSC_HAVE_MPI_C_DOUBLE_COMPLEX */ 1592c876bd9SBarry Smith 16050f81f78SJed Brown #if defined(PETSC_USE_COMPLEX) 16150f81f78SJed Brown typedef PetscComplex PetscScalar; 16250f81f78SJed Brown #define PetscRealPart(a) PetscRealPartComplex(a) 16350f81f78SJed Brown #define PetscImaginaryPart(a) PetscImaginaryPartComplex(a) 16450f81f78SJed Brown #define PetscAbsScalar(a) PetscAbsComplex(a) 16550f81f78SJed Brown #define PetscConj(a) PetscConjComplex(a) 16650f81f78SJed Brown #define PetscSqrtScalar(a) PetscSqrtComplex(a) 16750f81f78SJed Brown #define PetscPowScalar(a,b) PetscPowComplex(a,b) 16850f81f78SJed Brown #define PetscExpScalar(a) PetscExpComplex(a) 16950f81f78SJed Brown #define PetscLogScalar(a) PetscLogComplex(a) 17050f81f78SJed Brown #define PetscSinScalar(a) PetscSinComplex(a) 17150f81f78SJed Brown #define PetscCosScalar(a) PetscCosComplex(a) 17250f81f78SJed Brown 173ce63c4c1SBarry Smith #if defined(PETSC_USE_REAL_SINGLE) 174500d8756SSatish Balay #define MPIU_SCALAR MPIU_C_COMPLEX 175ce63c4c1SBarry Smith #elif defined(PETSC_USE_REAL_DOUBLE) 176500d8756SSatish Balay #define MPIU_SCALAR MPIU_C_DOUBLE_COMPLEX 1773351b394SSatish Balay #elif defined(PETSC_USE_REAL___FLOAT128) 1783351b394SSatish Balay #define MPIU_SCALAR MPIU___COMPLEX128 179ce63c4c1SBarry Smith #endif /* PETSC_USE_REAL_* */ 18075567043SBarry Smith 1811093a601SBarry Smith /* 1821093a601SBarry Smith real number definitions 1831093a601SBarry Smith */ 1841b65fc54SMatthew G Knepley #else /* PETSC_USE_COMPLEX */ 185ce63c4c1SBarry Smith #if defined(PETSC_USE_REAL_SINGLE) 18687828ca2SBarry Smith #define MPIU_SCALAR MPI_FLOAT 1871093a601SBarry Smith typedef float PetscScalar; 188ce63c4c1SBarry Smith #elif defined(PETSC_USE_REAL_DOUBLE) 1891093a601SBarry Smith #define MPIU_SCALAR MPI_DOUBLE 1901093a601SBarry Smith typedef double PetscScalar; 191ce63c4c1SBarry Smith #elif defined(PETSC_USE_REAL___FLOAT128) 192014dd563SJed Brown PETSC_EXTERN MPI_Datatype MPIU___FLOAT128; 193c90a1750SBarry Smith #define MPIU_SCALAR MPIU___FLOAT128 1940d0cc1b5SBarry Smith typedef __float128 PetscScalar; 195ce63c4c1SBarry Smith #endif /* PETSC_USE_REAL_* */ 196329f5518SBarry Smith #define PetscRealPart(a) (a) 197c1d390e3SJed Brown #define PetscImaginaryPart(a) ((PetscReal)0.) 198c1d390e3SJed Brown PETSC_STATIC_INLINE PetscReal PetscAbsScalar(PetscScalar a) {return a < 0.0 ? -a : a;} 199e489efc1SBarry Smith #define PetscConj(a) (a) 200ce63c4c1SBarry Smith #if !defined(PETSC_USE_REAL___FLOAT128) 20118a7d68fSSatish Balay #define PetscSqrtScalar(a) sqrt(a) 202184914b5SBarry Smith #define PetscPowScalar(a,b) pow(a,b) 203184914b5SBarry Smith #define PetscExpScalar(a) exp(a) 20406c1185fSBarry Smith #define PetscLogScalar(a) log(a) 205184914b5SBarry Smith #define PetscSinScalar(a) sin(a) 206184914b5SBarry Smith #define PetscCosScalar(a) cos(a) 207ce63c4c1SBarry Smith #else /* PETSC_USE_REAL___FLOAT128 */ 2080d0cc1b5SBarry Smith #define PetscSqrtScalar(a) sqrtq(a) 2090d0cc1b5SBarry Smith #define PetscPowScalar(a,b) powq(a,b) 2100d0cc1b5SBarry Smith #define PetscExpScalar(a) expq(a) 2110d0cc1b5SBarry Smith #define PetscLogScalar(a) logq(a) 2120d0cc1b5SBarry Smith #define PetscSinScalar(a) sinq(a) 2130d0cc1b5SBarry Smith #define PetscCosScalar(a) cosq(a) 214ce63c4c1SBarry Smith #endif /* PETSC_USE_REAL___FLOAT128 */ 215b0a32e0cSBarry Smith 2161b65fc54SMatthew G Knepley #endif /* PETSC_USE_COMPLEX */ 217e489efc1SBarry Smith 218da9b6338SBarry Smith #define PetscSign(a) (((a) >= 0) ? ((a) == 0 ? 0 : 1) : -1) 21926aa1773SMatthew Knepley #define PetscAbs(a) (((a) >= 0) ? (a) : -(a)) 2203f1db9ecSBarry Smith 221314da920SBarry Smith /* --------------------------------------------------------------------------*/ 222314da920SBarry Smith 223e489efc1SBarry Smith /* 224f22f69f0SBarry Smith Certain objects may be created using either single or double precision. 225f22f69f0SBarry Smith This is currently not used. 226e489efc1SBarry Smith */ 227557d4da8SBarry Smith typedef enum { PETSC_SCALAR_DOUBLE,PETSC_SCALAR_SINGLE, PETSC_SCALAR_LONG_DOUBLE } PetscScalarPrecision; 228e489efc1SBarry Smith 22950f81f78SJed Brown #if defined(PETSC_HAVE_COMPLEX) 230e489efc1SBarry Smith /* PETSC_i is the imaginary number, i */ 23150f81f78SJed Brown PETSC_EXTERN PetscComplex PETSC_i; 23250f81f78SJed Brown #endif 233e489efc1SBarry Smith 234b6a5bde7SBarry Smith /*MC 235b6a5bde7SBarry Smith PetscMin - Returns minimum of two numbers 236b6a5bde7SBarry Smith 237eca87e8dSBarry Smith Synopsis: 238eca87e8dSBarry Smith type PetscMin(type v1,type v2) 239eca87e8dSBarry Smith 240eca87e8dSBarry Smith Not Collective 241eca87e8dSBarry Smith 242b6a5bde7SBarry Smith Input Parameter: 243b6a5bde7SBarry Smith + v1 - first value to find minimum of 244b6a5bde7SBarry Smith - v2 - second value to find minimum of 245b6a5bde7SBarry Smith 246b6a5bde7SBarry Smith 247b6a5bde7SBarry Smith Notes: type can be integer or floating point value 248b6a5bde7SBarry Smith 249b6a5bde7SBarry Smith Level: beginner 250b6a5bde7SBarry Smith 251b6a5bde7SBarry Smith 252d9a4bb16SJed Brown .seealso: PetscMin(), PetscClipInterval(), PetscAbsInt(), PetscAbsReal(), PetscSqr() 253b6a5bde7SBarry Smith 254b6a5bde7SBarry Smith M*/ 255e489efc1SBarry Smith #define PetscMin(a,b) (((a)<(b)) ? (a) : (b)) 256b6a5bde7SBarry Smith 257b6a5bde7SBarry Smith /*MC 258b6a5bde7SBarry Smith PetscMax - Returns maxium of two numbers 259b6a5bde7SBarry Smith 260eca87e8dSBarry Smith Synopsis: 261eca87e8dSBarry Smith type max PetscMax(type v1,type v2) 262eca87e8dSBarry Smith 263eca87e8dSBarry Smith Not Collective 264eca87e8dSBarry Smith 265b6a5bde7SBarry Smith Input Parameter: 266b6a5bde7SBarry Smith + v1 - first value to find maximum of 267b6a5bde7SBarry Smith - v2 - second value to find maximum of 268b6a5bde7SBarry Smith 269b6a5bde7SBarry Smith Notes: type can be integer or floating point value 270b6a5bde7SBarry Smith 271b6a5bde7SBarry Smith Level: beginner 272b6a5bde7SBarry Smith 273d9a4bb16SJed Brown .seealso: PetscMin(), PetscClipInterval(), PetscAbsInt(), PetscAbsReal(), PetscSqr() 274b6a5bde7SBarry Smith 275b6a5bde7SBarry Smith M*/ 276e489efc1SBarry Smith #define PetscMax(a,b) (((a)<(b)) ? (b) : (a)) 277b6a5bde7SBarry Smith 278b6a5bde7SBarry Smith /*MC 279d9a4bb16SJed Brown PetscClipInterval - Returns a number clipped to be within an interval 280d9a4bb16SJed Brown 281d9a4bb16SJed Brown Synopsis: 282d9a4bb16SJed Brown type clip PetscClipInterval(type x,type a,type b) 283d9a4bb16SJed Brown 284d9a4bb16SJed Brown Not Collective 285d9a4bb16SJed Brown 286d9a4bb16SJed Brown Input Parameter: 287d9a4bb16SJed Brown + x - value to use if within interval (a,b) 288d9a4bb16SJed Brown . a - lower end of interval 289d9a4bb16SJed Brown - b - upper end of interval 290d9a4bb16SJed Brown 291d9a4bb16SJed Brown Notes: type can be integer or floating point value 292d9a4bb16SJed Brown 293d9a4bb16SJed Brown Level: beginner 294d9a4bb16SJed Brown 295d9a4bb16SJed Brown .seealso: PetscMin(), PetscMax(), PetscAbsInt(), PetscAbsReal(), PetscSqr() 296d9a4bb16SJed Brown 297d9a4bb16SJed Brown M*/ 298d9a4bb16SJed Brown #define PetscClipInterval(x,a,b) (PetscMax((a),PetscMin((x),(b)))) 299d9a4bb16SJed Brown 300d9a4bb16SJed Brown /*MC 301b6a5bde7SBarry Smith PetscAbsInt - Returns the absolute value of an integer 302b6a5bde7SBarry Smith 303b6a5bde7SBarry Smith Synopsis: 304b6a5bde7SBarry Smith int abs PetscAbsInt(int v1) 305b6a5bde7SBarry Smith 306eca87e8dSBarry Smith Not Collective 307eca87e8dSBarry Smith 308eca87e8dSBarry Smith Input Parameter: 309eca87e8dSBarry Smith . v1 - the integer 310b6a5bde7SBarry Smith 311b6a5bde7SBarry Smith Level: beginner 312b6a5bde7SBarry Smith 313b6a5bde7SBarry Smith .seealso: PetscMax(), PetscMin(), PetscAbsReal(), PetscSqr() 314b6a5bde7SBarry Smith 315b6a5bde7SBarry Smith M*/ 316e489efc1SBarry Smith #define PetscAbsInt(a) (((a)<0) ? -(a) : (a)) 317b6a5bde7SBarry Smith 318b6a5bde7SBarry Smith /*MC 319b6a5bde7SBarry Smith PetscAbsReal - Returns the absolute value of an real number 320b6a5bde7SBarry Smith 321eca87e8dSBarry Smith Synopsis: 322eca87e8dSBarry Smith Real abs PetscAbsReal(PetscReal v1) 323eca87e8dSBarry Smith 324eca87e8dSBarry Smith Not Collective 325eca87e8dSBarry Smith 326b6a5bde7SBarry Smith Input Parameter: 327b6a5bde7SBarry Smith . v1 - the double 328b6a5bde7SBarry Smith 329b6a5bde7SBarry Smith 330b6a5bde7SBarry Smith Level: beginner 331b6a5bde7SBarry Smith 332b6a5bde7SBarry Smith .seealso: PetscMax(), PetscMin(), PetscAbsInt(), PetscSqr() 333b6a5bde7SBarry Smith 334b6a5bde7SBarry Smith M*/ 335f6275e2eSBarry Smith #define PetscAbsReal(a) (((a)<0) ? -(a) : (a)) 336b6a5bde7SBarry Smith 337b6a5bde7SBarry Smith /*MC 338b6a5bde7SBarry Smith PetscSqr - Returns the square of a number 339b6a5bde7SBarry Smith 340b6a5bde7SBarry Smith Synopsis: 341b6a5bde7SBarry Smith type sqr PetscSqr(type v1) 342b6a5bde7SBarry Smith 343eca87e8dSBarry Smith Not Collective 344eca87e8dSBarry Smith 345eca87e8dSBarry Smith Input Parameter: 346eca87e8dSBarry Smith . v1 - the value 347eca87e8dSBarry Smith 348b6a5bde7SBarry Smith Notes: type can be integer or floating point value 349b6a5bde7SBarry Smith 350b6a5bde7SBarry Smith Level: beginner 351b6a5bde7SBarry Smith 352b6a5bde7SBarry Smith .seealso: PetscMax(), PetscMin(), PetscAbsInt(), PetscAbsReal() 353b6a5bde7SBarry Smith 354b6a5bde7SBarry Smith M*/ 3554ebda54eSMatthew Knepley #define PetscSqr(a) ((a)*(a)) 356e489efc1SBarry Smith 357314da920SBarry Smith /* ----------------------------------------------------------------------------*/ 358314da920SBarry Smith /* 359d34fcf5fSBarry Smith Basic constants 360314da920SBarry Smith */ 361ce63c4c1SBarry Smith #if defined(PETSC_USE_REAL___FLOAT128) 362d34fcf5fSBarry Smith #define PETSC_PI M_PIq 363d34fcf5fSBarry Smith #elif defined(M_PI) 364d34fcf5fSBarry Smith #define PETSC_PI M_PI 365d34fcf5fSBarry Smith #else 366faa6e9b0SMatthew G Knepley #define PETSC_PI 3.14159265358979323846264338327950288419716939937510582 367d34fcf5fSBarry Smith #endif 368d34fcf5fSBarry Smith 369ab824b78SBarry Smith #if !defined(PETSC_USE_64BIT_INDICES) 37071fd2e92SBarry Smith #define PETSC_MAX_INT 2147483647 371ab824b78SBarry Smith #define PETSC_MIN_INT (-PETSC_MAX_INT - 1) 372ab824b78SBarry Smith #else 373ab824b78SBarry Smith #define PETSC_MAX_INT 9223372036854775807L 374ab824b78SBarry Smith #define PETSC_MIN_INT (-PETSC_MAX_INT - 1) 375ab824b78SBarry Smith #endif 376e489efc1SBarry Smith 377ce63c4c1SBarry Smith #if defined(PETSC_USE_REAL_SINGLE) 378ab824b78SBarry Smith # define PETSC_MAX_REAL 3.40282346638528860e+38F 379ea345e14SBarry Smith # define PETSC_MIN_REAL -PETSC_MAX_REAL 38082a7e548SBarry Smith # define PETSC_MACHINE_EPSILON 1.19209290e-07F 38182a7e548SBarry Smith # define PETSC_SQRT_MACHINE_EPSILON 3.45266983e-04F 382cf6e855fSSatish Balay # define PETSC_SMALL 1.e-5 383ce63c4c1SBarry Smith #elif defined(PETSC_USE_REAL_DOUBLE) 384ab824b78SBarry Smith # define PETSC_MAX_REAL 1.7976931348623157e+308 385ea345e14SBarry Smith # define PETSC_MIN_REAL -PETSC_MAX_REAL 38682a7e548SBarry Smith # define PETSC_MACHINE_EPSILON 2.2204460492503131e-16 38782a7e548SBarry Smith # define PETSC_SQRT_MACHINE_EPSILON 1.490116119384766e-08 388cf6e855fSSatish Balay # define PETSC_SMALL 1.e-10 389ce63c4c1SBarry Smith #elif defined(PETSC_USE_REAL___FLOAT128) 390ea345e14SBarry Smith # define PETSC_MAX_REAL FLT128_MAX 391ce63c4c1SBarry Smith # define PETSC_MIN_REAL -FLT128_MAX 392d34fcf5fSBarry Smith # define PETSC_MACHINE_EPSILON FLT128_EPSILON 393d34fcf5fSBarry Smith # define PETSC_SQRT_MACHINE_EPSILON 1.38777878078e-17 394d34fcf5fSBarry Smith # define PETSC_SMALL 1.e-20 39582adfdadSBarry Smith #endif 39682adfdadSBarry Smith 3979cf09972SJed Brown #if defined PETSC_HAVE_ADIC 3989cf09972SJed Brown /* Use MPI_Allreduce when ADIC is not available. */ 399014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGlobalMax(MPI_Comm, const PetscReal*,PetscReal*); 400014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGlobalMin(MPI_Comm, const PetscReal*,PetscReal*); 401014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGlobalSum(MPI_Comm, const PetscScalar*,PetscScalar*); 4029cf09972SJed Brown #endif 4033e523bebSBarry Smith 404014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscIsInfOrNanScalar(PetscScalar); 405014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscIsInfOrNanReal(PetscReal); 4069a25a3ccSBarry Smith 407314da920SBarry Smith /* ----------------------------------------------------------------------------*/ 40887828ca2SBarry Smith #define PassiveReal PetscReal 409ea709b57SSatish Balay #define PassiveScalar PetscScalar 410d3ecb3a7SBarry Smith 41198725619SBarry Smith /* 41298725619SBarry Smith These macros are currently hardwired to match the regular data types, so there is no support for a different 41398725619SBarry Smith MatScalar from PetscScalar. We left the MatScalar in the source just in case we use it again. 41498725619SBarry Smith */ 41598725619SBarry Smith #define MPIU_MATSCALAR MPIU_SCALAR 41698725619SBarry Smith typedef PetscScalar MatScalar; 41798725619SBarry Smith typedef PetscReal MatReal; 41898725619SBarry Smith 419e9fa29b7SSatish Balay 420e489efc1SBarry Smith #endif 421