CONFIG: update c++ standard, some compiler rules (partially addresses #2209)

- migrate to c++14 for most compilers *except* gcc.
  There are still many systems in use with gcc-4.8.5, which does not
  support c++14.

- initial rules for nvidia compilers (pgi is will soon be defunct).
  Not fully tested...

CONFIG: provide fallback value for the user directory name

- in containers may have an unset USER env variable.
  Default to 'user' to prevent ugly looking directory names.
This commit is contained in:
Mark Olesen 2021-10-19 20:09:31 +02:00
parent 8eab653117
commit c2697f466d
31 changed files with 204 additions and 43 deletions

View File

@ -23,12 +23,12 @@ else
echo "mpirun=$(command -v mpirun || true)"
fi
echo
# Report compiler information
# Report compiler information. First non-blank line from --version output
compiler="$(wmake -show-path-cxx 2>/dev/null || true)"
if [ -x "$compiler" ]
then
echo "compiler=$compiler"
"$compiler" --version 2>/dev/null | sed -ne '1p'
"$compiler" --version 2>/dev/null | sed -e '/^$/d;q'
else
echo "compiler=unknown"
fi

View File

@ -167,22 +167,22 @@ checkUserShell
checkHostName
checkOS
# check user name
USER_NAME="$LOGNAME"
if [ $(length $USER_NAME) -eq 0 ]
then
USER_NAME="$USER"
fi
echo "$(fixlen User: $WIDTH) ${USER_NAME}"
if [ $(length $USER_NAME) -eq 0 ]
then
echo "ERROR: Cannot stat user name $USER_NAME."
echo " OpenFOAM $WM_PROJECT_VERSION needs a valid user name."
echo " Contact your system administrator. "
echo
fatalError="x${fatalError}"
fi
## # check user name
## USER_NAME="$LOGNAME"
## if [ $(length $USER_NAME) -eq 0 ]
## then
## USER_NAME="$USER"
## fi
##
## echo "$(fixlen User: $WIDTH) ${USER_NAME}"
## if [ $(length $USER_NAME) -eq 0 ]
## then
## echo "ERROR: Cannot stat user name $USER_NAME."
## echo " OpenFOAM $WM_PROJECT_VERSION needs a valid user name."
## echo " Contact your system administrator. "
## echo
## fatalError="x${fatalError}"
## fi
echo
if [ -n "$fatalError" ]

View File

@ -66,8 +66,9 @@ export WM_PROJECT_VERSION=com
export WM_COMPILER_TYPE=system
# [WM_COMPILER] - Compiler:
# = Gcc | Clang | Icc | Icx | Cray | Amd | Arm | Pgi | Fujitsu |
# = Gcc | Clang | Icc | Icx | Amd | Arm | Cray | Fujitsu |
# Gcc<digits> | Clang<digits>
# [Not well tested: Pgi | Nvidia]
export WM_COMPILER=Gcc
# [WM_PRECISION_OPTION] - Floating-point precision:
@ -162,7 +163,7 @@ unset FOAM_EXTRA_CFLAGS FOAM_EXTRA_CXXFLAGS FOAM_EXTRA_LDFLAGS
# Capture values of old directories to be cleaned from PATH, LD_LIBRARY_PATH
foamOldDirs="$WM_PROJECT_DIR $WM_THIRD_PARTY_DIR \
$HOME/$WM_PROJECT/$USER $FOAM_USER_APPBIN $FOAM_USER_LIBBIN \
$HOME/$WM_PROJECT/${USER:-user} $FOAM_USER_APPBIN $FOAM_USER_LIBBIN \
$WM_PROJECT_SITE $FOAM_SITE_APPBIN $FOAM_SITE_LIBBIN \
$FOAM_MODULE_APPBIN $FOAM_MODULE_LIBBIN"
@ -170,7 +171,7 @@ foamOldDirs="$WM_PROJECT_DIR $WM_THIRD_PARTY_DIR \
export WM_PROJECT_DIR="$projectDir"
# [WM_PROJECT_USER_DIR] - Location of user files
export WM_PROJECT_USER_DIR="$HOME/$WM_PROJECT/$USER-$WM_PROJECT_VERSION"
export WM_PROJECT_USER_DIR="$HOME/$WM_PROJECT/${USER:-user}-$WM_PROJECT_VERSION"
# [WM_PROJECT_SITE] - Location of site-specific (group) files
# Default (unset) implies WM_PROJECT_DIR/site

View File

@ -62,7 +62,7 @@ switch ("$WM_MPLIB")
# The system openmpi, discover locations via <mpicc>
case SYSTEMOPENMPI[1-9]:
# Preserve major version for the naming
set _foamMpiVersion=`echo "$WM_MPLIB" | sed -e 's/^.*MPI//'`
set _foamMpiVersion=`echo "$WM_MPLIB" | sed -e 's#^.*MPI##'`
#[fallthrough]
case SYSTEMOPENMPI:
@ -77,16 +77,17 @@ case SYSTEMOPENMPI:
endif
# Use <orte-info> (openmpi only command) to query configuration
# Parse "path:prefix:<pathname>" type of output
if ( "$MPI_ARCH_PATH" == "" ) then
set _foamFoundCmd=`which orte-info`
if ($status == 0) then
# prefix
set _foamFoundDir=`orte-info --path prefix --parsable | sed -e 's/^.*:prefix://'`
set _foamFoundDir=`orte-info --path prefix --parsable | sed -e 's#^path:[^:]*:##'`
if ( -d "$_foamFoundDir" ) then
setenv MPI_ARCH_PATH "${_foamFoundDir}"
# libdir
set _foamFoundDir=`orte-info --path libdir --parsable | sed -e 's/^.*:libdir://'`
set _foamFoundDir=`orte-info --path libdir --parsable | sed -e 's#^path:[^:]*:##'`
if ( -d "$_foamFoundDir" ) then
_foamAddLib "$_foamFoundDir"
else if ( "$MPI_ARCH_PATH" != "/usr" ) then
@ -101,7 +102,7 @@ case SYSTEMOPENMPI:
if ( "$MPI_ARCH_PATH" == "" ) then
set _foamFoundCmd=`which mpicc`
if ($status == 0) then
set _foamFoundDir=`mpicc --showme:link | sed -e 's/.*-L\([^ ]*\).*/\1/'`
set _foamFoundDir=`mpicc --showme:link | sed -e 's#.*-L\([^ ]*\).*#\1#'`
setenv MPI_ARCH_PATH "${_foamFoundDir:h}" # Prefix from libdir
_foamAddLib "$_foamFoundDir"
endif
@ -128,7 +129,7 @@ case SYSTEMOPENMPI:
# TBD: extra (major) version qualifier on name?
#-
## if ( "$FOAM_MPI" == "sys-openmpi" ) then
## set _foamMpiVersion=`echo "$MPI_ARCH_PATH" | sed -e 's/^.*mpi//'`
## set _foamMpiVersion=`echo "$MPI_ARCH_PATH" | sed -e 's#^.*mpi##'`
## switch ("$_foamMpiVersion")
## case [1-9]:
## setenv FOAM_MPI "${FOAM_MPI}${_foamMpiVersion}"

View File

@ -81,17 +81,19 @@ SYSTEMOPENMPI | SYSTEMOPENMPI[1-9])
unset MPI_ARCH_PATH
fi
# Use <orte-info> (openmpi only command) to query configuration
# Use <orte-info> (openmpi only command) to query configuration.
# Parse "path:prefix:<pathname>" type of output
if [ -z "$MPI_ARCH_PATH" ] && _foamFoundCmd="$(command -v orte-info)"
then
# prefix
_foamFoundDir="$("$_foamFoundCmd" --path prefix --parsable | sed -e 's/^.*:prefix://')"
_foamFoundDir="$("$_foamFoundCmd" --path prefix --parsable | sed -e 's#^path:[^:]*:##')"
if [ -d "$_foamFoundDir" ]
then
MPI_ARCH_PATH="${_foamFoundDir}"
# libdir
_foamFoundDir="$("$_foamFoundCmd" --path libdir --parsable | sed -e 's/^.*:libdir://')"
_foamFoundDir="$("$_foamFoundCmd" --path libdir --parsable | sed -e 's#^path:[^:]*:##')"
if [ -d "$_foamFoundDir" ]
then
_foamAddLib "$_foamFoundDir"
@ -106,7 +108,7 @@ SYSTEMOPENMPI | SYSTEMOPENMPI[1-9])
# strip off 'lib' to get the prefix directory
if [ -z "$MPI_ARCH_PATH" ] && _foamFoundCmd="$(command -v mpicc)"
then
_foamFoundDir="$("$_foamFoundCmd" --showme:link | sed -e 's/.*-L\([^ ]*\).*/\1/')"
_foamFoundDir="$("$_foamFoundCmd" --showme:link | sed -e 's#.*-L\([^ ]*\).*#\1#')"
MPI_ARCH_PATH="${_foamFoundDir%/*}" # Prefix from libdir
_foamAddLib "$_foamFoundDir"

