1#!/usr/bin/env python 2from __future__ import generators 3import config.base 4 5class Configure(config.base.Configure): 6 def __init__(self, framework): 7 config.base.Configure.__init__(self, framework) 8 self.headerPrefix = '' 9 self.substPrefix = '' 10 return 11 12 def __str1__(self): 13 desc = [] 14 if hasattr(self, 'scalartype'): 15 desc.append(' Scalar type: ' + self.scalartype) 16 if hasattr(self, 'precision'): 17 desc.append(' Precision: ' + self.precision) 18 return '\n'.join(desc)+'\n' 19 20 def setupHelp(self, help): 21 import nargs 22 # Dec 2016, the __fp16 type is only available with GNU compilers on ARM systems 23 help.addArgument('PETSc', '-with-precision=<__fp16,single,double,__float128>', nargs.Arg(None, 'double', 'Specify numerical precision')) 24 help.addArgument('PETSc', '-with-scalar-type=<real or complex>', nargs.Arg(None, 'real', 'Specify real or complex numbers')) 25 return 26 27 def setupDependencies(self, framework): 28 config.base.Configure.setupDependencies(self, framework) 29 self.types = framework.require('config.types', self) 30 self.languages = framework.require('PETSc.options.languages', self) 31 self.compilers = framework.require('config.compilers', self) 32 self.libraries = framework.require('config.libraries',self) 33 return 34 35 36 def configureScalarType(self): 37 '''Choose between real and complex numbers''' 38 self.scalartype = self.framework.argDB['with-scalar-type'].lower() 39 if self.scalartype == 'complex': 40 self.addDefine('USE_COMPLEX', '1') 41 if self.languages.clanguage == 'C' and not self.types.c99_complex: 42 raise RuntimeError('C Compiler provided doest not support C99 complex') 43 if self.languages.clanguage == 'Cxx' and not self.types.cxx_complex: 44 raise RuntimeError('Cxx compiler provided does not support std::complex') 45 if self.languages.clanguage == 'Cxx': 46 self.addDefine('USE_CXXCOMPLEX',1) 47 elif not self.scalartype == 'real': 48 raise RuntimeError('--with-scalar-type must be real or complex') 49 self.addDefine('USE_SCALAR_'+self.scalartype.upper(), '1') 50 self.logPrint('Scalar type is '+str(self.scalartype)) 51 # On apple isinf() and isnan() do not work when <complex> is included 52 self.pushLanguage(self.languages.clanguage) 53 if self.scalartype == 'complex' and self.languages.clanguage == 'Cxx': 54 if self.checkLink('#include <math.h>\n#include <complex>\n','double b = 2.0;int a = isnormal(b);\n'): 55 self.addDefine('HAVE_ISNORMAL',1) 56 if self.checkLink('#include <math.h>\n#include <complex>\n','double b = 2.0;int a = isnan(b);\n'): 57 self.addDefine('HAVE_ISNAN',1) 58 if self.checkLink('#include <math.h>\n#include <complex>\n','double b = 2.0;int a = isinf(b);\n'): 59 self.addDefine('HAVE_ISINF',1) 60 if self.checkLink('#include <float.h>\n#include <complex>\n','double b = 2.0;int a = _isnan(b);\n'): 61 self.addDefine('HAVE__ISNAN',1) 62 if self.checkLink('#include <float.h>\n#include <complex>\n','double b = 2.0;int a = _finite(b);\n'): 63 self.addDefine('HAVE__FINITE',1) 64 else: 65 if self.checkLink('#include <math.h>\n','double b = 2.0; int a = isnormal(b);\n'): 66 self.addDefine('HAVE_ISNORMAL',1) 67 if self.checkLink('#include <math.h>\n','double b = 2.0; int a = isnan(b);\n'): 68 self.addDefine('HAVE_ISNAN',1) 69 if self.checkLink('#include <math.h>\n','double b = 2.0; int a = isinf(b);\n'): 70 self.addDefine('HAVE_ISINF',1) 71 if self.checkLink('#include <float.h>\n','double b = 2.0;int a = _isnan(b);\n'): 72 self.addDefine('HAVE__ISNAN',1) 73 if self.checkLink('#include <float.h>\n','double b = 2.0;int a = _finite(b);\n'): 74 self.addDefine('HAVE__FINITE',1) 75 self.popLanguage() 76 return 77 78 def configurePrecision(self): 79 '''Set the default real number precision for PETSc objects''' 80 self.precision = self.framework.argDB['with-precision'].lower() 81 if self.precision == '__fp16': # supported by gcc trunk 82 if self.scalartype == 'complex': 83 raise RuntimeError('__fp16 can only be used with real numbers, not complex') 84 if hasattr(self.compilers, 'FC'): 85 raise RuntimeError('__fp16 can only be used with C compiler, not Fortran') 86 self.addDefine('USE_REAL___FP16', '1') 87 self.addMakeMacro('PETSC_SCALAR_SIZE', '16') 88 elif self.precision == 'single': 89 self.addDefine('USE_REAL_SINGLE', '1') 90 self.addMakeMacro('PETSC_SCALAR_SIZE', '32') 91 elif self.precision == 'double': 92 self.addDefine('USE_REAL_DOUBLE', '1') 93 self.addMakeMacro('PETSC_SCALAR_SIZE', '64') 94 elif self.precision == '__float128': # supported by gcc 4.6 95 if self.libraries.add('quadmath','logq',prototype='#include <quadmath.h>',call='__float128 f; logq(f);'): 96 self.addDefine('USE_REAL___FLOAT128', '1') 97 self.addMakeMacro('PETSC_SCALAR_SIZE', '128') 98 else: 99 raise RuntimeError('quadmath support not found. --with-precision=__float128 works with gcc-4.6 and newer compilers.') 100 else: 101 raise RuntimeError('--with-precision must be single, double,__float128') 102 self.logPrint('Precision is '+str(self.precision)) 103 if self.precision == '__float128' and self.scalartype == 'complex' and self.languages.clanguage == 'Cxx': 104 raise RuntimeError('Cannot use --with-precision=__float128 --with-scalar-type=complex and --with-clanguage=cxx because C++ std:complex class has no support for __float128, use --with-clanguage=c') 105 return 106 107 def configure(self): 108 self.executeTest(self.configureScalarType) 109 self.executeTest(self.configurePrecision) 110 return 111