Skip to content

Commit

Permalink
ENH: better handling of mpich for openfoam packages
Browse files Browse the repository at this point in the history
- define MPICH_SKIP_MPICXX, link libmpich instead of libmpi
  (as per disussion in PR spack#4990)

ENH: more flexible editing/patching of openfoam env files

CONFIG: comment out requirement for openmpi+thread_multiple

- was originally slated for the 1712 release and beyond, but there are
  reportedly unstable version/network combinations.
  Leave as comment for future reference, since it may be arise again.

STYLE: renamed openfoam-site.patch as 1706-site.patch (and reformatted)

- to preserve against impending changes in the layout of
  config.{csh,sh}/settings
  • Loading branch information
olesenm authored and scheibelp committed Dec 20, 2017
1 parent 235c3c1 commit ef2e515
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 69 deletions.
22 changes: 22 additions & 0 deletions var/spack/repos/builtin/packages/openfoam-com/1706-site.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--- OpenFOAM-plus.orig/etc/config.sh/settings 2016-12-23 15:22:59.000000000 +0100
+++ OpenFOAM-plus/etc/config.sh/settings 2017-04-04 12:21:31.295498985 +0200
@@ -157,7 +157,7 @@
export FOAM_EXT_LIBBIN=$WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER$WM_PRECISION_OPTION$WM_LABEL_OPTION/lib

# Site-specific directory
-siteDir="${WM_PROJECT_SITE:-$WM_PROJECT_INST_DIR/site}"
+siteDir="${WM_PROJECT_SITE:-$WM_PROJECT_DIR/site}" #SPACK: not in parent directory

# Shared site executables/libraries
# Similar naming convention as ~OpenFOAM expansion
--- OpenFOAM-plus.orig/etc/config.csh/settings 2016-12-23 15:22:59.000000000 +0100
+++ OpenFOAM-plus/etc/config.csh/settings 2017-03-23 12:23:52.737891912 +0100
@@ -156,7 +156,7 @@
if ( $?WM_PROJECT_SITE ) then
set siteDir=$WM_PROJECT_SITE
else
- set siteDir=$WM_PROJECT_INST_DIR/site
+ set siteDir=$WM_PROJECT_DIR/site #SPACK: not in parent directory
endif

# Shared site executables/libraries
35 changes: 0 additions & 35 deletions var/spack/repos/builtin/packages/openfoam-com/openfoam-site.patch

This file was deleted.

86 changes: 52 additions & 34 deletions var/spack/repos/builtin/packages/openfoam-com/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,12 @@ def write_environ(environ, **kwargs):
posix[=None] If set, the name of the POSIX file to rewrite.
cshell[=None] If set, the name of the C-shell file to rewrite.
"""
posix = kwargs.get('posix', None)
if posix:
_write_environ_file(posix, environ, format_export)
cshell = kwargs.get('cshell', None)
if cshell:
_write_environ_file(cshell, environ, format_setenv)
rcfile = kwargs.get('posix', None)
if rcfile:
_write_environ_file(rcfile, environ, format_export)
rcfile = kwargs.get('cshell', None)
if rcfile:
_write_environ_file(rcfile, environ, format_setenv)


def rewrite_environ_files(environ, **kwargs):
Expand All @@ -179,22 +179,29 @@ def rewrite_environ_files(environ, **kwargs):
posix[=None] If set, the name of the POSIX file to rewrite.
cshell[=None] If set, the name of the C-shell file to rewrite.
"""
posix = kwargs.get('posix', None)
if posix and os.path.isfile(posix):
rcfile = kwargs.get('posix', None)
if rcfile and os.path.isfile(rcfile):
for k, v in environ.items():
filter_file(
r'^(\s*export\s+%s)=.*$' % k,
r'\1=%s' % v,
posix,
backup=False)
cshell = kwargs.get('cshell', None)
if cshell and os.path.isfile(cshell):
regex = r'^(\s*export\s+{0})=.*$'.format(k)
if not v:
replace = r'unset {0} #SPACK: unset'.format(k)
elif v.startswith('#'):
replace = r'unset {0} {1}'.format(k, v)
else:
replace = r'\1={0}'.format(v)
filter_file(regex, replace, rcfile, backup=False)

rcfile = kwargs.get('cshell', None)
if rcfile and os.path.isfile(rcfile):
for k, v in environ.items():
filter_file(
r'^(\s*setenv\s+%s)\s+.*$' % k,
r'\1 %s' % v,
cshell,
backup=False)
regex = r'^(\s*setenv\s+{0})\s+.*$'.format(k)
if not v:
replace = r'unsetenv {0} #SPACK: unset'.format(k)
elif v.startswith('#'):
replace = r'unsetenv {0} {1}'.format(k, v)
else:
replace = r'\1 {0}'.format(v)
filter_file(regex, replace, rcfile, backup=False)


def foamAddPath(*args):
Expand Down Expand Up @@ -222,15 +229,20 @@ def pkglib(package, pre=None):


def mplib_content(spec, pre=None):
"""The mpi settings to have wmake
use spack information with minimum modifications to OpenFOAM.
"""The mpi settings (from spack) for the OpenFOAM wmake includes, which
allows later reuse within OpenFOAM.
Optional parameter 'pre' to provide alternative prefix
"""
mpi_spec = spec['mpi']
bin = mpi_spec.prefix.bin
inc = mpi_spec.prefix.include
lib = pkglib(mpi_spec)

libname = 'mpi'
if 'mpich' in mpi_spec.name:
libname = 'mpich'

if pre:
bin = join_path(pre, os.path.basename(bin))
inc = join_path(pre, os.path.basename(inc))
Expand All @@ -244,9 +256,9 @@ def mplib_content(spec, pre=None):
'include': inc,
'bindir': bin,
'libdir': lib,
'FLAGS': '-DOMPI_SKIP_MPICXX -DMPICH_IGNORE_CXX_SEEK',
'FLAGS': '-DOMPI_SKIP_MPICXX -DMPICH_SKIP_MPICXX',
'PINC': '-I{0}'.format(inc),
'PLIBS': '-L{0} -lmpi'.format(lib),
'PLIBS': '-L{0} -l{1}'.format(lib, libname),
}
return info

Expand Down Expand Up @@ -296,8 +308,9 @@ class OpenfoamCom(Package):
provides('openfoam')
depends_on('mpi')

# After 1712 require openmpi+thread_multiple for collated output
conflicts('^openmpi~thread_multiple', when='@1712:')
# After 1712, could suggest openmpi+thread_multiple for collated output
# but particular mixes of mpi versions and InfiniBand may not work so well
# conflicts('^openmpi~thread_multiple', when='@1712:')

depends_on('zlib')
depends_on('fftw')
Expand Down Expand Up @@ -339,11 +352,7 @@ class OpenfoamCom(Package):
patch('1612-mgridgen-lib.patch', when='@1612')
patch('1612-scotch-metis-lib.patch', when='@1612')
patch('1612-zoltan-lib.patch', when='@1612')

# This patch is reasonably version-invariant
# 1) default site directly under WM_PROJECT_DIR
# 2) no FOAM_EXT_LIBBIN required
patch('openfoam-site.patch', when='@1706:')
patch('1706-site.patch', when='@1706')

# Some user config settings
# default: 'compile-option': 'RpathOpt',
Expand Down Expand Up @@ -474,13 +483,22 @@ def patch(self):
# Filtering: bashrc,cshrc (using a patch is less flexible)
edits = {
'WM_THIRD_PARTY_DIR':
r'$WM_PROJECT_DIR/ThirdParty #SPACK: No separate third-party',
r'$WM_PROJECT_DIR/ThirdParty #SPACK: No separate third-party',
}
rewrite_environ_files( # Adjust etc/bashrc and etc/cshrc
rewrite_environ_files( # etc/{bashrc,cshrc}
edits,
posix=join_path('etc', 'bashrc'),
cshell=join_path('etc', 'cshrc'))

# Filtering: settings
edits = {
'FOAM_EXT_LIBBIN': '#SPACK: No separate third-party', # ie, unset
}
rewrite_environ_files( # etc/config.{csh,sh}/settings
edits,
posix=join_path('etc', 'config.sh', 'settings'),
cshell=join_path('etc', 'config.csh', 'settings'))

def configure(self, spec, prefix):
"""Make adjustments to the OpenFOAM configuration files in their various
locations: etc/bashrc, etc/config.sh/FEATURE and customizations that
Expand All @@ -490,7 +508,7 @@ def configure(self, spec, prefix):
# Filtering bashrc, cshrc
edits = {}
edits.update(self.foam_arch.foam_dict())
rewrite_environ_files( # Adjust etc/bashrc and etc/cshrc
rewrite_environ_files( # etc/{bashrc,cshrc}
edits,
posix=join_path('etc', 'bashrc'),
cshell=join_path('etc', 'cshrc'))
Expand Down

0 comments on commit ef2e515

Please sign in to comment.