View File

@ -66,8 +66,9 @@ setenv WM_PROJECT_VERSION com
setenv WM_COMPILER_TYPE system
# [WM_COMPILER] - Compiler:
# = Gcc | Clang | Icc | Icx | Cray | Amd | Arm | Pgi | Fujitsu |
# = Gcc | Clang | Icc | Icx | Amd | Arm | Cray | Fujitsu |
# Gcc<digits> | Clang<digits>
# [Not well tested: Pgi | Nvidia]
setenv WM_COMPILER Gcc
# [WM_PRECISION_OPTION] - Floating-point precision:

View File

@ -26,19 +26,19 @@ OpenFOAM/Alltouch -check 2>/dev/null
OSspecific/"${WM_OSTYPE:-POSIX}"/Allwmake $targetType $*
case "$WM_COMPILER" in
Mingw*)
(Mingw* | Nvidia*)
# Pstream/OpenFOAM cyclic dependency
# 1st pass: link as Pstream as single .o object
WM_MPLIB=dummy Pstream/Allwmake libo
FOAM_LINK_DUMMY_PSTREAM=libo wmake $targetType OpenFOAM
# 2nd pass: link Pstream.dll against libOpenFOAM.dll
# 2nd pass: link Pstream.{dll,so} against libOpenFOAM.{dll,so}
Pstream/Allwmake $targetType $*
# Force relink libOpenFOAM.dll against libPstream.dll
# Force relink libOpenFOAM.{dll,so} against libPstream.{dll,so}
OpenFOAM/Alltouch 2>/dev/null
;;
*)
(*)
Pstream/Allwmake $targetType $*
;;
esac

