xref: /petsc/config/PETSc/options/libraryOptions.py (revision bcab024551cbaaaa7f49e357634a3584f91cb6d5)
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-64-bit-indices=<bool>',   nargs.ArgBool(None, 0, 'Use 64 bit integers (long long) for indexing in vectors and matrices'))
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.debugging   = framework.require('PETSc.options.debugging', self)
30    self.compilers   = framework.require('config.compilers', self)
31    self.libraries   = framework.require('config.libraries', self)
32    self.types       = framework.require('config.types', self)
33    self.scalarTypes = framework.require('PETSc.options.scalarTypes', self)
34    return
35
36
37
38  def configureLibraryOptions(self):
39    '''Sets PETSC_USE_DEBUG, PETSC_USE_INFO, PETSC_USE_LOG, PETSC_USE_CTABLE and PETSC_USE_FORTRAN_KERNELS'''
40    '''Also sets PETSC_AssertAlignx() in Fortran and PETSC_Alignx() in C for IBM BG/P compiler '''
41    self.useLog   = self.framework.argDB['with-log']
42    self.addDefine('USE_LOG',   self.useLog)
43
44    if self.debugging.debugging:
45      self.addDefine('USE_DEBUG', '1')
46    elif not config.setCompilers.Configure.isIBM(self.framework.getCompiler()):
47      # IBM XLC version 12.1 (BG/Q and POWER) miscompiles PetscMalloc3()
48      # by reordering "*(void**)&ptr = x" as though ptr was not modified
49      # by this statement.
50      self.addDefine('USE_MALLOC_COALESCED',1)
51
52    self.useInfo   = self.framework.argDB['with-info']
53    self.addDefine('USE_INFO',   self.useInfo)
54
55    self.useCtable = self.framework.argDB['with-ctable']
56    if self.useCtable:
57      self.addDefine('USE_CTABLE', '1')
58
59    # used in src/mat/impls/sbaij/seq/relax.h
60    if not self.libraries.isBGL():
61      self.addDefine('USE_BACKWARD_LOOP','1')
62
63    self.useFortranKernels = self.framework.argDB['with-fortran-kernels']
64    if not hasattr(self.compilers, 'FC') and self.useFortranKernels:
65      raise RuntimeError('Cannot use fortran kernels without a Fortran compiler')
66    if self.useFortranKernels:
67      self.addDefine('USE_FORTRAN_KERNELS', 1)
68      if self.libraries.isBGL():
69        self.addDefine('AssertAlignx(a,b)','call ALIGNX(a,b)')
70      else:
71        self.addDefine('AssertAlignx(a,b)','  ')
72
73    if self.libraries.isBGL():
74      self.addDefine('Alignx(a,b)','__alignx(a,b)')
75    else:
76      self.addDefine('Alignx(a,b)','  ')
77
78    if self.framework.argDB['with-64-bit-indices']:
79      self.integerSize = 64
80      self.addDefine('USE_64BIT_INDICES', 1)
81      if self.libraries.check('-lgcc_s.1', '__floatdidf'):
82        self.compilers.LIBS += ' '+self.libraries.getLibArgument('-lgcc_s.1')
83    else:
84      self.integerSize = 32
85    return
86
87  def configureISColorValueType(self):
88    '''Sets PETSC_IS_COLOR_VALUE_TYPE, MPIU_COLORING_VALUE, IS_COLORING_MAX required by ISColor'''
89    self.isColorValueType  = self.framework.argDB['with-is-color-value-type']
90    if self.isColorValueType != 'char' and self.isColorValueType != 'short':
91      raise RuntimeError('Incorrect --with-is-color-value-type value specified. Can be either char or short. Specified value is :'+self.isColorValueType)
92    if self.isColorValueType == 'char':
93      max = pow(2,self.types.sizes['known-sizeof-char']*self.types.bits_per_byte)-1
94      mpi_type = 'MPI_UNSIGNED_CHAR'
95      sz = 'PETSC_SIZEOF_CHAR'
96    else:
97      max = pow(2,self.types.sizes['known-sizeof-short']*self.types.bits_per_byte)-1
98      mpi_type = 'MPI_UNSIGNED_SHORT'
99      sz  = 'PETSC_SIZEOF_SHORT'
100
101    self.framework.addDefine('MPIU_COLORING_VALUE',mpi_type)
102    self.framework.addDefine('IS_COLORING_MAX',max)
103    self.addDefine('IS_COLOR_VALUE_TYPE', self.isColorValueType)
104    self.addDefine('IS_COLOR_VALUE_TYPE_SIZE', sz)
105    return
106
107  def configure(self):
108    self.executeTest(self.configureLibraryOptions)
109    self.executeTest(self.configureISColorValueType)
110    return
111