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 15314da920SBarry Smith /* 16f4ccad53SBarry Smith 17f4ccad53SBarry Smith Defines operations that are different for complex and real numbers; 18a5057860SBarry Smith note that one cannot mix the use of complex and real in the same 19f4ccad53SBarry Smith PETSc program. All PETSc objects in one program are built around the object 2098725619SBarry Smith PetscScalar which is either always a real or a complex. 21f4ccad53SBarry Smith 22e489efc1SBarry Smith */ 23b36a9721SBarry Smith 24c1d390e3SJed Brown #if defined(PETSC_USE_REAL_SINGLE) 25c1d390e3SJed Brown #define MPIU_REAL MPI_FLOAT 26c1d390e3SJed Brown typedef float PetscReal; 279cf33046SSatish Balay #define PetscSqrtReal(a) sqrt(a) 289a07f4dfSJed Brown #define PetscExpReal(a) exp(a) 299a07f4dfSJed Brown #define PetscLogReal(a) log(a) 3077b4d14cSPeter Brune #define PetscLog10Real(a) log10(a) 3178a59e97SMatthew G. Knepley #ifdef PETSC_HAVE_LOG2 3278a59e97SMatthew G. Knepley #define PetscLog2Real(a) log2(a) 3378a59e97SMatthew G. Knepley #endif 349a07f4dfSJed Brown #define PetscSinReal(a) sin(a) 359a07f4dfSJed Brown #define PetscCosReal(a) cos(a) 36a4bea5a6SPeter Brune #define PetscTanReal(a) tan(a) 37255453a1SBarry Smith #define PetscAsinReal(a) asin(a) 38255453a1SBarry Smith #define PetscAcosReal(a) acos(a) 39a4bea5a6SPeter Brune #define PetscAtanReal(a) atan(a) 401d5abddaSDmitry Karpeev #define PetscAtan2Real(a,b) atan2(a,b) 41a4bea5a6SPeter Brune #define PetscSinhReal(a) sinh(a) 42a4bea5a6SPeter Brune #define PetscCoshReal(a) cosh(a) 43a4bea5a6SPeter Brune #define PetscTanhReal(a) tanh(a) 44369cc0aeSBarry Smith #define PetscPowReal(a,b) pow(a,b) 4577b4d14cSPeter Brune #define PetscCeilReal(a) ceil(a) 4677b4d14cSPeter Brune #define PetscFloorReal(a) floor(a) 47a4bea5a6SPeter Brune #define PetscFmodReal(a,b) fmod(a,b) 4843f0d3baSJed Brown #define PetscTGamma(a) tgammaf(a) 49c1d390e3SJed Brown #elif defined(PETSC_USE_REAL_DOUBLE) 50c1d390e3SJed Brown #define MPIU_REAL MPI_DOUBLE 51c1d390e3SJed Brown typedef double PetscReal; 528f1a2a5eSBarry Smith #define PetscSqrtReal(a) sqrt(a) 539a07f4dfSJed Brown #define PetscExpReal(a) exp(a) 549a07f4dfSJed Brown #define PetscLogReal(a) log(a) 5577b4d14cSPeter Brune #define PetscLog10Real(a) log10(a) 5678a59e97SMatthew G. Knepley #ifdef PETSC_HAVE_LOG2 5778a59e97SMatthew G. Knepley #define PetscLog2Real(a) log2(a) 5878a59e97SMatthew G. Knepley #endif 599a07f4dfSJed Brown #define PetscSinReal(a) sin(a) 609a07f4dfSJed Brown #define PetscCosReal(a) cos(a) 61a4bea5a6SPeter Brune #define PetscTanReal(a) tan(a) 62255453a1SBarry Smith #define PetscAsinReal(a) asin(a) 63255453a1SBarry Smith #define PetscAcosReal(a) acos(a) 64a4bea5a6SPeter Brune #define PetscAtanReal(a) atan(a) 651d5abddaSDmitry Karpeev #define PetscAtan2Real(a,b) atan2(a,b) 668d1b9be0SJed Brown #define PetscSinhReal(a) sinh(a) 678d1b9be0SJed Brown #define PetscCoshReal(a) cosh(a) 688d1b9be0SJed Brown #define PetscTanhReal(a) tanh(a) 69369cc0aeSBarry Smith #define PetscPowReal(a,b) pow(a,b) 7077b4d14cSPeter Brune #define PetscCeilReal(a) ceil(a) 7177b4d14cSPeter Brune #define PetscFloorReal(a) floor(a) 72a4bea5a6SPeter Brune #define PetscFmodReal(a,b) fmod(a,b) 730646a658SBarry Smith #define PetscTGamma(a) tgamma(a) 74c1d390e3SJed Brown #elif defined(PETSC_USE_REAL___FLOAT128) 75574fde7bSSatish Balay #if defined(__cplusplus) 76574fde7bSSatish Balay extern "C" { 77574fde7bSSatish Balay #endif 78574fde7bSSatish Balay #include <quadmath.h> 79574fde7bSSatish Balay #if defined(__cplusplus) 80574fde7bSSatish Balay } 81574fde7bSSatish Balay #endif 828ad47952SJed Brown PETSC_EXTERN MPI_Datatype MPIU___FLOAT128 PetscAttrMPITypeTag(__float128); 83c1d390e3SJed Brown #define MPIU_REAL MPIU___FLOAT128 84c1d390e3SJed Brown typedef __float128 PetscReal; 858f1a2a5eSBarry Smith #define PetscSqrtReal(a) sqrtq(a) 869a07f4dfSJed Brown #define PetscExpReal(a) expq(a) 879a07f4dfSJed Brown #define PetscLogReal(a) logq(a) 8877b4d14cSPeter Brune #define PetscLog10Real(a) log10q(a) 8978a59e97SMatthew G. Knepley #ifdef PETSC_HAVE_LOG2 9078a59e97SMatthew G. Knepley #define PetscLog2Real(a) log2q(a) 9178a59e97SMatthew G. Knepley #endif 929a07f4dfSJed Brown #define PetscSinReal(a) sinq(a) 939a07f4dfSJed Brown #define PetscCosReal(a) cosq(a) 94a4bea5a6SPeter Brune #define PetscTanReal(a) tanq(a) 95255453a1SBarry Smith #define PetscAsinReal(a) asinq(a) 96255453a1SBarry Smith #define PetscAcosReal(a) acosq(a) 97a4bea5a6SPeter Brune #define PetscAtanReal(a) atanq(a) 981d5abddaSDmitry Karpeev #define PetscAtan2Real(a,b) atan2q(a,b) 998d1b9be0SJed Brown #define PetscSinhReal(a) sinhq(a) 1008d1b9be0SJed Brown #define PetscCoshReal(a) coshq(a) 1018d1b9be0SJed Brown #define PetscTanhReal(a) tanhq(a) 102369cc0aeSBarry Smith #define PetscPowReal(a,b) powq(a,b) 10377b4d14cSPeter Brune #define PetscCeilReal(a) ceilq(a) 10477b4d14cSPeter Brune #define PetscFloorReal(a) floorq(a) 105a4bea5a6SPeter Brune #define PetscFmodReal(a,b) fmodq(a,b) 1060646a658SBarry Smith #define PetscTGamma(a) tgammaq(a) 107570b7f6dSBarry Smith #elif defined(PETSC_USE_REAL___FP16) 108570b7f6dSBarry Smith PETSC_EXTERN MPI_Datatype MPIU___FP16 PetscAttrMPITypeTag(__fp16); 109570b7f6dSBarry Smith #define MPIU_REAL MPIU___FP16 110570b7f6dSBarry Smith typedef __fp16 PetscReal; 111570b7f6dSBarry Smith #define PetscSqrtReal(a) sqrtf(a) 112570b7f6dSBarry Smith #define PetscExpReal(a) expf(a) 113570b7f6dSBarry Smith #define PetscLogReal(a) logf(a) 114570b7f6dSBarry Smith #define PetscLog10Real(a) log10f(a) 115570b7f6dSBarry Smith #ifdef PETSC_HAVE_LOG2 116570b7f6dSBarry Smith #define PetscLog2Real(a) log2f(a) 117570b7f6dSBarry Smith #endif 118570b7f6dSBarry Smith #define PetscSinReal(a) sinf(a) 119570b7f6dSBarry Smith #define PetscCosReal(a) cosf(a) 120570b7f6dSBarry Smith #define PetscTanReal(a) tanf(a) 121570b7f6dSBarry Smith #define PetscAsinReal(a) asinf(a) 122570b7f6dSBarry Smith #define PetscAcosReal(a) acosf(a) 123570b7f6dSBarry Smith #define PetscAtanReal(a) atanf(a) 124570b7f6dSBarry Smith #define PetscAtan2Real(a,b) atan2f(a,b) 125570b7f6dSBarry Smith #define PetscSinhReal(a) sinhf(a) 126570b7f6dSBarry Smith #define PetscCoshReal(a) coshf(a) 127570b7f6dSBarry Smith #define PetscTanhReal(a) tanhf(a) 128570b7f6dSBarry Smith #define PetscPowReal(a,b) powf(a,b) 129570b7f6dSBarry Smith #define PetscCeilReal(a) ceilf(a) 130570b7f6dSBarry Smith #define PetscFloorReal(a) floorf(a) 131570b7f6dSBarry Smith #define PetscFmodReal(a,b) fmodf(a,b) 132570b7f6dSBarry Smith #define PetscTGamma(a) tgammaf(a) 133c1d390e3SJed Brown #endif /* PETSC_USE_REAL_* */ 13459cb5930SBarry Smith 1351093a601SBarry Smith /* 1361093a601SBarry Smith Complex number definitions 1371093a601SBarry Smith */ 1382f217381SBarry Smith #if defined(__cplusplus) && defined(PETSC_HAVE_CXX_COMPLEX) && !defined(PETSC_USE_REAL___FLOAT128) 1398cd53115SBarry Smith #if !defined(PETSC_SKIP_COMPLEX) 14050f81f78SJed Brown #define PETSC_HAVE_COMPLEX 1 1411093a601SBarry Smith /* C++ support of complex number */ 142debe9ee2SPaul Mullowney #if defined(PETSC_HAVE_CUSP) 143debe9ee2SPaul Mullowney #define complexlib cusp 1449ae82921SPaul Mullowney #include <cusp/complex.h> 145fda01a78SKarl Rupp #elif defined(PETSC_HAVE_VECCUDA) && __CUDACC_VER_MAJOR__ > 6 146fda01a78SKarl Rupp /* complex headers in thrust only available in CUDA 7.0 and above */ 147ec42abe4SAlejandro Lamas Daviña #define complexlib thrust 148ec42abe4SAlejandro Lamas Daviña #include <thrust/complex.h> 149debe9ee2SPaul Mullowney #else 150debe9ee2SPaul Mullowney #define complexlib std 151debe9ee2SPaul Mullowney #include <complex> 1529ae82921SPaul Mullowney #endif 153b7940d39SSatish Balay 15450f81f78SJed Brown #define PetscRealPartComplex(a) (a).real() 15550f81f78SJed Brown #define PetscImaginaryPartComplex(a) (a).imag() 15650f81f78SJed Brown #define PetscAbsComplex(a) complexlib::abs(a) 15750f81f78SJed Brown #define PetscConjComplex(a) complexlib::conj(a) 15850f81f78SJed Brown #define PetscSqrtComplex(a) complexlib::sqrt(a) 15950f81f78SJed Brown #define PetscPowComplex(a,b) complexlib::pow(a,b) 16050f81f78SJed Brown #define PetscExpComplex(a) complexlib::exp(a) 16150f81f78SJed Brown #define PetscLogComplex(a) complexlib::log(a) 16250f81f78SJed Brown #define PetscSinComplex(a) complexlib::sin(a) 16350f81f78SJed Brown #define PetscCosComplex(a) complexlib::cos(a) 164255453a1SBarry Smith #define PetscAsinComplex(a) complexlib::asin(a) 165255453a1SBarry Smith #define PetscAcosComplex(a) complexlib::acos(a) 166027d9794SBarry Smith #if defined(PETSC_HAVE_TANCOMPLEX) 167a4bea5a6SPeter Brune #define PetscTanComplex(a) complexlib::tan(a) 168027d9794SBarry Smith #else 169027d9794SBarry Smith #define PetscTanComplex(a) PetscSinComplex(a)/PetscCosComplex(a) 170027d9794SBarry Smith #endif 171a4bea5a6SPeter Brune #define PetscSinhComplex(a) complexlib::sinh(a) 172a4bea5a6SPeter Brune #define PetscCoshComplex(a) complexlib::cosh(a) 173027d9794SBarry Smith #if defined(PETSC_HAVE_TANHCOMPLEX) 174a4bea5a6SPeter Brune #define PetscTanhComplex(a) complexlib::tanh(a) 175027d9794SBarry Smith #else 176027d9794SBarry Smith #define PetscTanhComplex(a) PetscSinhComplex(a)/PetscCoshComplex(a) 177027d9794SBarry Smith #endif 178debe9ee2SPaul Mullowney 179debe9ee2SPaul Mullowney #if defined(PETSC_USE_REAL_SINGLE) 18050f81f78SJed Brown typedef complexlib::complex<float> PetscComplex; 1813be776deSLisandro Dalcin #if defined(PETSC_USE_CXX_COMPLEX_FLOAT_WORKAROUND) 1823be776deSLisandro Dalcin static inline PetscComplex operator+(const PetscComplex& lhs, const double& rhs) { return lhs + float(rhs); } 1833be776deSLisandro Dalcin static inline PetscComplex operator+(const double& lhs, const PetscComplex& rhs) { return float(lhs) + rhs; } 1843be776deSLisandro Dalcin static inline PetscComplex operator-(const PetscComplex& lhs, const double& rhs) { return lhs - float(rhs); } 1853be776deSLisandro Dalcin static inline PetscComplex operator-(const double& lhs, const PetscComplex& rhs) { return float(lhs) - rhs; } 1863be776deSLisandro Dalcin static inline PetscComplex operator*(const PetscComplex& lhs, const double& rhs) { return lhs * float(rhs); } 1873be776deSLisandro Dalcin static inline PetscComplex operator*(const double& lhs, const PetscComplex& rhs) { return float(lhs) * rhs; } 1883be776deSLisandro Dalcin static inline PetscComplex operator/(const PetscComplex& lhs, const double& rhs) { return lhs / float(rhs); } 1893be776deSLisandro Dalcin static inline PetscComplex operator/(const double& lhs, const PetscComplex& rhs) { return float(lhs) / rhs; } 1903be776deSLisandro Dalcin static inline bool operator==(const PetscComplex& lhs, const double& rhs) { return lhs.imag() == float(0) && lhs.real() == float(rhs); } 1913be776deSLisandro Dalcin static inline bool operator==(const double& lhs, const PetscComplex& rhs) { return rhs.imag() == float(0) && rhs.real() == float(lhs); } 1923be776deSLisandro Dalcin static inline bool operator!=(const PetscComplex& lhs, const double& rhs) { return lhs.imag() != float(0) || lhs.real() != float(rhs); } 1933be776deSLisandro Dalcin static inline bool operator!=(const double& lhs, const PetscComplex& rhs) { return rhs.imag() != float(0) || rhs.real() != float(lhs); } 1943be776deSLisandro Dalcin #endif /* PETSC_USE_CXX_COMPLEX_FLOAT_WORKAROUND */ 195debe9ee2SPaul Mullowney #elif defined(PETSC_USE_REAL_DOUBLE) 19650f81f78SJed Brown typedef complexlib::complex<double> PetscComplex; 1971a9c6b96SLisandro Dalcin #if defined(PETSC_USE_CXX_COMPLEX_FLOAT_WORKAROUND) 1981a9c6b96SLisandro Dalcin static inline PetscComplex operator+(const PetscComplex& lhs, const PetscInt& rhs) { return lhs + double(rhs); } 1991a9c6b96SLisandro Dalcin static inline PetscComplex operator+(const PetscInt& lhs, const PetscComplex& rhs) { return double(lhs) + rhs; } 2001a9c6b96SLisandro Dalcin static inline PetscComplex operator-(const PetscComplex& lhs, const PetscInt& rhs) { return lhs - double(rhs); } 2011a9c6b96SLisandro Dalcin static inline PetscComplex operator-(const PetscInt& lhs, const PetscComplex& rhs) { return double(lhs) - rhs; } 2021a9c6b96SLisandro Dalcin static inline PetscComplex operator*(const PetscComplex& lhs, const PetscInt& rhs) { return lhs * double(rhs); } 2031a9c6b96SLisandro Dalcin static inline PetscComplex operator*(const PetscInt& lhs, const PetscComplex& rhs) { return double(lhs) * rhs; } 2041a9c6b96SLisandro Dalcin static inline PetscComplex operator/(const PetscComplex& lhs, const PetscInt& rhs) { return lhs / double(rhs); } 2051a9c6b96SLisandro Dalcin static inline PetscComplex operator/(const PetscInt& lhs, const PetscComplex& rhs) { return double(lhs) / rhs; } 2061a9c6b96SLisandro Dalcin static inline bool operator==(const PetscComplex& lhs, const PetscInt& rhs) { return lhs.imag() == double(0) && lhs.real() == double(rhs); } 2071a9c6b96SLisandro Dalcin static inline bool operator==(const PetscInt& lhs, const PetscComplex& rhs) { return rhs.imag() == double(0) && rhs.real() == double(lhs); } 2081a9c6b96SLisandro Dalcin static inline bool operator!=(const PetscComplex& lhs, const PetscInt& rhs) { return lhs.imag() != double(0) || lhs.real() != double(rhs); } 2091a9c6b96SLisandro Dalcin static inline bool operator!=(const PetscInt& lhs, const PetscComplex& rhs) { return rhs.imag() != double(0) || rhs.real() != double(lhs); } 2101a9c6b96SLisandro Dalcin #endif /* PETSC_USE_CXX_COMPLEX_FLOAT_WORKAROUND */ 2118c764dc5SJose Roman #elif defined(PETSC_USE_REAL___FLOAT128) 21250f81f78SJed Brown typedef complexlib::complex<__float128> PetscComplex; /* Notstandard and not expected to work, use __complex128 */ 21322b3908eSBarry Smith PETSC_EXTERN MPI_Datatype MPIU___COMPLEX128; 214debe9ee2SPaul Mullowney #endif /* PETSC_USE_REAL_ */ 2158cd53115SBarry Smith #endif /* ! PETSC_SKIP_COMPLEX */ 216debe9ee2SPaul Mullowney 217570b7f6dSBarry Smith #elif !defined(__cplusplus) && defined(PETSC_HAVE_C99_COMPLEX) && !defined(PETSC_USE_REAL___FP16) 2188cd53115SBarry Smith #if !defined(PETSC_SKIP_COMPLEX) 2199f20b660SSatish Balay #define PETSC_HAVE_COMPLEX 1 220519e2a1fSPaul Mullowney #include <complex.h> 221519e2a1fSPaul Mullowney 222570b7f6dSBarry Smith #if defined(PETSC_USE_REAL_SINGLE) || defined(PETSC_USE_REAL___FP16) 22350f81f78SJed Brown typedef float _Complex PetscComplex; 22485b47369SMatthew Knepley 22550f81f78SJed Brown #define PetscRealPartComplex(a) crealf(a) 22650f81f78SJed Brown #define PetscImaginaryPartComplex(a) cimagf(a) 22750f81f78SJed Brown #define PetscAbsComplex(a) cabsf(a) 22850f81f78SJed Brown #define PetscConjComplex(a) conjf(a) 22950f81f78SJed Brown #define PetscSqrtComplex(a) csqrtf(a) 23050f81f78SJed Brown #define PetscPowComplex(a,b) cpowf(a,b) 23150f81f78SJed Brown #define PetscExpComplex(a) cexpf(a) 23250f81f78SJed Brown #define PetscLogComplex(a) clogf(a) 23350f81f78SJed Brown #define PetscSinComplex(a) csinf(a) 23450f81f78SJed Brown #define PetscCosComplex(a) ccosf(a) 235255453a1SBarry Smith #define PetscAsinComplex(a) casinf(a) 236255453a1SBarry Smith #define PetscAcosComplex(a) cacosf(a) 237a4bea5a6SPeter Brune #define PetscTanComplex(a) ctanf(a) 238a4bea5a6SPeter Brune #define PetscSinhComplex(a) csinhf(a) 239a4bea5a6SPeter Brune #define PetscCoshComplex(a) ccoshf(a) 240a4bea5a6SPeter Brune #define PetscTanhComplex(a) ctanhf(a) 2411093a601SBarry Smith 242ce63c4c1SBarry Smith #elif defined(PETSC_USE_REAL_DOUBLE) 24350f81f78SJed Brown typedef double _Complex PetscComplex; 2441093a601SBarry Smith 24550f81f78SJed Brown #define PetscRealPartComplex(a) creal(a) 24650f81f78SJed Brown #define PetscImaginaryPartComplex(a) cimag(a) 24750f81f78SJed Brown #define PetscAbsComplex(a) cabs(a) 24850f81f78SJed Brown #define PetscConjComplex(a) conj(a) 24950f81f78SJed Brown #define PetscSqrtComplex(a) csqrt(a) 25050f81f78SJed Brown #define PetscPowComplex(a,b) cpow(a,b) 25150f81f78SJed Brown #define PetscExpComplex(a) cexp(a) 25250f81f78SJed Brown #define PetscLogComplex(a) clog(a) 25350f81f78SJed Brown #define PetscSinComplex(a) csin(a) 25450f81f78SJed Brown #define PetscCosComplex(a) ccos(a) 255255453a1SBarry Smith #define PetscAsinComplex(a) casin(a) 256255453a1SBarry Smith #define PetscAcosComplex(a) cacos(a) 257a4bea5a6SPeter Brune #define PetscTanComplex(a) ctan(a) 258a4bea5a6SPeter Brune #define PetscSinhComplex(a) csinh(a) 259a4bea5a6SPeter Brune #define PetscCoshComplex(a) ccosh(a) 260a4bea5a6SPeter Brune #define PetscTanhComplex(a) ctanh(a) 2611093a601SBarry Smith 2628c764dc5SJose Roman #elif defined(PETSC_USE_REAL___FLOAT128) 26350f81f78SJed Brown typedef __complex128 PetscComplex; 2648ad47952SJed Brown PETSC_EXTERN MPI_Datatype MPIU___COMPLEX128 PetscAttrMPITypeTag(__complex128); 2658c764dc5SJose Roman 26650f81f78SJed Brown #define PetscRealPartComplex(a) crealq(a) 26750f81f78SJed Brown #define PetscImaginaryPartComplex(a) cimagq(a) 26850f81f78SJed Brown #define PetscAbsComplex(a) cabsq(a) 26950f81f78SJed Brown #define PetscConjComplex(a) conjq(a) 27050f81f78SJed Brown #define PetscSqrtComplex(a) csqrtq(a) 27150f81f78SJed Brown #define PetscPowComplex(a,b) cpowq(a,b) 27250f81f78SJed Brown #define PetscExpComplex(a) cexpq(a) 27350f81f78SJed Brown #define PetscLogComplex(a) clogq(a) 27450f81f78SJed Brown #define PetscSinComplex(a) csinq(a) 27550f81f78SJed Brown #define PetscCosComplex(a) ccosq(a) 276255453a1SBarry Smith #define PetscAsinComplex(a) casinq(a) 277255453a1SBarry Smith #define PetscAcosComplex(a) cacosq(a) 278a4bea5a6SPeter Brune #define PetscTanComplex(a) ctanq(a) 279a4bea5a6SPeter Brune #define PetscSinhComplex(a) csinhq(a) 280a4bea5a6SPeter Brune #define PetscCoshComplex(a) ccoshq(a) 281a4bea5a6SPeter Brune #define PetscTanhComplex(a) ctanhq(a) 282a4bea5a6SPeter Brune 283ce63c4c1SBarry Smith #endif /* PETSC_USE_REAL_* */ 284d4161b4aSBarry Smith #elif (defined(PETSC_USE_COMPLEX) && !defined(PETSC_SKIP_COMPLEX)) 28550f81f78SJed Brown #error "PETSc was configured --with-scalar-type=complex, but a language-appropriate complex library is not available" 2868cd53115SBarry Smith #endif /* !PETSC_SKIP_COMPLEX */ 2872f217381SBarry Smith #endif /* (__cplusplus && PETSC_HAVE_CXX_COMPLEX) else-if (!__cplusplus && PETSC_HAVE_C99_COMPLEX) */ 288e489efc1SBarry Smith 2898dc6f2c2SJed Brown #if defined(PETSC_HAVE_COMPLEX) 29070da9c3bSJed Brown #if defined(PETSC_HAVE_MPI_C_DOUBLE_COMPLEX) 291500d8756SSatish Balay #define MPIU_C_DOUBLE_COMPLEX MPI_C_DOUBLE_COMPLEX 292500d8756SSatish Balay #define MPIU_C_COMPLEX MPI_C_COMPLEX 29370da9c3bSJed Brown #else 2942f217381SBarry Smith # if defined(__cplusplus) && defined(PETSC_HAVE_CXX_COMPLEX) 2958ad47952SJed Brown typedef complexlib::complex<double> petsc_mpiu_c_double_complex; 2968ad47952SJed Brown typedef complexlib::complex<float> petsc_mpiu_c_complex; 2972f217381SBarry Smith # elif !defined(__cplusplus) && defined(PETSC_HAVE_C99_COMPLEX) 2988ad47952SJed Brown typedef double _Complex petsc_mpiu_c_double_complex; 2998ad47952SJed Brown typedef float _Complex petsc_mpiu_c_complex; 3008ad47952SJed Brown # else 3018ad47952SJed Brown typedef struct {double real,imag;} petsc_mpiu_c_double_complex; 3028ad47952SJed Brown typedef struct {float real,imag;} petsc_mpiu_c_complex; 3038ad47952SJed Brown # endif 3048ad47952SJed Brown PETSC_EXTERN MPI_Datatype MPIU_C_DOUBLE_COMPLEX PetscAttrMPITypeTagLayoutCompatible(petsc_mpiu_c_double_complex); 3058ad47952SJed Brown PETSC_EXTERN MPI_Datatype MPIU_C_COMPLEX PetscAttrMPITypeTagLayoutCompatible(petsc_mpiu_c_complex); 3061b65fc54SMatthew G Knepley #endif /* PETSC_HAVE_MPI_C_DOUBLE_COMPLEX */ 3078dc6f2c2SJed Brown #endif /* PETSC_HAVE_COMPLEX */ 3082c876bd9SBarry Smith 3097c2de775SJed Brown #if defined(PETSC_HAVE_COMPLEX) 310570b7f6dSBarry Smith # if defined(PETSC_USE_REAL_SINGLE) || defined(PETSC_USE_REAL___FP16) 3117c2de775SJed Brown # define MPIU_COMPLEX MPIU_C_COMPLEX 3127c2de775SJed Brown # elif defined(PETSC_USE_REAL_DOUBLE) 3137c2de775SJed Brown # define MPIU_COMPLEX MPIU_C_DOUBLE_COMPLEX 3147c2de775SJed Brown # elif defined(PETSC_USE_REAL___FLOAT128) 3157c2de775SJed Brown # define MPIU_COMPLEX MPIU___COMPLEX128 3167c2de775SJed Brown # endif /* PETSC_USE_REAL_* */ 3177c2de775SJed Brown #endif 3187c2de775SJed Brown 319d4161b4aSBarry Smith #if (defined(PETSC_USE_COMPLEX) && !defined(PETSC_SKIP_COMPLEX)) 32050f81f78SJed Brown typedef PetscComplex PetscScalar; 32150f81f78SJed Brown #define PetscRealPart(a) PetscRealPartComplex(a) 32250f81f78SJed Brown #define PetscImaginaryPart(a) PetscImaginaryPartComplex(a) 32350f81f78SJed Brown #define PetscAbsScalar(a) PetscAbsComplex(a) 32450f81f78SJed Brown #define PetscConj(a) PetscConjComplex(a) 32550f81f78SJed Brown #define PetscSqrtScalar(a) PetscSqrtComplex(a) 32650f81f78SJed Brown #define PetscPowScalar(a,b) PetscPowComplex(a,b) 32750f81f78SJed Brown #define PetscExpScalar(a) PetscExpComplex(a) 32850f81f78SJed Brown #define PetscLogScalar(a) PetscLogComplex(a) 32950f81f78SJed Brown #define PetscSinScalar(a) PetscSinComplex(a) 33050f81f78SJed Brown #define PetscCosScalar(a) PetscCosComplex(a) 331255453a1SBarry Smith #define PetscAsinScalar(a) PetscAsinComplex(a) 332255453a1SBarry Smith #define PetscAcosScalar(a) PetscAcosComplex(a) 333a4bea5a6SPeter Brune #define PetscTanScalar(a) PetscTanComplex(a) 334a4bea5a6SPeter Brune #define PetscSinhScalar(a) PetscSinhComplex(a) 335a4bea5a6SPeter Brune #define PetscCoshScalar(a) PetscCoshComplex(a) 336a4bea5a6SPeter Brune #define PetscTanhScalar(a) PetscTanhComplex(a) 3377c2de775SJed Brown #define MPIU_SCALAR MPIU_COMPLEX 33875567043SBarry Smith 3391093a601SBarry Smith /* 3401093a601SBarry Smith real number definitions 3411093a601SBarry Smith */ 3421b65fc54SMatthew G Knepley #else /* PETSC_USE_COMPLEX */ 3437c2de775SJed Brown typedef PetscReal PetscScalar; 3447c2de775SJed Brown #define MPIU_SCALAR MPIU_REAL 3457c2de775SJed Brown 346329f5518SBarry Smith #define PetscRealPart(a) (a) 347c1d390e3SJed Brown #define PetscImaginaryPart(a) ((PetscReal)0.) 348c1d390e3SJed Brown PETSC_STATIC_INLINE PetscReal PetscAbsScalar(PetscScalar a) {return a < 0.0 ? -a : a;} 349e489efc1SBarry Smith #define PetscConj(a) (a) 350570b7f6dSBarry Smith #if !defined(PETSC_USE_REAL___FLOAT128) && !defined(PETSC_USE_REAL___FP16) 35118a7d68fSSatish Balay #define PetscSqrtScalar(a) sqrt(a) 352184914b5SBarry Smith #define PetscPowScalar(a,b) pow(a,b) 353184914b5SBarry Smith #define PetscExpScalar(a) exp(a) 35406c1185fSBarry Smith #define PetscLogScalar(a) log(a) 355184914b5SBarry Smith #define PetscSinScalar(a) sin(a) 356184914b5SBarry Smith #define PetscCosScalar(a) cos(a) 357255453a1SBarry Smith #define PetscAsinScalar(a) asin(a) 358255453a1SBarry Smith #define PetscAcosScalar(a) acos(a) 359a4bea5a6SPeter Brune #define PetscTanScalar(a) tan(a) 360a4bea5a6SPeter Brune #define PetscSinhScalar(a) sinh(a) 361a4bea5a6SPeter Brune #define PetscCoshScalar(a) cosh(a) 362a4bea5a6SPeter Brune #define PetscTanhScalar(a) tanh(a) 363570b7f6dSBarry Smith #elif defined(PETSC_USE_REAL___FP16) 364570b7f6dSBarry Smith #define PetscSqrtScalar(a) sqrtf(a) 365570b7f6dSBarry Smith #define PetscPowScalar(a,b) powf(a,b) 366570b7f6dSBarry Smith #define PetscExpScalar(a) expf(a) 367570b7f6dSBarry Smith #define PetscLogScalar(a) logf(a) 368570b7f6dSBarry Smith #define PetscSinScalar(a) sinf(a) 369570b7f6dSBarry Smith #define PetscCosScalar(a) cosf(a) 370570b7f6dSBarry Smith #define PetscAsinScalar(a) asinf(a) 371570b7f6dSBarry Smith #define PetscAcosScalar(a) acosf(a) 372570b7f6dSBarry Smith #define PetscTanScalar(a) tanf(a) 373570b7f6dSBarry Smith #define PetscSinhScalar(a) sinhf(a) 374570b7f6dSBarry Smith #define PetscCoshScalar(a) coshf(a) 375570b7f6dSBarry Smith #define PetscTanhScalar(a) tanhf(a) 376ce63c4c1SBarry Smith #else /* PETSC_USE_REAL___FLOAT128 */ 3770d0cc1b5SBarry Smith #define PetscSqrtScalar(a) sqrtq(a) 3780d0cc1b5SBarry Smith #define PetscPowScalar(a,b) powq(a,b) 3790d0cc1b5SBarry Smith #define PetscExpScalar(a) expq(a) 3800d0cc1b5SBarry Smith #define PetscLogScalar(a) logq(a) 3810d0cc1b5SBarry Smith #define PetscSinScalar(a) sinq(a) 3820d0cc1b5SBarry Smith #define PetscCosScalar(a) cosq(a) 383255453a1SBarry Smith #define PetscAsinScalar(a) asinq(a) 384255453a1SBarry Smith #define PetscAcosScalar(a) acosq(a) 385a4bea5a6SPeter Brune #define PetscTanScalar(a) tanq(a) 386a4bea5a6SPeter Brune #define PetscSinhScalar(a) sinhq(a) 387a4bea5a6SPeter Brune #define PetscCoshScalar(a) coshq(a) 388a4bea5a6SPeter Brune #define PetscTanhScalar(a) tanhq(a) 389ce63c4c1SBarry Smith #endif /* PETSC_USE_REAL___FLOAT128 */ 390b0a32e0cSBarry Smith 3911b65fc54SMatthew G Knepley #endif /* PETSC_USE_COMPLEX */ 392e489efc1SBarry Smith 393da9b6338SBarry Smith #define PetscSign(a) (((a) >= 0) ? ((a) == 0 ? 0 : 1) : -1) 39436850ab7SBarry Smith #define PetscSignReal(a) (((a) >= 0.0) ? ((a) == 0.0 ? 0.0 : 1.0) : -1.0) 39526aa1773SMatthew Knepley #define PetscAbs(a) (((a) >= 0) ? (a) : -(a)) 3963f1db9ecSBarry Smith 397314da920SBarry Smith /* --------------------------------------------------------------------------*/ 398314da920SBarry Smith 399e489efc1SBarry Smith /* 400f22f69f0SBarry Smith Certain objects may be created using either single or double precision. 401f22f69f0SBarry Smith This is currently not used. 402e489efc1SBarry Smith */ 403570b7f6dSBarry Smith typedef enum { PETSC_SCALAR_DOUBLE,PETSC_SCALAR_SINGLE, PETSC_SCALAR_LONG_DOUBLE, PETSC_SCALAR_HALF } PetscScalarPrecision; 404e489efc1SBarry Smith 40550f81f78SJed Brown #if defined(PETSC_HAVE_COMPLEX) 406e489efc1SBarry Smith /* PETSC_i is the imaginary number, i */ 40750f81f78SJed Brown PETSC_EXTERN PetscComplex PETSC_i; 408*8a351411SToby Isaac 409*8a351411SToby Isaac /* Try to do the right thing for complex number construction: see 410*8a351411SToby Isaac 411*8a351411SToby Isaac http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1464.htm 412*8a351411SToby Isaac 413*8a351411SToby Isaac for details 414*8a351411SToby Isaac */ 415*8a351411SToby Isaac static inline PetscComplex PetscCMPLX(PetscReal x, PetscReal y) 416*8a351411SToby Isaac { 417*8a351411SToby Isaac #if defined(__cplusplus) 418*8a351411SToby Isaac return PetscComplex(x,y); 419*8a351411SToby Isaac #elif defined(_Imaginary_I) 420*8a351411SToby Isaac return x + y * _Imaginary_I; 421*8a351411SToby Isaac #else 422*8a351411SToby Isaac #if defined(PETSC_USE_REAL_SINGLE) && defined(CMPLXF) 423*8a351411SToby Isaac return CMPLXF(x,y); 424*8a351411SToby Isaac PETSC_REAL 425*8a351411SToby Isaac #elif defined(PETSC_USE_REAL_DOUBLE) && defined(CMPLX) 426*8a351411SToby Isaac return CMPLX(x,y); 427*8a351411SToby Isaac #else 428*8a351411SToby Isaac return x + y * PETSC_i; 42950f81f78SJed Brown #endif 430*8a351411SToby Isaac #endif 431*8a351411SToby Isaac } 432*8a351411SToby Isaac #endif 433*8a351411SToby Isaac 434e489efc1SBarry Smith 435b6a5bde7SBarry Smith /*MC 436b6a5bde7SBarry Smith PetscMin - Returns minimum of two numbers 437b6a5bde7SBarry Smith 438eca87e8dSBarry Smith Synopsis: 439aaa7dc30SBarry Smith #include <petscmath.h> 440eca87e8dSBarry Smith type PetscMin(type v1,type v2) 441eca87e8dSBarry Smith 442eca87e8dSBarry Smith Not Collective 443eca87e8dSBarry Smith 444b6a5bde7SBarry Smith Input Parameter: 445b6a5bde7SBarry Smith + v1 - first value to find minimum of 446b6a5bde7SBarry Smith - v2 - second value to find minimum of 447b6a5bde7SBarry Smith 448b6a5bde7SBarry Smith Notes: type can be integer or floating point value 449b6a5bde7SBarry Smith 450b6a5bde7SBarry Smith Level: beginner 451b6a5bde7SBarry Smith 452d9a4bb16SJed Brown .seealso: PetscMin(), PetscClipInterval(), PetscAbsInt(), PetscAbsReal(), PetscSqr() 453b6a5bde7SBarry Smith 454b6a5bde7SBarry Smith M*/ 455e489efc1SBarry Smith #define PetscMin(a,b) (((a)<(b)) ? (a) : (b)) 456b6a5bde7SBarry Smith 457b6a5bde7SBarry Smith /*MC 458b6a5bde7SBarry Smith PetscMax - Returns maxium of two numbers 459b6a5bde7SBarry Smith 460eca87e8dSBarry Smith Synopsis: 461aaa7dc30SBarry Smith #include <petscmath.h> 462eca87e8dSBarry Smith type max PetscMax(type v1,type v2) 463eca87e8dSBarry Smith 464eca87e8dSBarry Smith Not Collective 465eca87e8dSBarry Smith 466b6a5bde7SBarry Smith Input Parameter: 467b6a5bde7SBarry Smith + v1 - first value to find maximum of 468b6a5bde7SBarry Smith - v2 - second value to find maximum of 469b6a5bde7SBarry Smith 470b6a5bde7SBarry Smith Notes: type can be integer or floating point value 471b6a5bde7SBarry Smith 472b6a5bde7SBarry Smith Level: beginner 473b6a5bde7SBarry Smith 474d9a4bb16SJed Brown .seealso: PetscMin(), PetscClipInterval(), PetscAbsInt(), PetscAbsReal(), PetscSqr() 475b6a5bde7SBarry Smith 476b6a5bde7SBarry Smith M*/ 477e489efc1SBarry Smith #define PetscMax(a,b) (((a)<(b)) ? (b) : (a)) 478b6a5bde7SBarry Smith 479b6a5bde7SBarry Smith /*MC 480d9a4bb16SJed Brown PetscClipInterval - Returns a number clipped to be within an interval 481d9a4bb16SJed Brown 482d9a4bb16SJed Brown Synopsis: 483aaa7dc30SBarry Smith #include <petscmath.h> 484d9a4bb16SJed Brown type clip PetscClipInterval(type x,type a,type b) 485d9a4bb16SJed Brown 486d9a4bb16SJed Brown Not Collective 487d9a4bb16SJed Brown 488d9a4bb16SJed Brown Input Parameter: 489d9a4bb16SJed Brown + x - value to use if within interval (a,b) 490d9a4bb16SJed Brown . a - lower end of interval 491d9a4bb16SJed Brown - b - upper end of interval 492d9a4bb16SJed Brown 493d9a4bb16SJed Brown Notes: type can be integer or floating point value 494d9a4bb16SJed Brown 495d9a4bb16SJed Brown Level: beginner 496d9a4bb16SJed Brown 497d9a4bb16SJed Brown .seealso: PetscMin(), PetscMax(), PetscAbsInt(), PetscAbsReal(), PetscSqr() 498d9a4bb16SJed Brown 499d9a4bb16SJed Brown M*/ 500d9a4bb16SJed Brown #define PetscClipInterval(x,a,b) (PetscMax((a),PetscMin((x),(b)))) 501d9a4bb16SJed Brown 502d9a4bb16SJed Brown /*MC 503b6a5bde7SBarry Smith PetscAbsInt - Returns the absolute value of an integer 504b6a5bde7SBarry Smith 505b6a5bde7SBarry Smith Synopsis: 506aaa7dc30SBarry Smith #include <petscmath.h> 507b6a5bde7SBarry Smith int abs PetscAbsInt(int v1) 508b6a5bde7SBarry Smith 509eca87e8dSBarry Smith Not Collective 510eca87e8dSBarry Smith 511eca87e8dSBarry Smith Input Parameter: 512eca87e8dSBarry Smith . v1 - the integer 513b6a5bde7SBarry Smith 514b6a5bde7SBarry Smith Level: beginner 515b6a5bde7SBarry Smith 516b6a5bde7SBarry Smith .seealso: PetscMax(), PetscMin(), PetscAbsReal(), PetscSqr() 517b6a5bde7SBarry Smith 518b6a5bde7SBarry Smith M*/ 519e489efc1SBarry Smith #define PetscAbsInt(a) (((a)<0) ? -(a) : (a)) 520b6a5bde7SBarry Smith 521b6a5bde7SBarry Smith /*MC 522b6a5bde7SBarry Smith PetscAbsReal - Returns the absolute value of an real number 523b6a5bde7SBarry Smith 524eca87e8dSBarry Smith Synopsis: 525aaa7dc30SBarry Smith #include <petscmath.h> 526eca87e8dSBarry Smith Real abs PetscAbsReal(PetscReal v1) 527eca87e8dSBarry Smith 528eca87e8dSBarry Smith Not Collective 529eca87e8dSBarry Smith 530b6a5bde7SBarry Smith Input Parameter: 531b6a5bde7SBarry Smith . v1 - the double 532b6a5bde7SBarry Smith 533b6a5bde7SBarry Smith 534b6a5bde7SBarry Smith Level: beginner 535b6a5bde7SBarry Smith 536b6a5bde7SBarry Smith .seealso: PetscMax(), PetscMin(), PetscAbsInt(), PetscSqr() 537b6a5bde7SBarry Smith 538b6a5bde7SBarry Smith M*/ 539f6275e2eSBarry Smith #define PetscAbsReal(a) (((a)<0) ? -(a) : (a)) 540b6a5bde7SBarry Smith 541b6a5bde7SBarry Smith /*MC 542b6a5bde7SBarry Smith PetscSqr - Returns the square of a number 543b6a5bde7SBarry Smith 544b6a5bde7SBarry Smith Synopsis: 545aaa7dc30SBarry Smith #include <petscmath.h> 546b6a5bde7SBarry Smith type sqr PetscSqr(type v1) 547b6a5bde7SBarry Smith 548eca87e8dSBarry Smith Not Collective 549eca87e8dSBarry Smith 550eca87e8dSBarry Smith Input Parameter: 551eca87e8dSBarry Smith . v1 - the value 552eca87e8dSBarry Smith 553b6a5bde7SBarry Smith Notes: type can be integer or floating point value 554b6a5bde7SBarry Smith 555b6a5bde7SBarry Smith Level: beginner 556b6a5bde7SBarry Smith 557b6a5bde7SBarry Smith .seealso: PetscMax(), PetscMin(), PetscAbsInt(), PetscAbsReal() 558b6a5bde7SBarry Smith 559b6a5bde7SBarry Smith M*/ 5604ebda54eSMatthew Knepley #define PetscSqr(a) ((a)*(a)) 561e489efc1SBarry Smith 562314da920SBarry Smith /* ----------------------------------------------------------------------------*/ 563314da920SBarry Smith /* 564d34fcf5fSBarry Smith Basic constants 565314da920SBarry Smith */ 566ce63c4c1SBarry Smith #if defined(PETSC_USE_REAL___FLOAT128) 567d34fcf5fSBarry Smith #define PETSC_PI M_PIq 568d34fcf5fSBarry Smith #elif defined(M_PI) 569d34fcf5fSBarry Smith #define PETSC_PI M_PI 570d34fcf5fSBarry Smith #else 571faa6e9b0SMatthew G Knepley #define PETSC_PI 3.14159265358979323846264338327950288419716939937510582 572d34fcf5fSBarry Smith #endif 573d34fcf5fSBarry Smith 574ab824b78SBarry Smith #if !defined(PETSC_USE_64BIT_INDICES) 57571fd2e92SBarry Smith #define PETSC_MAX_INT 2147483647 576ab824b78SBarry Smith #define PETSC_MIN_INT (-PETSC_MAX_INT - 1) 577ab824b78SBarry Smith #else 578ab824b78SBarry Smith #define PETSC_MAX_INT 9223372036854775807L 579ab824b78SBarry Smith #define PETSC_MIN_INT (-PETSC_MAX_INT - 1) 580ab824b78SBarry Smith #endif 581e489efc1SBarry Smith 582ce63c4c1SBarry Smith #if defined(PETSC_USE_REAL_SINGLE) 583ab824b78SBarry Smith # define PETSC_MAX_REAL 3.40282346638528860e+38F 584ea345e14SBarry Smith # define PETSC_MIN_REAL -PETSC_MAX_REAL 58582a7e548SBarry Smith # define PETSC_MACHINE_EPSILON 1.19209290e-07F 58682a7e548SBarry Smith # define PETSC_SQRT_MACHINE_EPSILON 3.45266983e-04F 587cf6e855fSSatish Balay # define PETSC_SMALL 1.e-5 588ce63c4c1SBarry Smith #elif defined(PETSC_USE_REAL_DOUBLE) 589ab824b78SBarry Smith # define PETSC_MAX_REAL 1.7976931348623157e+308 590ea345e14SBarry Smith # define PETSC_MIN_REAL -PETSC_MAX_REAL 59182a7e548SBarry Smith # define PETSC_MACHINE_EPSILON 2.2204460492503131e-16 59282a7e548SBarry Smith # define PETSC_SQRT_MACHINE_EPSILON 1.490116119384766e-08 593cf6e855fSSatish Balay # define PETSC_SMALL 1.e-10 594ce63c4c1SBarry Smith #elif defined(PETSC_USE_REAL___FLOAT128) 595ea345e14SBarry Smith # define PETSC_MAX_REAL FLT128_MAX 596ce63c4c1SBarry Smith # define PETSC_MIN_REAL -FLT128_MAX 597d34fcf5fSBarry Smith # define PETSC_MACHINE_EPSILON FLT128_EPSILON 59846d881e9SBarry Smith # define PETSC_SQRT_MACHINE_EPSILON 1.38777878078e-17q 59946d881e9SBarry Smith # define PETSC_SMALL 1.e-20q 600570b7f6dSBarry Smith #elif defined(PETSC_USE_REAL___FP16) /* maybe should use single precision values for these? */ 601570b7f6dSBarry Smith # define PETSC_MAX_REAL 65504. 602570b7f6dSBarry Smith # define PETSC_MIN_REAL -PETSC_MAX_REAL 603570b7f6dSBarry Smith # define PETSC_MACHINE_EPSILON .00097656 604570b7f6dSBarry Smith # define PETSC_SQRT_MACHINE_EPSILON .0312 605570b7f6dSBarry Smith # define PETSC_SMALL 5.e-3 6069cf09972SJed Brown #endif 6073e523bebSBarry Smith 608e270355aSBarry Smith #define PETSC_INFINITY PETSC_MAX_REAL/4.0 609e270355aSBarry Smith #define PETSC_NINFINITY -PETSC_INFINITY 610e270355aSBarry Smith 611014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscIsInfOrNanReal(PetscReal); 612bae46576SBarry Smith PETSC_EXTERN PetscErrorCode PetscIsNanReal(PetscReal); 6138b49ba18SBarry Smith PETSC_EXTERN PetscBool PetscIsNormalReal(PetscReal); 614834b1445SSatish Balay PETSC_STATIC_INLINE PetscErrorCode PetscIsInfOrNanScalar(PetscScalar v) {return PetscIsInfOrNanReal(PetscAbsScalar(v));} 615bae46576SBarry Smith PETSC_STATIC_INLINE PetscErrorCode PetscIsNanScalar(PetscScalar v) {return PetscIsNanReal(PetscAbsScalar(v));} 616834b1445SSatish Balay PETSC_STATIC_INLINE PetscErrorCode PetscIsNormalScalar(PetscScalar v) {return PetscIsNormalReal(PetscAbsScalar(v));} 6179a25a3ccSBarry Smith 61898725619SBarry Smith /* 61998725619SBarry Smith These macros are currently hardwired to match the regular data types, so there is no support for a different 62098725619SBarry Smith MatScalar from PetscScalar. We left the MatScalar in the source just in case we use it again. 62198725619SBarry Smith */ 62298725619SBarry Smith #define MPIU_MATSCALAR MPIU_SCALAR 62398725619SBarry Smith typedef PetscScalar MatScalar; 62498725619SBarry Smith typedef PetscReal MatReal; 62598725619SBarry Smith 6268ad47952SJed Brown struct petsc_mpiu_2scalar {PetscScalar a,b;}; 6278ad47952SJed Brown PETSC_EXTERN MPI_Datatype MPIU_2SCALAR PetscAttrMPITypeTagLayoutCompatible(struct petsc_mpiu_2scalar); 6288ad47952SJed Brown #if defined(PETSC_USE_64BIT_INDICES) || !defined(MPI_2INT) 6298ad47952SJed Brown struct petsc_mpiu_2int {PetscInt a,b;}; 6308ad47952SJed Brown PETSC_EXTERN MPI_Datatype MPIU_2INT PetscAttrMPITypeTagLayoutCompatible(struct petsc_mpiu_2int); 6318ad47952SJed Brown #else 6328ad47952SJed Brown #define MPIU_2INT MPI_2INT 6338ad47952SJed Brown #endif 634e9fa29b7SSatish Balay 635b2fb0278SBarry Smith PETSC_STATIC_INLINE PetscInt PetscPowInt(PetscInt base,PetscInt power) 636b2fb0278SBarry Smith { 637fa711258SJed Brown PetscInt result = 1; 638fa711258SJed Brown while (power) { 639fa711258SJed Brown if (power & 1) result *= base; 640fa711258SJed Brown power >>= 1; 641fa711258SJed Brown base *= base; 642fa711258SJed Brown } 643fa711258SJed Brown return result; 644fa711258SJed Brown } 645b2fb0278SBarry Smith 646b2fb0278SBarry Smith PETSC_STATIC_INLINE PetscReal PetscPowRealInt(PetscReal base,PetscInt power) 647b2fb0278SBarry Smith { 648fa711258SJed Brown PetscReal result = 1; 649d98d5da7SBarry Smith if (power < 0) { 650d98d5da7SBarry Smith power = -power; 65110d40e53SLisandro Dalcin base = ((PetscReal)1)/base; 652d98d5da7SBarry Smith } 653fa711258SJed Brown while (power) { 654fa711258SJed Brown if (power & 1) result *= base; 655fa711258SJed Brown power >>= 1; 656fa711258SJed Brown base *= base; 657fa711258SJed Brown } 658fa711258SJed Brown return result; 659fa711258SJed Brown } 660fa711258SJed Brown 661b2fb0278SBarry Smith PETSC_STATIC_INLINE PetscScalar PetscPowScalarInt(PetscScalar base,PetscInt power) 662b2fb0278SBarry Smith { 6638b49ba18SBarry Smith PetscScalar result = 1; 6648b49ba18SBarry Smith if (power < 0) { 6658b49ba18SBarry Smith power = -power; 66610d40e53SLisandro Dalcin base = ((PetscReal)1)/base; 6678b49ba18SBarry Smith } 6688b49ba18SBarry Smith while (power) { 6698b49ba18SBarry Smith if (power & 1) result *= base; 6708b49ba18SBarry Smith power >>= 1; 6718b49ba18SBarry Smith base *= base; 6728b49ba18SBarry Smith } 6738b49ba18SBarry Smith return result; 6748b49ba18SBarry Smith } 6758b49ba18SBarry Smith 676b2fb0278SBarry Smith PETSC_STATIC_INLINE PetscScalar PetscPowScalarReal(PetscScalar base,PetscReal power) 677b2fb0278SBarry Smith { 678b2fb0278SBarry Smith PetscScalar cpower = power; 679b2fb0278SBarry Smith return PetscPowScalar(base,cpower); 680b2fb0278SBarry Smith } 68178a59e97SMatthew G. Knepley 68278a59e97SMatthew G. Knepley #ifndef PETSC_HAVE_LOG2 68378a59e97SMatthew G. Knepley PETSC_STATIC_INLINE PetscReal PetscLog2Real(PetscReal n) 68478a59e97SMatthew G. Knepley { 68591954be4SBarry Smith return PetscLogReal(n)/PetscLogReal(2.0); 68678a59e97SMatthew G. Knepley } 68778a59e97SMatthew G. Knepley #endif 688e489efc1SBarry Smith #endif 689