View File

@ -1,6 +1,7 @@
#------------------------------------------------------------------------------
SUFFIXES += .C .cc .cpp .cxx
CC = clang++ -std=c++11
CC = clang++ -std=c++14
c++ARCH =
c++DBUG =

View File

@ -1,3 +1,9 @@
#------------------------------------------------------------------------------
# C++14 support with gcc-5 and later, but several systems (as of 2021)
# are still using gcc-4.8.4 (centos7, suse SLES12, ...)
#
# NOTE if your system gcc is new enough can simply use c++14 too.
#------------------------------------------------------------------------------
SUFFIXES += .C .cc .cpp .cxx
CC = g++ -std=c++11

View File

@ -1,6 +1,9 @@
#------------------------------------------------------------------------------
# Intel compiler is new enough to support c++14
#------------------------------------------------------------------------------
SUFFIXES += .C .cc .cpp .cxx
CC = icpc -std=c++11
CC = icpc -std=c++14
c++ARCH =
c++DBUG =

View File

@ -1,6 +1,9 @@
#------------------------------------------------------------------------------
# Intel compiler is new enough to support c++14
#------------------------------------------------------------------------------
SUFFIXES += .C .cc .cpp .cxx
CC = icpx -std=c++11
CC = icpx -std=c++14
c++ARCH =
c++DBUG =

