1#!/usr/bin/env python 2from __future__ import generators 3import user 4import config.base 5 6class Configure(config.base.Configure): 7 def __init__(self, framework): 8 config.base.Configure.__init__(self, framework) 9 self.headerPrefix = '' 10 self.substPrefix = '' 11 return 12 13 def __str1__(self): 14 desc = [] 15 if hasattr(self, 'scalartype'): 16 desc.append(' Scalar type: ' + self.scalartype) 17 if hasattr(self, 'precision'): 18 desc.append(' Precision: ' + self.precision) 19 return '\n'.join(desc)+'\n' 20 21 def setupHelp(self, help): 22 import nargs 23 help.addArgument('PETSc', '-with-precision=<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 elif not self.scalartype == 'real': 46 raise RuntimeError('--with-scalar-type must be real or complex') 47 self.addDefine('USE_SCALAR_'+self.scalartype.upper(), '1') 48 self.logPrint('Scalar type is '+str(self.scalartype)) 49 # On apple isinf() and isnan() do not work when <complex> is included 50 self.pushLanguage(self.languages.clanguage) 51 if self.scalartype == 'complex' and self.languages.clanguage == 'Cxx': 52 if self.checkLink('#include <math.h>\n#include <complex>\n','double b = 2.0;int a = isnormal(b);\n'): 53 self.addDefine('HAVE_ISNORMAL',1) 54 if self.checkLink('#include <math.h>\n#include <complex>\n','double b = 2.0;int a = isnan(b);\n'): 55 self.addDefine('HAVE_ISNAN',1) 56 if self.checkLink('#include <math.h>\n#include <complex>\n','double b = 2.0;int a = isinf(b);\n'): 57 self.addDefine('HAVE_ISINF',1) 58 if self.checkLink('#include <float.h>\n#include <complex>\n','double b = 2.0;int a = _isnan(b);\n'): 59 self.addDefine('HAVE__ISNAN',1) 60 if self.checkLink('#include <float.h>\n#include <complex>\n','double b = 2.0;int a = _finite(b);\n'): 61 self.addDefine('HAVE__FINITE',1) 62 else: 63 if self.checkLink('#include <math.h>\n','double b = 2.0; int a = isnormal(b);\n'): 64 self.addDefine('HAVE_ISNORMAL',1) 65 if self.checkLink('#include <math.h>\n','double b = 2.0; int a = isnan(b);\n'): 66 self.addDefine('HAVE_ISNAN',1) 67 if self.checkLink('#include <math.h>\n','double b = 2.0; int a = isinf(b);\n'): 68 self.addDefine('HAVE_ISINF',1) 69 if self.checkLink('#include <float.h>\n','double b = 2.0;int a = _isnan(b);\n'): 70 self.addDefine('HAVE__ISNAN',1) 71 if self.checkLink('#include <float.h>\n','double b = 2.0;int a = _finite(b);\n'): 72 self.addDefine('HAVE__FINITE',1) 73 self.popLanguage() 74 return 75 76 def configurePrecision(self): 77 '''Set the default real number precision for PETSc objects''' 78 self.precision = self.framework.argDB['with-precision'].lower() 79 if self.precision == 'single': 80 self.addDefine('USE_REAL_SINGLE', '1') 81 self.addMakeMacro('PETSC_SCALAR_SIZE', '32') 82 elif self.precision == 'double': 83 self.addDefine('USE_REAL_DOUBLE', '1') 84 self.addMakeMacro('PETSC_SCALAR_SIZE', '64') 85 elif self.precision == '__float128': # supported by gcc 4.6 86 if self.libraries.add('quadmath','logq',prototype='#include <quadmath.h>',call='__float128 f; logq(f);'): 87 self.addDefine('USE_REAL___FLOAT128', '1') 88 self.addMakeMacro('PETSC_SCALAR_SIZE', '128') 89 else: 90 raise RuntimeError('quadmath support not found. --with-precision=__float128 works with gcc-4.6 and newer compilers.') 91 else: 92 raise RuntimeError('--with-precision must be single, double,__float128') 93 self.logPrint('Precision is '+str(self.precision)) 94 if self.precision == '__float128' and self.scalartype == 'complex' and self.languages.clanguage == 'Cxx': 95 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') 96 return 97 98 def configure(self): 99 self.executeTest(self.configureScalarType) 100 self.executeTest(self.configurePrecision) 101 return 102