xref: /petsc/config/PETSc/options/libraryOptions.py (revision 02aeac5ff96c3a19dfd43e6071abe571687f39b6)
1from __future__ import generators
2import config.base
3import os
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 __str__(self):
13    return ''
14
15  def setupHelp(self, help):
16    import nargs
17    help.addArgument('PETSc', '-with-log=<bool>',              nargs.ArgBool(None, 1, 'Activate logging code in PETSc'))
18    help.addArgument('PETSc', '-with-threadsafety=<bool>',     nargs.ArgBool(None, 0, 'Allow individual threads in PETSc to call PETSc routines'))
19    help.addArgument('PETSc', '-with-info=<bool>',             nargs.ArgBool(None, 1, 'Activate PetscInfo() (i.e. -info)  code in PETSc'))
20    help.addArgument('PETSc', '-with-ctable=<bool>',           nargs.ArgBool(None, 1, 'Activate CTABLE hashing for certain search functions - to conserve memory'))
21    help.addArgument('PETSc', '-with-dmlandau-3d=<bool>',      nargs.ArgBool(None, 0, 'Enable full 3D DM Landau, default is 2.5D'))
22    help.addArgument('PETSc', '-with-fortran-kernels=<bool>',  nargs.ArgBool(None, 0, 'Use Fortran for linear algebra kernels'))
23    help.addArgument('PETSc', '-with-avx512-kernels=<bool>',   nargs.ArgBool(None, 1, 'Use AVX-512 intrinsics for linear algebra kernels when available'))
24    help.addArgument('PETSc', '-with-is-color-value-type=<char,short>',nargs.ArgString(None, 'short', 'char, short can store 256, 65536 colors'))
25    return
26
27  def setupDependencies(self, framework):
28    config.base.Configure.setupDependencies(self, framework)
29    self.compilers        = framework.require('config.compilers', self)
30    self.setCompilers     = framework.require('config.setCompilers', self)
31    self.libraries        = framework.require('config.libraries', self)
32    self.types            = framework.require('config.types', self)
33    self.compilerFlags    = framework.require('config.compilerFlags', self)
34    self.sharedLibraries  = framework.require('PETSc.options.sharedLibraries', None)
35    self.petscConfigure   = framework.require('PETSc.Configure', None)
36    return
37
38  def configureLibraryOptions(self):
39    '''Sets PETSC_USE_DEBUG, PETSC_USE_INFO, PETSC_USE_LOG, PETSC_USE_CTABLE, PETSC_USE_DMLANDAU_2D, PETSC_USE_FORTRAN_KERNELS, and PETSC_USE_AVX512_KERNELS'''
40    '''Also sets PETSC_AssertAlignx() in Fortran and PETSC_Alignx() in C for IBM BG/P compiler '''
41    if self.framework.argDB['with-threadsafety']:
42      self.addDefine('HAVE_THREADSAFETY',1)
43      self.useThreadSafety = 1
44    else:
45      self.useThreadSafety = 0
46
47    if self.useThreadSafety and self.framework.argDB['with-log']:
48      raise RuntimeError('Must use --with-log=0 with --with-threadsafety')
49
50    if self.useThreadSafety and not ((self.sharedLibraries.useShared and self.setCompilers.dynamicLibraries) or self.framework.argDB['with-single-library']):
51      raise RuntimeError('Must use --with-shared-libraries or --with-single-library with --with-threadsafety')
52
53    self.useLog   = self.framework.argDB['with-log']
54    self.addDefine('USE_LOG',   self.useLog)
55
56    if self.compilerFlags.debugging:
57      if self.useThreadSafety:
58        raise RuntimeError('Must use --with-debugging=0 with --with-threadsafety')
59      self.addDefine('USE_DEBUG',1)
60    elif not config.setCompilers.Configure.isIBM(self.framework.getCompiler(), self.log):
61      # IBM XLC version 12.1 (BG/Q and POWER) miscompiles PetscMalloc3()
62      # by reordering "*(void**)&ptr = x" as though ptr was not modified
63      # by this statement.
64      self.addDefine('USE_MALLOC_COALESCED',1)
65
66    self.useInfo   = self.framework.argDB['with-info']
67    self.addDefine('USE_INFO',   self.useInfo)
68
69    self.useCtable = self.framework.argDB['with-ctable']
70    if self.useCtable:
71      self.addDefine('USE_CTABLE', '1')
72
73    self.useDmLandau3d = self.framework.argDB['with-dmlandau-3d']
74    if not self.useDmLandau3d:
75      self.addDefine('USE_DMLANDAU_2D',1)
76
77    # used in src/mat/impls/sbaij/seq/relax.h
78    self.libraries.saveLog()
79    if not self.libraries.isBGL():
80      self.addDefine('USE_BACKWARD_LOOP','1')
81    self.logWrite(self.libraries.restoreLog())
82
83    self.useFortranKernels = self.framework.argDB['with-fortran-kernels']
84    if not hasattr(self.compilers, 'FC') and self.useFortranKernels:
85      raise RuntimeError('Cannot use fortran kernels without a Fortran compiler')
86    if self.useFortranKernels:
87      self.addDefine('USE_FORTRAN_KERNELS', 1)
88      if self.libraries.isBGL():
89        self.addDefine('AssertAlignx(a,b)','call ALIGNX(a,b)')
90      else:
91        self.addDefine('AssertAlignx(a,b)','  ')
92
93    self.useAVX512Kernels = self.framework.argDB['with-avx512-kernels']
94    if self.useAVX512Kernels:
95      self.addDefine('USE_AVX512_KERNELS', 1)
96
97    if self.libraries.isBGL():
98      self.addDefine('Alignx(a,b)','__alignx(a,b)')
99    else:
100      self.addDefine('Alignx(a,b)','  ')
101    return
102
103  def configureISColorValueType(self):
104    '''Sets PETSC_IS_COLORING_VALUE_TYPE, PETSC_MPIU_IS_COLORING_VALUE_TYPE, and PETSC_IS_COLORING_MAX as required by ISColoring'''
105    self.isColorValueType  = self.framework.argDB['with-is-color-value-type']
106    if self.isColorValueType != 'char' and self.isColorValueType != 'short':
107      raise RuntimeError('Incorrect --with-is-color-value-type value specified. Can be either char or short. Specified value is :'+self.isColorValueType)
108    if self.isColorValueType == 'char':
109      max_value = 'UCHAR_MAX'
110      mpi_type = 'MPI_UNSIGNED_CHAR'
111      type_f = 'integer1'
112    else:
113      max_value = 'USHRT_MAX'
114      mpi_type = 'MPI_UNSIGNED_SHORT'
115      type_f = 'integer2'
116
117    self.addDefine('MPIU_IS_COLORING_VALUE_TYPE',mpi_type)
118    self.addDefine('IS_COLORING_MAX',max_value)
119    self.addDefine('IS_COLORING_VALUE_TYPE',self.isColorValueType)
120    self.addDefine('IS_COLORING_VALUE_TYPE_F',type_f)
121    return
122
123  def configure(self):
124    self.executeTest(self.configureLibraryOptions)
125    self.executeTest(self.configureISColorValueType)
126    return
127