View File

@ -0,0 +1,13 @@
#------------------------------------------------------------------------------
# Nvidia compilers
#------------------------------------------------------------------------------
SUFFIXES += .c
cc = nvc
cARCH =
cDBUG =
cOPT = -O2
cWARN = $(FOAM_EXTRA_CFLAGS)
#------------------------------------------------------------------------------

View File

@ -0,0 +1,37 @@
#------------------------------------------------------------------------------
# Nvidia compilers
#------------------------------------------------------------------------------
SUFFIXES += .C .cc .cpp .cxx
CC = nvc++ -std=c++14
c++ARCH =
c++DBUG =
c++OPT = -O2
ptFLAGS = -DNoRepository
# - Standard warnings
# - Less restrictive warnings (may be needed for flex++, CGAL, etc.)
c++WARN = \
-Wall -Wextra \
--diag_suppress=111,128,177,185,612,998,1098 \
--display_error_number \
$(FOAM_EXTRA_CXXFLAGS)
c++LESSWARN =
# Warnings
# --------
# Run with --display_error_number to get numbers
# and --diag_suppress=XXX to suppress
#
#111-D: statement is unreachable
#128-D: loop is not reachable
#177-D: function was declared but never referenced
#185-D: dynamic initialization in unreachable code
#612-D: overloaded virtual function ... is only partially overridden
#998-D: function XX is hidden by YY -- virtual function override intended?
#1098-D: unknown attribute "fallthrough"
#
#------------------------------------------------------------------------------

View File

@ -0,0 +1,5 @@
LINK_LIBS = $(cDBUG)
LINKLIBSO = $(cc) $(cARCH) -shared
LINKEXE = $(cc) $(cARCH) -Xlinker --add-needed -Xlinker -z -Xlinker nodefs

View File

@ -0,0 +1,8 @@
LINK_LIBS = $(c++DBUG)
LINKLIBSO = $(CC) $(c++FLAGS) -shared \
$(FOAM_EXTRA_LDFLAGS)
LINKEXE = $(CC) $(c++FLAGS) \
-Xlinker --add-needed \
$(FOAM_EXTRA_LDFLAGS)

View File

@ -0,0 +1,5 @@
# Flags for compiling/linking openmp
# The USE_OMP is for OpenFOAM-specific use (general use is _OPENMP)
COMP_OPENMP = -DUSE_OMP -fopenmp
LINK_OPENMP = -lnvomp

View File

@ -1,3 +1,6 @@
#------------------------------------------------------------------------------
# PGI Compilers are defunct - now in NVIDIA HPC SDK (2021)
#------------------------------------------------------------------------------
SUFFIXES += .C .cc .cpp .cxx
CC = pgc++ -std=c++11

View File

@ -1,7 +1,10 @@
#------------------------------------------------------------------------------
# Cray compiler - a gcc variant/wrapper
# presumably new enough to support c++14
#------------------------------------------------------------------------------
include $(GENERAL_RULES)/Gcc/c++
CC = CC -std=c++11
CC = CC -std=c++14
c++ARCH = -m64 -pthread
@ -15,3 +18,5 @@ cctoo = $(Ctoo)
cpptoo = $(Ctoo)
include $(GENERAL_RULES)/Gcc/link-c++
#------------------------------------------------------------------------------

View File

@ -1,9 +1,12 @@
#------------------------------------------------------------------------------
# mingw is gcc, but new enough to support c++14
#------------------------------------------------------------------------------
include $(GENERAL_RULES)/Gcc/c++
c++ARCH = -m64 -pthread
# With gnu++11 (not c++11) to ensure __STRICT_ANSI__ is not defined
CC = x86_64-w64-mingw32-g++ -std=gnu++11
# With gnu++14 (not c++14) to ensure __STRICT_ANSI__ is not defined
CC = x86_64-w64-mingw32-g++ -std=gnu++14
include $(RULES)/c++$(WM_COMPILE_OPTION)
@ -34,3 +37,5 @@ LINKEXE = $(CC) $(c++FLAGS) \
-Wl,--strip-all \
-Wl,--force-exe-suffix \
$(FOAM_EXTRA_LDFLAGS)
#------------------------------------------------------------------------------

