xref: /petsc/config/PETSc/options/libraryOptions.py (revision 01e13f7363797b80262b2aca243ce72bcaa53640)
1#!/usr/bin/env python
2from __future__ import generators
3import user
4import config.base
5import os
6
7class Configure(config.base.Configure):
8  def __init__(self, framework):
9    config.base.Configure.__init__(self, framework)
10    self.headerPrefix = ''
11    self.substPrefix  = ''
12    return
13
14  def __str__(self):
15    return ''
16
17  def setupHelp(self, help):
18    import nargs
19    help.addArgument('PETSc', '-with-log=<bool>',              nargs.ArgBool(None, 1, 'Activate logging code in PETSc'))
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-is-color-value-type=<char,short>',nargs.ArgString(None, 'short', 'char, short can store 256, 65536 colors'))
24    return
25
26  def setupDependencies(self, framework):
27    config.base.Configure.setupDependencies(self, framework)
28    self.debugging   = framework.require('PETSc.options.debugging', self)
29    self.compilers   = framework.require('config.compilers', self)
30    self.libraries   = framework.require('config.libraries', self)
31    self.types       = framework.require('config.types', self)
32    return
33
34
35
36  def configureLibraryOptions(self):
37    '''Sets PETSC_USE_DEBUG, PETSC_USE_INFO, PETSC_USE_LOG, PETSC_USE_CTABLE and PETSC_USE_FORTRAN_KERNELS'''
38    '''Also sets PETSC_AssertAlignx() in Fortran and PETSC_Alignx() in C for IBM BG/P compiler '''
39    self.useLog   = self.framework.argDB['with-log']
40    self.addDefine('USE_LOG',   self.useLog)
41
42    if self.debugging.debugging:
43      self.addDefine('USE_DEBUG', '1')
44    elif not config.setCompilers.Configure.isIBM(self.framework.getCompiler()):
45      # IBM XLC version 12.1 (BG/Q and POWER) miscompiles PetscMalloc3()
46      # by reordering "*(void**)&ptr = x" as though ptr was not modified
47      # by this statement.
48      self.addDefine('USE_MALLOC_COALESCED',1)
49
50    self.useInfo   = self.framework.argDB['with-info']
51    self.addDefine('USE_INFO',   self.useInfo)
52
53    self.useCtable = self.framework.argDB['with-ctable']
54    if self.useCtable:
55      self.addDefine('USE_CTABLE', '1')
56
57    # used in src/mat/impls/sbaij/seq/relax.h
58    if not self.libraries.isBGL():
59      self.addDefine('USE_BACKWARD_LOOP','1')
60
61    self.useFortranKernels = self.framework.argDB['with-fortran-kernels']
62    if not hasattr(self.compilers, 'FC') and self.useFortranKernels:
63      raise RuntimeError('Cannot use fortran kernels without a Fortran compiler')
64    if self.useFortranKernels:
65      self.addDefine('USE_FORTRAN_KERNELS', 1)
66      if self.libraries.isBGL():
67        self.addDefine('AssertAlignx(a,b)','call ALIGNX(a,b)')
68      else:
69        self.addDefine('AssertAlignx(a,b)','  ')
70
71    if self.libraries.isBGL():
72      self.addDefine('Alignx(a,b)','__alignx(a,b)')
73    else:
74      self.addDefine('Alignx(a,b)','  ')
75    return
76
77  def configureISColorValueType(self):
78    '''Sets PETSC_IS_COLOR_VALUE_TYPE, MPIU_COLORING_VALUE, IS_COLORING_MAX required by ISColor'''
79    self.isColorValueType  = self.framework.argDB['with-is-color-value-type']
80    if self.isColorValueType != 'char' and self.isColorValueType != 'short':
81      raise RuntimeError('Incorrect --with-is-color-value-type value specified. Can be either char or short. Specified value is :'+self.isColorValueType)
82    if self.isColorValueType == 'char':
83      max = pow(2,self.types.sizes['known-sizeof-char']*self.types.bits_per_byte)-1
84      mpi_type = 'MPI_UNSIGNED_CHAR'
85      sz = 'PETSC_SIZEOF_CHAR'
86    else:
87      max = pow(2,self.types.sizes['known-sizeof-short']*self.types.bits_per_byte)-1
88      mpi_type = 'MPI_UNSIGNED_SHORT'
89      sz  = 'PETSC_SIZEOF_SHORT'
90
91    self.framework.addDefine('MPIU_COLORING_VALUE',mpi_type)
92    self.framework.addDefine('IS_COLORING_MAX',max)
93    self.addDefine('IS_COLOR_VALUE_TYPE', self.isColorValueType)
94    self.addDefine('IS_COLOR_VALUE_TYPE_SIZE', sz)
95    return
96
97  def configure(self):
98    self.executeTest(self.configureLibraryOptions)
99    self.executeTest(self.configureISColorValueType)
100    return
101