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) 329a07f4dfSJed Brown #define PetscExpReal(a) exp(a) 339a07f4dfSJed Brown #define PetscLogReal(a) log(a) 349a07f4dfSJed Brown #define PetscSinReal(a) sin(a) 359a07f4dfSJed 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) 409a07f4dfSJed Brown #define PetscExpReal(a) exp(a) 419a07f4dfSJed Brown #define PetscLogReal(a) log(a) 429a07f4dfSJed Brown #define PetscSinReal(a) sin(a) 439a07f4dfSJed 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 52*7c2de775SJed Brown PETSC_EXTERN MPI_Datatype MPIU___FLOAT128; 53c1d390e3SJed Brown #define MPIU_REAL MPIU___FLOAT128 54c1d390e3SJed Brown typedef __float128 PetscReal; 558f1a2a5eSBarry Smith #define PetscSqrtReal(a) sqrtq(a) 569a07f4dfSJed Brown #define PetscExpReal(a) expq(a) 579a07f4dfSJed Brown #define PetscLogReal(a) logq(a) 589a07f4dfSJed Brown #define PetscSinReal(a) sinq(a) 599a07f4dfSJed Brown #define PetscCosReal(a) cosq(a) 60c1d390e3SJed Brown #endif /* PETSC_USE_REAL_* */ 6159cb5930SBarry Smith 621093a601SBarry Smith /* 631093a601SBarry Smith Complex number definitions 641093a601SBarry Smith */ 6550f81f78SJed Brown #if defined(PETSC_CLANGUAGE_CXX) && defined(PETSC_HAVE_CXX_COMPLEX) 669f20b660SSatish Balay #if defined(PETSC_USE_COMPLEX) || defined(PETSC_DESIRE_COMPLEX) 6750f81f78SJed Brown #define PETSC_HAVE_COMPLEX 1 681093a601SBarry Smith /* C++ support of complex number */ 69debe9ee2SPaul Mullowney #if defined(PETSC_HAVE_CUSP) 70debe9ee2SPaul Mullowney #define complexlib cusp 719ae82921SPaul Mullowney #include <cusp/complex.h> 72debe9ee2SPaul Mullowney #else 73debe9ee2SPaul Mullowney #define complexlib std 74debe9ee2SPaul Mullowney #include <complex> 759ae82921SPaul Mullowney #endif 76b7940d39SSatish Balay 7750f81f78SJed Brown #define PetscRealPartComplex(a) (a).real() 7850f81f78SJed Brown #define PetscImaginaryPartComplex(a) (a).imag() 7950f81f78SJed Brown #define PetscAbsComplex(a) complexlib::abs(a) 8050f81f78SJed Brown #define PetscConjComplex(a) complexlib::conj(a) 8150f81f78SJed Brown #define PetscSqrtComplex(a) complexlib::sqrt(a) 8250f81f78SJed Brown #define PetscPowComplex(a,b) complexlib::pow(a,b) 8350f81f78SJed Brown #define PetscExpComplex(a) complexlib::exp(a) 8450f81f78SJed Brown #define PetscLogComplex(a) complexlib::log(a) 8550f81f78SJed Brown #define PetscSinComplex(a) complexlib::sin(a) 8650f81f78SJed Brown #define PetscCosComplex(a) complexlib::cos(a) 87debe9ee2SPaul Mullowney 88debe9ee2SPaul Mullowney #if defined(PETSC_USE_REAL_SINGLE) 8950f81f78SJed Brown typedef complexlib::complex<float> PetscComplex; 90debe9ee2SPaul Mullowney #elif defined(PETSC_USE_REAL_DOUBLE) 9150f81f78SJed Brown typedef complexlib::complex<double> PetscComplex; 928c764dc5SJose Roman #elif defined(PETSC_USE_REAL___FLOAT128) 9350f81f78SJed Brown typedef complexlib::complex<__float128> PetscComplex; /* Notstandard and not expected to work, use __complex128 */ 94debe9ee2SPaul Mullowney #endif /* PETSC_USE_REAL_ */ 959f20b660SSatish Balay #endif /* PETSC_USE_COMPLEX && PETSC_DESIRE_COMPLEX */ 96debe9ee2SPaul Mullowney 9750f81f78SJed Brown #elif defined(PETSC_CLANGUAGE_C) && defined(PETSC_HAVE_C99_COMPLEX) 9850f81f78SJed Brown /* Use C99 _Complex for the type. Do not include complex.h by default to define "complex" because of symbol conflicts in Hypre. */ 9950f81f78SJed Brown /* Compilation units that can safely use complex should define PETSC_DESIRE_COMPLEX before including any headers */ 10050f81f78SJed Brown #if defined(PETSC_USE_COMPLEX) || defined(PETSC_DESIRE_COMPLEX) 1019f20b660SSatish Balay #define PETSC_HAVE_COMPLEX 1 102519e2a1fSPaul Mullowney #include <complex.h> 103519e2a1fSPaul Mullowney 104ce63c4c1SBarry Smith #if defined(PETSC_USE_REAL_SINGLE) 10550f81f78SJed Brown typedef float _Complex PetscComplex; 10685b47369SMatthew Knepley 10750f81f78SJed Brown #define PetscRealPartComplex(a) crealf(a) 10850f81f78SJed Brown #define PetscImaginaryPartComplex(a) cimagf(a) 10950f81f78SJed Brown #define PetscAbsComplex(a) cabsf(a) 11050f81f78SJed Brown #define PetscConjComplex(a) conjf(a) 11150f81f78SJed Brown #define PetscSqrtComplex(a) csqrtf(a) 11250f81f78SJed Brown #define PetscPowComplex(a,b) cpowf(a,b) 11350f81f78SJed Brown #define PetscExpComplex(a) cexpf(a) 11450f81f78SJed Brown #define PetscLogComplex(a) clogf(a) 11550f81f78SJed Brown #define PetscSinComplex(a) csinf(a) 11650f81f78SJed Brown #define PetscCosComplex(a) ccosf(a) 1171093a601SBarry Smith 118ce63c4c1SBarry Smith #elif defined(PETSC_USE_REAL_DOUBLE) 11950f81f78SJed Brown typedef double _Complex PetscComplex; 1201093a601SBarry Smith 12150f81f78SJed Brown #define PetscRealPartComplex(a) creal(a) 12250f81f78SJed Brown #define PetscImaginaryPartComplex(a) cimag(a) 12350f81f78SJed Brown #define PetscAbsComplex(a) cabs(a) 12450f81f78SJed Brown #define PetscConjComplex(a) conj(a) 12550f81f78SJed Brown #define PetscSqrtComplex(a) csqrt(a) 12650f81f78SJed Brown #define PetscPowComplex(a,b) cpow(a,b) 12750f81f78SJed Brown #define PetscExpComplex(a) cexp(a) 12850f81f78SJed Brown #define PetscLogComplex(a) clog(a) 12950f81f78SJed Brown #define PetscSinComplex(a) csin(a) 13050f81f78SJed Brown #define PetscCosComplex(a) ccos(a) 1311093a601SBarry Smith 1328c764dc5SJose Roman #elif defined(PETSC_USE_REAL___FLOAT128) 13350f81f78SJed Brown typedef __complex128 PetscComplex; 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 160*7c2de775SJed Brown #if defined(PETSC_HAVE_COMPLEX) 161*7c2de775SJed Brown # if defined(PETSC_USE_REAL_SINGLE) 162*7c2de775SJed Brown # define MPIU_COMPLEX MPIU_C_COMPLEX 163*7c2de775SJed Brown # elif defined(PETSC_USE_REAL_DOUBLE) 164*7c2de775SJed Brown # define MPIU_COMPLEX MPIU_C_DOUBLE_COMPLEX 165*7c2de775SJed Brown # elif defined(PETSC_USE_REAL___FLOAT128) 166*7c2de775SJed Brown # define MPIU_COMPLEX MPIU___COMPLEX128 167*7c2de775SJed Brown # endif /* PETSC_USE_REAL_* */ 168*7c2de775SJed Brown #endif 169*7c2de775SJed Brown 17050f81f78SJed Brown #if defined(PETSC_USE_COMPLEX) 17150f81f78SJed Brown typedef PetscComplex PetscScalar; 17250f81f78SJed Brown #define PetscRealPart(a) PetscRealPartComplex(a) 17350f81f78SJed Brown #define PetscImaginaryPart(a) PetscImaginaryPartComplex(a) 17450f81f78SJed Brown #define PetscAbsScalar(a) PetscAbsComplex(a) 17550f81f78SJed Brown #define PetscConj(a) PetscConjComplex(a) 17650f81f78SJed Brown #define PetscSqrtScalar(a) PetscSqrtComplex(a) 17750f81f78SJed Brown #define PetscPowScalar(a,b) PetscPowComplex(a,b) 17850f81f78SJed Brown #define PetscExpScalar(a) PetscExpComplex(a) 17950f81f78SJed Brown #define PetscLogScalar(a) PetscLogComplex(a) 18050f81f78SJed Brown #define PetscSinScalar(a) PetscSinComplex(a) 18150f81f78SJed Brown #define PetscCosScalar(a) PetscCosComplex(a) 18250f81f78SJed Brown 183*7c2de775SJed Brown #define MPIU_SCALAR MPIU_COMPLEX 18475567043SBarry Smith 1851093a601SBarry Smith /* 1861093a601SBarry Smith real number definitions 1871093a601SBarry Smith */ 1881b65fc54SMatthew G Knepley #else /* PETSC_USE_COMPLEX */ 189*7c2de775SJed Brown typedef PetscReal PetscScalar; 190*7c2de775SJed Brown #define MPIU_SCALAR MPIU_REAL 191*7c2de775SJed Brown 192329f5518SBarry Smith #define PetscRealPart(a) (a) 193c1d390e3SJed Brown #define PetscImaginaryPart(a) ((PetscReal)0.) 194c1d390e3SJed Brown PETSC_STATIC_INLINE PetscReal PetscAbsScalar(PetscScalar a) {return a < 0.0 ? -a : a;} 195e489efc1SBarry Smith #define PetscConj(a) (a) 196ce63c4c1SBarry Smith #if !defined(PETSC_USE_REAL___FLOAT128) 19718a7d68fSSatish Balay #define PetscSqrtScalar(a) sqrt(a) 198184914b5SBarry Smith #define PetscPowScalar(a,b) pow(a,b) 199184914b5SBarry Smith #define PetscExpScalar(a) exp(a) 20006c1185fSBarry Smith #define PetscLogScalar(a) log(a) 201184914b5SBarry Smith #define PetscSinScalar(a) sin(a) 202184914b5SBarry Smith #define PetscCosScalar(a) cos(a) 203ce63c4c1SBarry Smith #else /* PETSC_USE_REAL___FLOAT128 */ 2040d0cc1b5SBarry Smith #define PetscSqrtScalar(a) sqrtq(a) 2050d0cc1b5SBarry Smith #define PetscPowScalar(a,b) powq(a,b) 2060d0cc1b5SBarry Smith #define PetscExpScalar(a) expq(a) 2070d0cc1b5SBarry Smith #define PetscLogScalar(a) logq(a) 2080d0cc1b5SBarry Smith #define PetscSinScalar(a) sinq(a) 2090d0cc1b5SBarry Smith #define PetscCosScalar(a) cosq(a) 210ce63c4c1SBarry Smith #endif /* PETSC_USE_REAL___FLOAT128 */ 211b0a32e0cSBarry Smith 2121b65fc54SMatthew G Knepley #endif /* PETSC_USE_COMPLEX */ 213e489efc1SBarry Smith 214da9b6338SBarry Smith #define PetscSign(a) (((a) >= 0) ? ((a) == 0 ? 0 : 1) : -1) 21526aa1773SMatthew Knepley #define PetscAbs(a) (((a) >= 0) ? (a) : -(a)) 2163f1db9ecSBarry Smith 217314da920SBarry Smith /* --------------------------------------------------------------------------*/ 218314da920SBarry Smith 219e489efc1SBarry Smith /* 220f22f69f0SBarry Smith Certain objects may be created using either single or double precision. 221f22f69f0SBarry Smith This is currently not used. 222e489efc1SBarry Smith */ 223557d4da8SBarry Smith typedef enum { PETSC_SCALAR_DOUBLE,PETSC_SCALAR_SINGLE, PETSC_SCALAR_LONG_DOUBLE } PetscScalarPrecision; 224e489efc1SBarry Smith 22550f81f78SJed Brown #if defined(PETSC_HAVE_COMPLEX) 226e489efc1SBarry Smith /* PETSC_i is the imaginary number, i */ 22750f81f78SJed Brown PETSC_EXTERN PetscComplex PETSC_i; 22850f81f78SJed Brown #endif 229e489efc1SBarry Smith 230b6a5bde7SBarry Smith /*MC 231b6a5bde7SBarry Smith PetscMin - Returns minimum of two numbers 232b6a5bde7SBarry Smith 233eca87e8dSBarry Smith Synopsis: 234eca87e8dSBarry Smith type PetscMin(type v1,type v2) 235eca87e8dSBarry Smith 236eca87e8dSBarry Smith Not Collective 237eca87e8dSBarry Smith 238b6a5bde7SBarry Smith Input Parameter: 239b6a5bde7SBarry Smith + v1 - first value to find minimum of 240b6a5bde7SBarry Smith - v2 - second value to find minimum of 241b6a5bde7SBarry Smith 242b6a5bde7SBarry Smith 243b6a5bde7SBarry Smith Notes: type can be integer or floating point value 244b6a5bde7SBarry Smith 245b6a5bde7SBarry Smith Level: beginner 246b6a5bde7SBarry Smith 247b6a5bde7SBarry Smith 248d9a4bb16SJed Brown .seealso: PetscMin(), PetscClipInterval(), PetscAbsInt(), PetscAbsReal(), PetscSqr() 249b6a5bde7SBarry Smith 250b6a5bde7SBarry Smith M*/ 251e489efc1SBarry Smith #define PetscMin(a,b) (((a)<(b)) ? (a) : (b)) 252b6a5bde7SBarry Smith 253b6a5bde7SBarry Smith /*MC 254b6a5bde7SBarry Smith PetscMax - Returns maxium of two numbers 255b6a5bde7SBarry Smith 256eca87e8dSBarry Smith Synopsis: 257eca87e8dSBarry Smith type max PetscMax(type v1,type v2) 258eca87e8dSBarry Smith 259eca87e8dSBarry Smith Not Collective 260eca87e8dSBarry Smith 261b6a5bde7SBarry Smith Input Parameter: 262b6a5bde7SBarry Smith + v1 - first value to find maximum of 263b6a5bde7SBarry Smith - v2 - second value to find maximum of 264b6a5bde7SBarry Smith 265b6a5bde7SBarry Smith Notes: type can be integer or floating point value 266b6a5bde7SBarry Smith 267b6a5bde7SBarry Smith Level: beginner 268b6a5bde7SBarry Smith 269d9a4bb16SJed Brown .seealso: PetscMin(), PetscClipInterval(), PetscAbsInt(), PetscAbsReal(), PetscSqr() 270b6a5bde7SBarry Smith 271b6a5bde7SBarry Smith M*/ 272e489efc1SBarry Smith #define PetscMax(a,b) (((a)<(b)) ? (b) : (a)) 273b6a5bde7SBarry Smith 274b6a5bde7SBarry Smith /*MC 275d9a4bb16SJed Brown PetscClipInterval - Returns a number clipped to be within an interval 276d9a4bb16SJed Brown 277d9a4bb16SJed Brown Synopsis: 278d9a4bb16SJed Brown type clip PetscClipInterval(type x,type a,type b) 279d9a4bb16SJed Brown 280d9a4bb16SJed Brown Not Collective 281d9a4bb16SJed Brown 282d9a4bb16SJed Brown Input Parameter: 283d9a4bb16SJed Brown + x - value to use if within interval (a,b) 284d9a4bb16SJed Brown . a - lower end of interval 285d9a4bb16SJed Brown - b - upper end of interval 286d9a4bb16SJed Brown 287d9a4bb16SJed Brown Notes: type can be integer or floating point value 288d9a4bb16SJed Brown 289d9a4bb16SJed Brown Level: beginner 290d9a4bb16SJed Brown 291d9a4bb16SJed Brown .seealso: PetscMin(), PetscMax(), PetscAbsInt(), PetscAbsReal(), PetscSqr() 292d9a4bb16SJed Brown 293d9a4bb16SJed Brown M*/ 294d9a4bb16SJed Brown #define PetscClipInterval(x,a,b) (PetscMax((a),PetscMin((x),(b)))) 295d9a4bb16SJed Brown 296d9a4bb16SJed Brown /*MC 297b6a5bde7SBarry Smith PetscAbsInt - Returns the absolute value of an integer 298b6a5bde7SBarry Smith 299b6a5bde7SBarry Smith Synopsis: 300b6a5bde7SBarry Smith int abs PetscAbsInt(int v1) 301b6a5bde7SBarry Smith 302eca87e8dSBarry Smith Not Collective 303eca87e8dSBarry Smith 304eca87e8dSBarry Smith Input Parameter: 305eca87e8dSBarry Smith . v1 - the integer 306b6a5bde7SBarry Smith 307b6a5bde7SBarry Smith Level: beginner 308b6a5bde7SBarry Smith 309b6a5bde7SBarry Smith .seealso: PetscMax(), PetscMin(), PetscAbsReal(), PetscSqr() 310b6a5bde7SBarry Smith 311b6a5bde7SBarry Smith M*/ 312e489efc1SBarry Smith #define PetscAbsInt(a) (((a)<0) ? -(a) : (a)) 313b6a5bde7SBarry Smith 314b6a5bde7SBarry Smith /*MC 315b6a5bde7SBarry Smith PetscAbsReal - Returns the absolute value of an real number 316b6a5bde7SBarry Smith 317eca87e8dSBarry Smith Synopsis: 318eca87e8dSBarry Smith Real abs PetscAbsReal(PetscReal v1) 319eca87e8dSBarry Smith 320eca87e8dSBarry Smith Not Collective 321eca87e8dSBarry Smith 322b6a5bde7SBarry Smith Input Parameter: 323b6a5bde7SBarry Smith . v1 - the double 324b6a5bde7SBarry Smith 325b6a5bde7SBarry Smith 326b6a5bde7SBarry Smith Level: beginner 327b6a5bde7SBarry Smith 328b6a5bde7SBarry Smith .seealso: PetscMax(), PetscMin(), PetscAbsInt(), PetscSqr() 329b6a5bde7SBarry Smith 330b6a5bde7SBarry Smith M*/ 331f6275e2eSBarry Smith #define PetscAbsReal(a) (((a)<0) ? -(a) : (a)) 332b6a5bde7SBarry Smith 333b6a5bde7SBarry Smith /*MC 334b6a5bde7SBarry Smith PetscSqr - Returns the square of a number 335b6a5bde7SBarry Smith 336b6a5bde7SBarry Smith Synopsis: 337b6a5bde7SBarry Smith type sqr PetscSqr(type v1) 338b6a5bde7SBarry Smith 339eca87e8dSBarry Smith Not Collective 340eca87e8dSBarry Smith 341eca87e8dSBarry Smith Input Parameter: 342eca87e8dSBarry Smith . v1 - the value 343eca87e8dSBarry Smith 344b6a5bde7SBarry Smith Notes: type can be integer or floating point value 345b6a5bde7SBarry Smith 346b6a5bde7SBarry Smith Level: beginner 347b6a5bde7SBarry Smith 348b6a5bde7SBarry Smith .seealso: PetscMax(), PetscMin(), PetscAbsInt(), PetscAbsReal() 349b6a5bde7SBarry Smith 350b6a5bde7SBarry Smith M*/ 3514ebda54eSMatthew Knepley #define PetscSqr(a) ((a)*(a)) 352e489efc1SBarry Smith 353314da920SBarry Smith /* ----------------------------------------------------------------------------*/ 354314da920SBarry Smith /* 355d34fcf5fSBarry Smith Basic constants 356314da920SBarry Smith */ 357ce63c4c1SBarry Smith #if defined(PETSC_USE_REAL___FLOAT128) 358d34fcf5fSBarry Smith #define PETSC_PI M_PIq 359d34fcf5fSBarry Smith #elif defined(M_PI) 360d34fcf5fSBarry Smith #define PETSC_PI M_PI 361d34fcf5fSBarry Smith #else 362faa6e9b0SMatthew G Knepley #define PETSC_PI 3.14159265358979323846264338327950288419716939937510582 363d34fcf5fSBarry Smith #endif 364d34fcf5fSBarry Smith 365ab824b78SBarry Smith #if !defined(PETSC_USE_64BIT_INDICES) 36671fd2e92SBarry Smith #define PETSC_MAX_INT 2147483647 367ab824b78SBarry Smith #define PETSC_MIN_INT (-PETSC_MAX_INT - 1) 368ab824b78SBarry Smith #else 369ab824b78SBarry Smith #define PETSC_MAX_INT 9223372036854775807L 370ab824b78SBarry Smith #define PETSC_MIN_INT (-PETSC_MAX_INT - 1) 371ab824b78SBarry Smith #endif 372e489efc1SBarry Smith 373ce63c4c1SBarry Smith #if defined(PETSC_USE_REAL_SINGLE) 374ab824b78SBarry Smith # define PETSC_MAX_REAL 3.40282346638528860e+38F 375ea345e14SBarry Smith # define PETSC_MIN_REAL -PETSC_MAX_REAL 37682a7e548SBarry Smith # define PETSC_MACHINE_EPSILON 1.19209290e-07F 37782a7e548SBarry Smith # define PETSC_SQRT_MACHINE_EPSILON 3.45266983e-04F 378cf6e855fSSatish Balay # define PETSC_SMALL 1.e-5 379ce63c4c1SBarry Smith #elif defined(PETSC_USE_REAL_DOUBLE) 380ab824b78SBarry Smith # define PETSC_MAX_REAL 1.7976931348623157e+308 381ea345e14SBarry Smith # define PETSC_MIN_REAL -PETSC_MAX_REAL 38282a7e548SBarry Smith # define PETSC_MACHINE_EPSILON 2.2204460492503131e-16 38382a7e548SBarry Smith # define PETSC_SQRT_MACHINE_EPSILON 1.490116119384766e-08 384cf6e855fSSatish Balay # define PETSC_SMALL 1.e-10 385ce63c4c1SBarry Smith #elif defined(PETSC_USE_REAL___FLOAT128) 386ea345e14SBarry Smith # define PETSC_MAX_REAL FLT128_MAX 387ce63c4c1SBarry Smith # define PETSC_MIN_REAL -FLT128_MAX 388d34fcf5fSBarry Smith # define PETSC_MACHINE_EPSILON FLT128_EPSILON 389d34fcf5fSBarry Smith # define PETSC_SQRT_MACHINE_EPSILON 1.38777878078e-17 390d34fcf5fSBarry Smith # define PETSC_SMALL 1.e-20 39182adfdadSBarry Smith #endif 39282adfdadSBarry Smith 3939cf09972SJed Brown #if defined PETSC_HAVE_ADIC 3949cf09972SJed Brown /* Use MPI_Allreduce when ADIC is not available. */ 395014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGlobalMax(MPI_Comm, const PetscReal*,PetscReal*); 396014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGlobalMin(MPI_Comm, const PetscReal*,PetscReal*); 397014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGlobalSum(MPI_Comm, const PetscScalar*,PetscScalar*); 3989cf09972SJed Brown #endif 3993e523bebSBarry Smith 400014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscIsInfOrNanScalar(PetscScalar); 401014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscIsInfOrNanReal(PetscReal); 4029a25a3ccSBarry Smith 403314da920SBarry Smith /* ----------------------------------------------------------------------------*/ 40487828ca2SBarry Smith #define PassiveReal PetscReal 405ea709b57SSatish Balay #define PassiveScalar PetscScalar 406d3ecb3a7SBarry Smith 40798725619SBarry Smith /* 40898725619SBarry Smith These macros are currently hardwired to match the regular data types, so there is no support for a different 40998725619SBarry Smith MatScalar from PetscScalar. We left the MatScalar in the source just in case we use it again. 41098725619SBarry Smith */ 41198725619SBarry Smith #define MPIU_MATSCALAR MPIU_SCALAR 41298725619SBarry Smith typedef PetscScalar MatScalar; 41398725619SBarry Smith typedef PetscReal MatReal; 41498725619SBarry Smith 415e9fa29b7SSatish Balay 416e489efc1SBarry Smith #endif 417