View File

@ -0,0 +1,12 @@
include $(GENERAL_RULES)/Nvidia/c
cARCH = -m64
# Compile option is non-mandatory, but must be non-empty
sinclude $(DEFAULT_RULES)/c$(WM_COMPILE_OPTION)
cFLAGS = $(cARCH) $(GFLAGS) $(cWARN) $(cOPT) $(cDBUG) $(LIB_HEADER_DIRS) -fPIC
ctoo = $(WM_SCHEDULER) $(cc) $(cFLAGS) -c $< -o $@
include $(GENERAL_RULES)/Nvidia/link-c

View File

@ -0,0 +1,14 @@
include $(GENERAL_RULES)/Nvidia/c++
c++ARCH = -m64
include $(DEFAULT_RULES)/c++$(WM_COMPILE_OPTION)
c++FLAGS = $(c++ARCH) $(GFLAGS) $(c++WARN) $(c++OPT) $(c++DBUG) $(ptFLAGS) $(LIB_HEADER_DIRS) -fPIC
Ctoo = $(WM_SCHEDULER) $(CC) $(c++FLAGS) -c $< -o $@
cxxtoo = $(Ctoo)
cctoo = $(Ctoo)
cpptoo = $(Ctoo)
include $(GENERAL_RULES)/Nvidia/link-c++

View File

@ -0,0 +1,2 @@
c++DBUG = -g -DFULLDEBUG
c++OPT = -O0

View File

@ -0,0 +1,2 @@
c++DBUG =
c++OPT = -O3

View File

@ -0,0 +1,2 @@
c++DBUG = -pg
c++OPT = -O2

View File

@ -0,0 +1,2 @@
cDBUG = -g -DFULLDEBUG
cOPT = -O0

View File

@ -0,0 +1,2 @@
cDBUG =
cOPT = -O3

View File

@ -0,0 +1,2 @@
cDBUG = -pg
cOPT = -O2

View File

@ -0,0 +1,13 @@
CPP = cpp -traditional-cpp $(GFLAGS)
include $(GENERAL_RULES)/standard
## include $(GENERAL_RULES)/Pgi/openmp
ifneq (,$(findstring ~openmp,$(WM_COMPILE_CONTROL)))
include $(GENERAL_RULES)/no-openmp
endif
include $(DEFAULT_RULES)/c
include $(DEFAULT_RULES)/c++
# -----------------------------------------------------------------------------

View File

@ -0,0 +1,3 @@
PFLAGS = -DMPICH_SKIP_MPICXX -DOMPI_SKIP_MPICXX
PINC = -I$(MPI_ARCH_PATH)/include
PLIBS = -L$(MPI_ARCH_PATH)/lib$(WM_COMPILER_LIB_ARCH) -L$(MPI_ARCH_PATH)/lib -lmpi

View File

@ -1,7 +1,9 @@
#------------------------------------------------------------------------------
# A clang variant
#------------------------------------------------------------------------------
include $(GENERAL_RULES)/Clang/c++
CC = armclang++ -std=c++11
CC = armclang++ -std=c++14
c++ARCH = -mcpu=native -pthread
@ -18,3 +20,5 @@ include $(GENERAL_RULES)/Clang/link-c++
LINKLIBSO += -armpl
LINKEXE += -armpl
#------------------------------------------------------------------------------

View File

@ -1,7 +1,9 @@
#------------------------------------------------------------------------------
# Fujitsu compiler - a clang variant
#------------------------------------------------------------------------------
include $(GENERAL_RULES)/Clang/c++
CC = FCC -std=c++11
CC = FCC -std=c++14
c++ARCH = -pthread
@ -15,3 +17,5 @@ cctoo = $(Ctoo)
cpptoo = $(Ctoo)
include $(GENERAL_RULES)/Clang/link-c++
#------------------------------------------------------------------------------