xref: /petsc/config/PETSc/options/libraryOptions.py (revision 7d5fd1e4d9337468ad3f05b65b7facdcd2dfd2a4)
1#!/usr/bin/env python
2from __future__ import generators
3import config.base
4import os
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 __str__(self):
14    return ''
15
16  def setupHelp(self, help):
17    import nargs
18    help.addArgument('PETSc', '-with-log=<bool>',              nargs.ArgBool(None, 1, 'Activate logging code in PETSc'))
19    help.addArgument('PETSc', '-with-threadsafety=<bool>',     nargs.ArgBool(None, 0, 'Allow individual threads in PETSc to call PETSc routines'))
20    help.addArgument('PETSc', '-with-info=<bool>',             nargs.ArgBool(None, 1, 'Activate PetscInfo() (i.e. -info)  code in PETSc'))
21    help.addArgument('PETSc', '-with-ctable=<bool>',           nargs.ArgBool(None, 1, 'Activate CTABLE hashing for certain search functions - to conserve memory'))
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_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    # used in src/mat/impls/sbaij/seq/relax.h
74    self.libraries.saveLog()
75    if not self.libraries.isBGL():
76      self.addDefine('USE_BACKWARD_LOOP','1')
77    self.logWrite(self.libraries.restoreLog())
78
79    self.useFortranKernels = self.framework.argDB['with-fortran-kernels']
80    if not hasattr(self.compilers, 'FC') and self.useFortranKernels:
81      raise RuntimeError('Cannot use fortran kernels without a Fortran compiler')
82    if self.useFortranKernels:
83      self.addDefine('USE_FORTRAN_KERNELS', 1)
84      if self.libraries.isBGL():
85        self.addDefine('AssertAlignx(a,b)','call ALIGNX(a,b)')
86      else:
87        self.addDefine('AssertAlignx(a,b)','  ')
88
89    self.useAVX512Kernels = self.framework.argDB['with-avx512-kernels']
90    if self.useAVX512Kernels:
91      self.addDefine('USE_AVX512_KERNELS', 1)
92
93    if self.libraries.isBGL():
94      self.addDefine('Alignx(a,b)','__alignx(a,b)')
95    else:
96      self.addDefine('Alignx(a,b)','  ')
97    return
98
99  def configureISColorValueType(self):
100    '''Sets PETSC_IS_COLORING_VALUE_TYPE, PETSC_MPIU_IS_COLORING_VALUE_TYPE, and PETSC_IS_COLORING_MAX as required by ISColoring'''
101    self.isColorValueType  = self.framework.argDB['with-is-color-value-type']
102    if self.isColorValueType != 'char' and self.isColorValueType != 'short':
103      raise RuntimeError('Incorrect --with-is-color-value-type value specified. Can be either char or short. Specified value is :'+self.isColorValueType)
104    if self.isColorValueType == 'char':
105      max_value = 'UCHAR_MAX'
106      mpi_type = 'MPI_UNSIGNED_CHAR'
107      type_f = 'integer1'
108    else:
109      max_value = 'USHRT_MAX'
110      mpi_type = 'MPI_UNSIGNED_SHORT'
111      type_f = 'integer2'
112
113    self.addDefine('MPIU_IS_COLORING_VALUE_TYPE',mpi_type)
114    self.addDefine('IS_COLORING_MAX',max_value)
115    self.addDefine('IS_COLORING_VALUE_TYPE',self.isColorValueType)
116    self.addDefine('IS_COLORING_VALUE_TYPE_F',type_f)
117    return
118
119  def configure(self):
120    self.executeTest(self.configureLibraryOptions)
121    self.executeTest(self.configureISColorValueType)
122    return
123