- prefix FOAM_MPI and library directories with 'sys-' for system versions for uniform identication. WM_MPLIB | libdir (FOAM_MPI) | old naming | SYSTEMMPI | sys-mpi | mpi | SYSTEMOPENMPI | sys-openmpi | openmpi-system | - prefix preferences with 'prefs.' to make them more easily identifiable, and update bin/tools/create-mpi-config accordingly Old name: config.{csh,sh}/openmpi New name: config.{csh,sh}/prefs.openmpi - additional mpi preferences now available: * prefs.intelmpi * prefs.mpich ... CONFIG: added hook for EASYBUILDMPI (eb-mpi), somewhat like USERMPI - EasyBuild uses mpicc when compiling, so no explicit wmake rules are used ENH: support different major versions for system openmpi - for example, with WM_MPLIB=SYSTEMOPENMPI2 defines FOAM_MPI=sys-openmpi2 and thus creates lib/sys-openmpi2 ENH: centralize handling of mpi as 'mpi-rules' Before: sinclude $(GENERAL_RULES)/mplib$(WM_MPLIB) sinclude $(DEFAULT_RULES)/mplib$(WM_MPLIB) ifeq (,$(FOAM_MPI_LIBBIN)) FOAM_MPI_LIBBIN := $(FOAM_LIBBIN)/$(FOAM_MPI) endif After: include $(GENERAL_RULES)/mpi-rules - also allows variants such as SYSTEMOPENMPI2 to be handled separately
284 lines
7.0 KiB
Bash
Executable File
284 lines
7.0 KiB
Bash
Executable File
#!/bin/sh
|
|
#------------------------------------------------------------------------------
|
|
# ========= |
|
|
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
|
# \\ / O peration |
|
|
# \\ / A nd | www.openfoam.com
|
|
# \\/ M anipulation |
|
|
#------------------------------------------------------------------------------
|
|
# Copyright (C) 2020 OpenCFD Ltd.
|
|
#------------------------------------------------------------------------------
|
|
# License
|
|
# This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
|
|
#
|
|
# Script
|
|
# bin/tools/create-mpi-config
|
|
#
|
|
# Description
|
|
# Define hard-coded packaging settings for MPI flavours,
|
|
# primarily for system openmpi.
|
|
# This eliminates a runtime dependency on mpicc, for example.
|
|
#
|
|
# Instead of querying/parsing 'mpicc --showme:link' each time,
|
|
# it is done once during packaging.
|
|
#
|
|
# Environment
|
|
# FOAM_MPI, MPI_ARCH_PATH, DEB_TARGET_MULTIARCH
|
|
#
|
|
# Possible Dependencies
|
|
# - dpkg-architecture
|
|
# - mpicc
|
|
#
|
|
# Notes
|
|
# Run from top-level directory when creating config files
|
|
#
|
|
#------------------------------------------------------------------------------
|
|
printHelp() {
|
|
exec 1>&2
|
|
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
|
|
cat<<USAGE
|
|
|
|
usage: ${0##*/} options
|
|
|
|
options:
|
|
-dry-run, -n Report but do not write config files
|
|
-no-mpicc Bypass any use of mpicc
|
|
-query-openmpi Report installation directory for system openmpi
|
|
-write-openmpi Query system openmpi and write config files
|
|
-write Write config files using FOAM_MPI, MPI_ARCH_PATH
|
|
|
|
Define hard-coded packaging settings for MPI flavours.
|
|
|
|
Equivalent options:
|
|
-write-system-openmpi | -write-openmpi
|
|
-query-system-openmpi | -query-openmpi
|
|
|
|
USAGE
|
|
exit 0 # A clean exit
|
|
}
|
|
|
|
|
|
# Report error and exit
|
|
die()
|
|
{
|
|
exec 1>&2
|
|
echo
|
|
echo "Error encountered:"
|
|
while [ "$#" -ge 1 ]; do echo " $1"; shift; done
|
|
echo
|
|
echo "See '${0##*/} -help' for usage"
|
|
echo
|
|
exit 1
|
|
}
|
|
|
|
|
|
#------------------------------------------------------------------------------
|
|
# Options
|
|
unset optDryRun
|
|
withMpicc="mpicc"
|
|
|
|
# Get installation directory for system openmpi
|
|
# - from "mpicc --showme:link"
|
|
# - manual fallback
|
|
#
|
|
# The mpicc content looks like this:
|
|
# ----
|
|
# ... -L/usr/lib64/mpi/gcc/openmpi/lib64 -lmpi
|
|
# ... -L/usr/lib64/mpi/gcc/openmpi2/lib64 -lmpi
|
|
# ... -L/usr/lib64/openmpi/lib -lmpi
|
|
# ----
|
|
|
|
query_system_openmpi()
|
|
{
|
|
unset arch_path
|
|
|
|
if [ -n "$withMpicc" ]
|
|
then
|
|
arch_path=$(mpicc --showme:link 2>/dev/null | sed -e 's/^.*-L\([^ ]*\).*/\1/')
|
|
arch_path="${arch_path%/*}" # prefix from libdir
|
|
|
|
if [ -n "$arch_path" ]
|
|
then
|
|
echo "$arch_path"
|
|
return 0 # Clean exit
|
|
fi
|
|
|
|
echo "No mpicc found. Attempt manually" 1>&2
|
|
fi
|
|
|
|
|
|
# Manual discovery
|
|
if [ -z "$DEB_TARGET_MULTIARCH" ]
|
|
then
|
|
DEB_TARGET_MULTIARCH=$(dpkg-architecture -qDEB_TARGET_MULTIARCH 2>/dev/null || true)
|
|
fi
|
|
|
|
# Include is under /usr/lib... (eg, debian, openSUSE)
|
|
# Note this cannot handle (openmpi | openmpi1 | openmpi2 | ...) include directories
|
|
# unless we also try to grab information out of PATH or LD_LIBRARY_PATH
|
|
for testdir in \
|
|
/usr/lib/"${DEB_TARGET_MULTIARCH:+${DEB_TARGET_MULTIARCH}/}"openmpi \
|
|
/usr/lib64/mpi/gcc/openmpi \
|
|
;
|
|
do
|
|
if [ -e "$testdir/include/mpi.h" ]
|
|
then
|
|
echo "$testdir"
|
|
return 0 # Clean exit
|
|
fi
|
|
done
|
|
|
|
# Include is under /usr/include (eg, RedHat)
|
|
for testdir in \
|
|
/usr/include/openmpi-"$(uname -m)" \
|
|
/usr/include/openmpi \
|
|
;
|
|
do
|
|
if [ -e "$testdir/mpi.h" ]
|
|
then
|
|
echo "/usr"
|
|
return 0 # Clean exit
|
|
fi
|
|
done
|
|
|
|
# Partial env from RedHat "module load mpi/openmpi-x86_64"
|
|
#
|
|
## MPI_COMPILER=openmpi-x86_64
|
|
## MPI_HOME=/usr/lib64/openmpi
|
|
## MPI_BIN=/usr/lib64/openmpi/bin
|
|
## MPI_LIB=/usr/lib64/openmpi/lib
|
|
## MPI_INCLUDE=/usr/include/openmpi-x86_64
|
|
## MPI_SUFFIX=_openmpi
|
|
|
|
|
|
# Failed (should not happen)
|
|
# - report '/usr', but with error code 2
|
|
echo "/usr"
|
|
return 2
|
|
}
|
|
|
|
|
|
# Generate etc/config.{csh,sh}/MPI-TYPE files
|
|
# based on the values for FOAM_MPI and MPI_ARCH_PATH
|
|
|
|
create_files()
|
|
{
|
|
[ -n "$FOAM_MPI" ] || die "FOAM_MPI not set"
|
|
|
|
# MPI-name without trailing major version
|
|
mpiName="${FOAM_MPI%[0-9]}"
|
|
|
|
# The prefs name
|
|
prefsName="prefs.$mpiName"
|
|
|
|
if [ -d "$MPI_ARCH_PATH" ]
|
|
then
|
|
echo "Define $FOAM_MPI with $MPI_ARCH_PATH" 1>&2
|
|
|
|
case "$mpiName" in
|
|
(sys-openmpi | openmpi-system)
|
|
|
|
# POSIX shell
|
|
prefsFile="etc/config.sh/$prefsName"
|
|
if [ -d "${prefsFile%/*}" ] || [ -n "$optDryRun" ]
|
|
then
|
|
(
|
|
if [ -n "$optDryRun" ]
|
|
then
|
|
exec 1>&2
|
|
else
|
|
exec 1> "$prefsFile"
|
|
fi
|
|
|
|
echo "${optDryRun}Write $prefsFile" 1>&2
|
|
cat << CONTENT
|
|
# $prefsFile
|
|
#
|
|
# Packaging configured value for $FOAM_MPI
|
|
export MPI_ARCH_PATH="$MPI_ARCH_PATH"
|
|
#----
|
|
CONTENT
|
|
)
|
|
else
|
|
echo "Cannot write $prefsFile - no directory" 1>&2
|
|
fi
|
|
|
|
|
|
# C-shell
|
|
prefsFile="etc/config.csh/$prefsName"
|
|
if [ -d "${prefsFile%/*}" ] || [ -n "$optDryRun" ]
|
|
then
|
|
(
|
|
if [ -n "$optDryRun" ]
|
|
then
|
|
exec 1>&2
|
|
else
|
|
exec 1> "$prefsFile"
|
|
fi
|
|
|
|
echo "${optDryRun}Write $prefsFile" 1>&2
|
|
cat << CONTENT
|
|
# $prefsFile
|
|
#
|
|
# Packaging configured value for $FOAM_MPI
|
|
setenv MPI_ARCH_PATH "$MPI_ARCH_PATH"
|
|
#----
|
|
CONTENT
|
|
)
|
|
else
|
|
echo "Cannot write $prefsFile - no directory" 1>&2
|
|
fi
|
|
;;
|
|
esac
|
|
else
|
|
echo "Warning: $FOAM_MPI with bad MPI_ARCH_PATH: $MPI_ARCH_PATH" 1>&2
|
|
# TBD - remove old/bad entries?
|
|
#
|
|
# rm -f "etc/config.sh/$prefsName" "etc/config.csh/$prefsName"
|
|
fi
|
|
}
|
|
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
# Parse options
|
|
while [ "$#" -gt 0 ]
|
|
do
|
|
case "$1" in
|
|
'') true ;; # Discard empty arguments
|
|
-h | -help* | --help*) printHelp ;;
|
|
-n | -dry-run) optDryRun="(dry-run) " ;;
|
|
|
|
-no-mpicc)
|
|
unset withMpicc
|
|
;;
|
|
|
|
-query-openmpi | -query-system-openmpi)
|
|
query_system_openmpi
|
|
exit $?
|
|
;;
|
|
|
|
-write-openmpi | -write-system-openmpi)
|
|
if MPI_ARCH_PATH=$(query_system_openmpi)
|
|
then
|
|
FOAM_MPI="sys-openmpi" create_files
|
|
else
|
|
die "Failed query for system openmpi"
|
|
fi
|
|
;;
|
|
|
|
-write)
|
|
create_files
|
|
;;
|
|
|
|
*)
|
|
echo "Ignore unknown option/argument: '$1'" 1>&2
|
|
;;
|
|
esac
|
|
shift
|
|
done
|
|
|
|
exit 0 # A clean exit, if we get this far
|
|
|
|
# -----------------------------------------------------------------------------
|