Skip to content

Commit

Permalink
Bump minimum C++ standard from 11 to 14. (AMReX-Codes#1787)
Browse files Browse the repository at this point in the history
This is well-supported now and will allow a lot of the code in amrex to be simplified. 

I have also bumped the version on the Cuda 9 CI test to Cuda 9.2 and GCC 6.5.0, since the old combination did not work with C++14.
  • Loading branch information
atmyers authored Feb 16, 2021
1 parent 3ed36ff commit 4a332b5
Show file tree
Hide file tree
Showing 15 changed files with 69 additions and 75 deletions.
23 changes: 18 additions & 5 deletions .github/workflows/dependencies/dependencies_nvcc9.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,24 @@ sudo apt-get update

sudo apt-get install -y --no-install-recommends\
build-essential \
g++-4.8 \
gfortran-4.8 \
g++-6 \
gfortran-6 \
libopenmpi-dev \
openmpi-bin \
nvidia-cuda-dev \
nvidia-cuda-toolkit
openmpi-bin

sudo wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/7fa2af80.pub
sudo apt-key add 7fa2af80.pub
echo "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64 /" \
| sudo tee /etc/apt/sources.list.d/cuda.list
sudo apt-get update
sudo apt-get install -y \
cuda-command-line-tools-9-2 \
cuda-compiler-9-2 \
cuda-minimal-build-9-2 \
cuda-nvml-dev-9-2 \
cuda-nvtx-9-2 \
cuda-curand-dev-9.2

sudo ln -s cuda-9.2 /usr/local/cuda


30 changes: 16 additions & 14 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ jobs:
# Build libamrex and all tutorials
tutorials-nofortran:
name: GNU@7.5 C++11 w/o Fortran [tutorials]
name: GNU@7.5 C++14 w/o Fortran [tutorials]
runs-on: ubuntu-18.04
env: {CXXFLAGS: "-Werror -Wshadow -Woverloaded-virtual -Wunreachable-code -fno-operator-names"}
steps:
Expand All @@ -168,13 +168,12 @@ jobs:
-DCMAKE_VERBOSE_MAKEFILE=ON \
-DAMReX_BUILD_TUTORIALS=ON \
-DAMReX_PARTICLES=ON \
-DAMReX_FORTRAN=OFF \
-DCMAKE_CXX_STANDARD=11
-DAMReX_FORTRAN=OFF
make -j 2
# Build libamrex and all tutorials with CUDA 9.1 (oldest supported)
# Build libamrex and all tutorials with CUDA 9.2
tutorials-cuda9:
name: CUDA@9.1.85 GNU@4.8.5 C++11 Release [tutorials]
name: CUDA@9.2 GNU@6.5.0 C++14 Release [tutorials]
runs-on: ubuntu-18.04
env: {CXXFLAGS: "-fno-operator-names"}
steps:
Expand All @@ -183,17 +182,20 @@ jobs:
run: .github/workflows/dependencies/dependencies_nvcc9.sh
- name: Build & Install
run: |
export PATH=/usr/local/nvidia/bin:/usr/local/cuda/bin:${PATH}
export LD_LIBRARY_PATH=/usr/local/nvidia/lib:/usr/local/nvidia/lib64:/usr/local/cuda/lib64:${LD_LIBRARY_PATH}
which nvcc || echo "nvcc not in PATH!"
mkdir build
cd build
cmake .. \
-DCMAKE_VERBOSE_MAKEFILE=ON \
-DAMReX_BUILD_TUTORIALS=ON \
-DAMReX_PARTICLES=ON \
-DAMReX_GPU_BACKEND=CUDA \
-DCMAKE_C_COMPILER=$(which gcc-4.8) \
-DCMAKE_CXX_COMPILER=$(which g++-4.8) \
-DCMAKE_CUDA_HOST_COMPILER=$(which g++-4.8) \
-DCMAKE_Fortran_COMPILER=$(which gfortran-4.8) \
cmake .. \
-DCMAKE_VERBOSE_MAKEFILE=ON \
-DAMReX_BUILD_TUTORIALS=ON \
-DAMReX_PARTICLES=ON \
-DAMReX_GPU_BACKEND=CUDA \
-DCMAKE_C_COMPILER=$(which gcc-6) \
-DCMAKE_CXX_COMPILER=$(which g++-6) \
-DCMAKE_CUDA_HOST_COMPILER=$(which g++-6) \
-DCMAKE_Fortran_COMPILER=$(which gfortran-6) \
-DAMReX_CUDA_ARCH=6.0 \
-DAMReX_CUDA_ERROR_CROSS_EXECUTION_SPACE_CALL=ON
make -j 2
Expand Down
6 changes: 3 additions & 3 deletions Docs/sphinx_documentation/source/BuildingAMReX.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ list of important variables.
+-----------------+-------------------------------------+--------------------+
| COMP | gnu, cray, ibm, intel, llvm, or pgi | none |
+-----------------+-------------------------------------+--------------------+
| CXXSTD | C++ standard (``c++11``, ``c++14``, | compiler default, |
| | ``c++17``, ``c++20``) | at least ``c++11`` |
| CXXSTD | C++ standard (``c++14``, ``c++17``, | compiler default, |
| | ``c++20``) | at least ``c++14`` |
+-----------------+-------------------------------------+--------------------+
| DEBUG | TRUE or FALSE | FALSE |
+-----------------+-------------------------------------+--------------------+
Expand Down Expand Up @@ -736,7 +736,7 @@ The AMReX team does development on Linux machines, from laptops to supercomputer
We do not officially support AMReX on Windows, and many of us do not have access to any Windows
machines. However, we believe there are no fundamental issues for it to work on Windows.

(1) AMReX mostly uses standard C++11, but for Windows C++17 is required. This is because we use
(1) AMReX mostly uses standard C++14, but for Windows C++17 is required. This is because we use
C++17 to support file system operations when POSIX I/O is not available.

(2) We use POSIX signal handling when floating point exceptions, segmentation faults, etc. happen.
Expand Down
2 changes: 1 addition & 1 deletion Docs/sphinx_documentation/source/BuildingAMReX_Chapter.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ an application code then uses its own build system and links to AMReX as an exte

Finally, AMReX can also be built with CMake, as detailed in the section on :ref:`sec:build:cmake`.

AMReX requires a C++ compiler that supports the C++11 standard, a
AMReX requires a C++ compiler that supports the C++14 standard, a
Fortran compiler that supports the Fortran 2003 standard, and a C
compiler that supports the C99 standard. Prerequisites for building
with GNU Make include Python (>= 2.7, including 3) and standard tools
Expand Down
2 changes: 1 addition & 1 deletion INSTALL
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ There are three ways to use AMReX.
Fortran modules via `./configure` followed by `make` and `make
install`. Type `./configure -h` to show help message. An
application code uses its build system to compile and link to the
AMReX library. Because AMReX uses C++11 and Fortran, the linker
AMReX library. Because AMReX uses C++14 and Fortran, the linker
needs to link the libraries. See
`Tutorials/Basic/Build_with_libamrex` for an example of this
approach. Note that this approach relies the make system in
Expand Down
8 changes: 4 additions & 4 deletions Tools/CMake/AMReX_Config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,17 @@ function (configure_amrex)
# Moreover, it will also enforce such standard on all the consuming targets
#
set_target_properties(amrex PROPERTIES CXX_EXTENSIONS OFF)
# minimum: C++11 on Linux, C++17 on Windows, C++17 for dpc++
# minimum: C++14 on Linux, C++17 on Windows, C++17 for dpc++
if (AMReX_DPCPP)
target_compile_features(amrex PUBLIC cxx_std_17)
else ()
target_compile_features(amrex PUBLIC $<IF:$<STREQUAL:$<PLATFORM_ID>,Windows>,cxx_std_17,cxx_std_11>)
target_compile_features(amrex PUBLIC $<IF:$<STREQUAL:$<PLATFORM_ID>,Windows>,cxx_std_17,cxx_std_14>)
endif ()

if (AMReX_CUDA AND (CMAKE_VERSION VERSION_GREATER_EQUAL 3.17) )
set_target_properties(amrex PROPERTIES CUDA_EXTENSIONS OFF)
# minimum: C++11 on Linux, C++17 on Windows
target_compile_features(amrex PUBLIC $<IF:$<STREQUAL:$<PLATFORM_ID>,Windows>,cuda_std_17,cuda_std_11>)
# minimum: C++14 on Linux, C++17 on Windows
target_compile_features(amrex PUBLIC $<IF:$<STREQUAL:$<PLATFORM_ID>,Windows>,cuda_std_17,cuda_std_14>)
endif()

#
Expand Down
2 changes: 1 addition & 1 deletion Tools/GNUMake/comps/cray.mak
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ endif
ifdef CXXSTD
CXXSTD := $(strip $(CXXSTD))
else
CXXSTD := c++11
CXXSTD := c++14
endif

ifeq ($(CCE_GE_V9),TRUE)
Expand Down
4 changes: 1 addition & 3 deletions Tools/GNUMake/comps/gnu.mak
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,7 @@ ifdef CXXSTD
endif
CXXFLAGS += -std=$(CXXSTD)
else
ifeq ($(gcc_major_version),4)
CXXFLAGS += -std=c++11
else ifeq ($(gcc_major_version),5)
ifeq ($(gcc_major_version),5)
CXXFLAGS += -std=c++14
endif
endif
Expand Down
2 changes: 1 addition & 1 deletion Tools/GNUMake/comps/intel.mak
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ else
ifeq ($(firstword $(sort 17.0 $(intel_version))), 17.0)
CXXFLAGS += -std=c++14
else
CXXFLAGS += -std=c++11
$(error Intel icpc 17.0 or newer is required.)
endif
endif

Expand Down
2 changes: 1 addition & 1 deletion Tools/GNUMake/comps/llvm-flang.mak
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ endif
ifdef CXXSTD
CXXSTD := $(strip $(CXXSTD))
else
CXXSTD := c++11
CXXSTD := c++14
endif

CXXFLAGS += -std=$(CXXSTD)
Expand Down
6 changes: 1 addition & 5 deletions Tools/GNUMake/comps/nag.mak
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,7 @@ ifdef CXXSTD
endif
CXXFLAGS += -std=$(CXXSTD)
else
ifeq ($(gcc_major_version),4)
CXXFLAGS += -std=c++11
else ifeq ($(gcc_major_version),5)
CXXFLAGS += -std=c++14
endif
CXXFLAGS += -std=c++14
endif

CFLAGS += -std=gnu99
Expand Down
37 changes: 13 additions & 24 deletions Tools/GNUMake/comps/nvcc.mak
Original file line number Diff line number Diff line change
Expand Up @@ -56,27 +56,22 @@ ifeq ($(lowercase_nvcc_host_comp),$(filter $(lowercase_nvcc_host_comp),gcc gnu g
endif

ifeq ($(lowercase_nvcc_host_comp),gnu)

ifeq ($(shell expr $(gcc_major_version) \< 5),1)
ifneq ($(NO_CONFIG_CHECKING),TRUE)
$(error C++14 support requires GCC 5 or newer.)
endif
endif

ifdef CXXSTD
CXXSTD := $(strip $(CXXSTD))
ifeq ($(shell expr $(gcc_major_version) \< 5),1)
ifneq ($(NO_CONFIG_CHECKING),TRUE)
ifeq ($(CXXSTD),c++14)
$(error C++14 support requires GCC 5 or newer.)
endif
endif
endif
CXXFLAGS += -std=$(CXXSTD)
else
ifeq ($(gcc_major_version),4)
CXXSTD := c++11
else ifeq ($(gcc_major_version),5)
CXXSTD := c++14
else
CXXSTD := c++14
ifeq ($(gcc_major_version),5)
CXXFLAGS += -std=c++14
endif
endif

CXXFLAGS += -std=$(CXXSTD)

NVCC_CCBIN ?= g++

CXXFLAGS_FROM_HOST := -ccbin=$(NVCC_CCBIN) -Xcompiler='$(CXXFLAGS)' --std=$(CXXSTD)
Expand All @@ -93,27 +88,21 @@ else ifeq ($(lowercase_nvcc_host_comp),pgi)
endif
endif
else
ifeq ($(gcc_major_version),4)
CXXSTD := c++11
else ifeq ($(gcc_major_version),5)
CXXSTD := c++14
else
CXXSTD := c++14
endif
CXXSTD := c++14
endif

CXXFLAGS += -std=$(CXXSTD)

NVCC_CCBIN ?= pgc++

# In pgi.make, we use gcc_major_version to handle c++11/c++14 flag.
# In pgi.make, we use gcc_major_version to handle c++14 flag.
CXXFLAGS_FROM_HOST := -ccbin=$(NVCC_CCBIN) -Xcompiler='$(CXXFLAGS)' --std=$(CXXSTD)
CFLAGS_FROM_HOST := $(CXXFLAGS_FROM_HOST)
else
ifdef CXXSTD
CXXSTD := $(strip $(CXXSTD))
else
CXXSTD := c++11
CXXSTD := c++14
endif

NVCC_CCBIN ?= $(CXX)
Expand Down
4 changes: 1 addition & 3 deletions Tools/GNUMake/comps/nvhpc.mak
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,7 @@ ifdef CXXSTD
endif
CXXFLAGS += -std=$(CXXSTD)
else
ifeq ($(gcc_major_version),4)
CXXFLAGS += -std=c++11
else ifeq ($(gcc_major_version),5)
ifeq ($(gcc_major_version),5)
CXXFLAGS += -std=c++14
endif
endif
Expand Down
14 changes: 6 additions & 8 deletions Tools/GNUMake/comps/pgi.mak
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,16 @@ else
endif

# The logic here should be consistent with what's in nvcc.mak

ifeq ($(shell expr $(gcc_major_version) \< 5),1)
$(error C++14 support requires GCC 5 or newer.)
endif

ifdef CXXSTD
CXXSTD := $(strip $(CXXSTD))
ifeq ($(shell expr $(gcc_major_version) \< 5),1)
ifeq ($(CXXSTD),c++14)
$(error C++14 support requires GCC 5 or newer.)
endif
endif
CXXFLAGS += -std=$(CXXSTD)
else
ifeq ($(gcc_major_version),4)
CXXFLAGS += -std=c++11
else ifeq ($(gcc_major_version),5)
ifeq ($(gcc_major_version),5)
CXXFLAGS += -std=c++14
endif
endif
Expand Down
2 changes: 1 addition & 1 deletion Tutorials/Basic/Build_with_libamrex/GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ CXX = mpicxx
FC = gfortran

CPPFLAGS = -I. -I$(AMREX_INSTALL_DIR)/include
CXXFLAGS = -O2 -std=c++11
CXXFLAGS = -O2 -std=c++14
FFLAGS = -O2
LDFLAGS = -L$(AMREX_INSTALL_DIR)/lib

Expand Down

0 comments on commit 4a332b5

Please sign in to comment.