xref: /petsc/config/BuildSystem/config/packages/HPDDM.py (revision 74df5e01f481fb3fe90b32c3b4345ef0122eb3ce)
1import config.package
2
3class Configure(config.package.Package):
4  def __init__(self,framework):
5    config.package.Package.__init__(self,framework)
6    self.version                = '2.3.5'
7    self.gitcommit              = 'v'+self.version # main sep-27-2025
8    self.download               = ['git://https://github.com/hpddm/hpddm','https://github.com/hpddm/hpddm/archive/'+self.gitcommit+'.tar.gz']
9    self.minversion             = '2.2.1'
10    self.versionname            = 'HPDDM_VERSION'
11    self.versioninclude         = 'HPDDM_define.hpp'
12    self.buildLanguages         = ['Cxx']
13    self.functions              = []
14    self.includes               = ['HPDDM.hpp']
15    self.skippackagewithoptions = 1
16    self.linkedbypetsc          = 0
17    self.builtafterpetsc        = 1
18    self.hastestsdatafiles      = 1
19    return
20
21  def setupDependencies(self,framework):
22    config.package.Package.setupDependencies(self,framework)
23    self.setCompilers    = framework.require('config.setCompilers',self)
24    self.sharedLibraries = framework.require('PETSc.options.sharedLibraries',self)
25    self.blasLapack      = framework.require('config.packages.BlasLapack',self)
26    self.cxxlibs         = framework.require('config.packages.cxxlibs',self)
27    self.mathlib         = framework.require('config.packages.mathlib',self)
28    self.flibs           = framework.require('config.packages.flibs',self)
29    self.deps            = [self.blasLapack,self.cxxlibs,self.mathlib,self.flibs] # KSPHPDDM
30    self.mpi             = framework.require('config.packages.MPI',self)
31    self.slepc           = framework.require('config.packages.SLEPc',self)
32    self.odeps           = [self.mpi,self.slepc] # KSPHPDDM + PCHPDDM
33    return
34
35  def Install(self):
36    import os
37    if self.blasLapack.mkl and not self.blasLapack.mkl_spblas_h:
38      raise RuntimeError('Cannot use HPDDM with the MKL as \'mkl_spblas.h\' was not found, check for missing --with-blaslapack-include=/opt/intel/mkl/include (or similar)')
39    buildDir = os.path.join(self.packageDir,'petsc-build')
40    self.pushLanguage('Cxx')
41    cxx = self.getCompiler()
42    cxxflags = self.getCompilerFlags()
43    self.popLanguage()
44    if self.framework.argDB['prefix'] and not 'package-prefix-hash' in self.argDB:
45      PETSC_DIR  = os.path.abspath(os.path.expanduser(self.argDB['prefix']))
46      PETSC_ARCH = ''
47      prefix     = os.path.abspath(os.path.expanduser(self.argDB['prefix']))
48    else:
49      PETSC_DIR  = self.petscdir.dir
50      PETSC_ARCH = self.arch
51      prefix     = os.path.join(self.petscdir.dir,self.arch)
52    incDir = os.path.join(prefix,'include')
53    libDir = os.path.join(prefix,self.libDirs[0])
54    self.addMakeMacro('HPDDM','yes')
55    self.include = [incDir]
56    if not hasattr(self.framework,'packages'):
57      self.framework.packages = []
58    self.framework.packages.append(self)
59    try:
60      self.logPrintBox('Copying HPDDM; this may take several seconds')
61      output,err,ret = config.package.Package.executeShellCommand(['cp','-rf',os.path.join(self.packageDir,'include'),prefix],timeout=100,log=self.log) # cannot use shutil.copytree since target directory likely exists
62      self.log.write(output+err)
63    except RuntimeError as e:
64      raise RuntimeError('Error copying HPDDM: '+str(e))
65    if self.checkSharedLibrariesEnabled():
66      ldflags = ' '.join(self.setCompilers.sharedLibraryFlags)
67      cxxflags += ' '+self.headers.toStringNoDupes(self.dinclude+[os.path.join(PETSC_DIR,'include'),incDir])
68      if self.argDB['with-single-library']:
69        ldflags += ' '+self.libraries.toStringNoDupes(self.dlib+[os.path.join(libDir,'libpetsc')])
70      else:
71        ldflags += ' '+self.libraries.toStringNoDupes(self.dlib+[os.path.join(libDir,'libpetscml'),'-lpetsctao -lpetscts -lpetscsnes -lpetscksp -lpetscdm -lpetscmat -lpetscvec -lpetscsys'])
72      oldFlags = self.compilers.CXXPPFLAGS
73      self.compilers.CXXPPFLAGS += ' -I'+incDir
74      self.checkVersion()
75      self.compilers.CXXPPFLAGS = oldFlags
76      # check for Windows-specific define
77      if self.sharedLibraries.getMakeMacro('PETSC_DLL_EXPORTS'):
78        cxxflags += ' -Dpetsc_EXPORTS'
79      if self.slepc.found:
80        self.addPost(self.packageDir, cxx + ' ' + cxxflags + ' ' + os.path.join(self.packageDir,'interface','hpddm_petsc.cpp') + ' ' + ldflags + ' -o ' + os.path.join(libDir,'libhpddm_petsc.' + self.setCompilers.sharedLibraryExt))
81        return self.installDir
82      else:
83        self.logPrintWarning('Compiling HPDDM without SLEPc, PCHPDDM won\'t be available, unless reconfiguring with --download-slepc or configuring SLEPc with --download-hpddm')
84    else:
85      self.logPrintWarning('Skipping PCHPDDM installation, remove --with-shared-libraries=0')
86    self.logPrintBox('HPDDM examples are available at '+os.path.join(self.packageDir,'examples'))
87    return self.installDir
88