diff --git a/.gitignore b/.gitignore index 81a7fb376..e5c25df47 100644 --- a/.gitignore +++ b/.gitignore @@ -31,6 +31,8 @@ dump* !README_figs/* #Docker and Singularity files +!docker/ +!singularity/ !Dockerfile !swiftest.def diff --git a/CMakeLists.txt b/CMakeLists.txt index a047c0163..37cda5709 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,6 +31,7 @@ ENDIF(NOT CMAKE_Fortran_COMPILER_SUPPORTS_F90) OPTION(USE_COARRAY "Use Coarray Fortran for parallelization of test particles" OFF) OPTION(USE_OPENMP "Use OpenMP for parallelization" ON) OPTION(USE_SIMD "Use SIMD vectorization" ON) +OPTION(CONTAINERIZE "Compiling for use in a Docker/Singularity container" OFF) # Locate and set parallelization libraries. There are some CMake peculiarities # taken care of here, such as the fact that the FindOpenMP routine doesn't know diff --git a/cmake/Modules/SetFortranFlags.cmake b/cmake/Modules/SetFortranFlags.cmake index 5f0c94bf5..782fdc808 100644 --- a/cmake/Modules/SetFortranFlags.cmake +++ b/cmake/Modules/SetFortranFlags.cmake @@ -19,38 +19,40 @@ INCLUDE(${CMAKE_MODULE_PATH}/SetCompileFlag.cmake) # Make sure the build type is uppercase STRING(TOUPPER "${CMAKE_BUILD_TYPE}" BT) +SET(BUILD_TYPE_MSG "Choose the type of build, options are DEBUG, RELEASE, PROFILE, or TESTING.") + IF(BT STREQUAL "RELEASE") SET(CMAKE_BUILD_TYPE RELEASE CACHE STRING - "Choose the type of build, options are DEBUG, RELEASE, PROFILE, or TESTING." + ${BUILD_TYPE_MSG} FORCE) ELSEIF(BT STREQUAL "DEBUG") SET (CMAKE_BUILD_TYPE DEBUG CACHE STRING - "Choose the type of build, options are DEBUG, RELEASE, PROFILE, or TESTING." + ${BUILD_TYPE_MSG} FORCE) ELSEIF(BT STREQUAL "TESTING") SET (CMAKE_BUILD_TYPE TESTING CACHE STRING - "Choose the type of build, options are DEBUG, RELEASE, PROFILE, or TESTING." + ${BUILD_TYPE_MSG} FORCE) ELSEIF(BT STREQUAL "PROFILE") SET (CMAKE_BUILD_TYPE PROFILE CACHE STRING - "Choose the type of build, options are DEBUG, RELEASE, PROFILE, or TESTING." - FORCE) + ${BUILD_TYPE_MSG} + FORCE) ELSEIF(NOT BT) SET(CMAKE_BUILD_TYPE RELEASE CACHE STRING - "Choose the type of build, options are DEBUG, RELEASE, PROFILE, or TESTING." + ${BUILD_TYPE_MSG} FORCE) MESSAGE(STATUS "CMAKE_BUILD_TYPE not given, defaulting to RELEASE") ELSE() - MESSAGE(FATAL_ERROR "CMAKE_BUILD_TYPE not valid, choices are DEBUG, RELEASE, PROFILE, or TESTING") + MESSAGE(FATAL_ERROR "CMAKE_BUILD_TYPE not valid! ${BUILD_TYPE_MSG}") ENDIF(BT STREQUAL "RELEASE") ######################################################### # If the compiler flags have already been set, return now ######################################################### -IF(CMAKE_Fortran_FLAGS_RELEASE AND CMAKE_Fortran_FLAGS_TESTING AND CMAKE_Fortran_FLAGS_DEBUG AND CMAKE_Fortran_FLAGS_PROFILE) +IF(CMAKE_Fortran_FLAGS_RELEASE AND CMAKE_Fortran_FLAGS_TESTING AND CMAKE_Fortran_FLAGS_DEBUG AND CMAKE_Fortran_FLAGS_PROFILE AND CMAKE_Fortran_FLAGS_CONTAINER) RETURN () -ENDIF(CMAKE_Fortran_FLAGS_RELEASE AND CMAKE_Fortran_FLAGS_TESTING AND CMAKE_Fortran_FLAGS_DEBUG AND CMAKE_Fortran_FLAGS_PROFILE) +ENDIF(CMAKE_Fortran_FLAGS_RELEASE AND CMAKE_Fortran_FLAGS_TESTING AND CMAKE_Fortran_FLAGS_DEBUG AND CMAKE_Fortran_FLAGS_PROFILE AND CMAKE_Fortran_FLAGS_CONTAINER) ######################################################################## # Determine the appropriate flags for this compiler for each build type. @@ -110,12 +112,57 @@ SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}" "/Qpad" # Intel Windows ) -# There is some bug where -march=native doesn't work on Mac -IF(APPLE) - SET(GNUNATIVE "-mtune=CORE-AVX2 -xCORE-AVX2") -ELSE() - SET(GNUNATIVE "-march=CORE-AVX2 -axCORE-AVX2") -ENDIF() + + +IF (USE_SIMD) + # Enables OpenMP SIMD compilation when OpenMP parallelization is disabled. + IF (NOT USE_OPENMP) + SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}" + Fortran "-qno-openmp -qopenmp-simd" # Intel + Fortran "/Qopenmp- /Qopenmp-simd" # Intel Windows + ) + ENDIF (NOT USE_OPENMP) + + IF (CONTAINERIZE) + # Optimize for an old enough processor that it should run on most computers + SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}" + Fortran "-xSANDYBRIDGE" # Intel + "/QxSANDYBRIDGE" # Intel Windows + ${GNUNATIVE} # GNU + ) + ELSE + # Optimize for the host's architecture + SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}" + Fortran "-xhost" # Intel + "/QxHost" # Intel Windows + ${GNUNATIVE} # GNU + ) + ENDIF (CONTAINERIZE) + + # Generate an extended set of vector functions + SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}" + Fortran "-vecabi=cmdtarget" # Intel + Fortran "/Qvecabi:cmdtarget" # Intel Windows + ) +ENDIF (USE_SIMD) + +IF (CONTAINERIZE) + # There is some bug where -march=native doesn't work on Mac + IF(APPLE) + SET(GNUNATIVE "-mtune=sandybridge") + ELSE() + SET(GNUNATIVE "-march=sandybridge") + ENDIF() +ELSE () + # There is some bug where -march=native doesn't work on Mac + IF(APPLE) + SET(GNUNATIVE "-mtune=native") + ELSE() + SET(GNUNATIVE "-march=native") + ENDIF() +ENDIF (CONTAINERIZE) + + ################### ### DEBUG FLAGS ### @@ -340,19 +387,3 @@ SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_PROFILE "${CMAKE_Fortran_FLAGS_RELEASE}" "/O2 /Qopt-report:5 /traceback /Z7" # Intel Windows "-O2 -pg -fbacktrace" # GNU ) - -IF (USE_SIMD) - # Enables OpenMP SIMD compilation when OpenMP parallelization is disabled. - IF (NOT USE_OPENMP) - SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}" - Fortran "-qno-openmp -qopenmp-simd" # Intel - Fortran "/Qopenmp- /Qopenmp-simd" # Intel Windows - ) - ENDIF (NOT USE_OPENMP) - - # Generate an extended set of vector functions - SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}" - Fortran "-vecabi=cmdtarget" # Intel - Fortran "/Qvecabi:cmdtarget" # Intel Windows - ) -ENDIF (USE_SIMD) \ No newline at end of file diff --git a/docker/.gitignore b/docker/.gitignore new file mode 100644 index 000000000..a50979646 --- /dev/null +++ b/docker/.gitignore @@ -0,0 +1,2 @@ +!Dockerfile +!bin/ diff --git a/Dockerfile b/docker/Dockerfile similarity index 100% rename from Dockerfile rename to docker/Dockerfile diff --git a/docker/bin/.gitignore b/docker/bin/.gitignore new file mode 100644 index 000000000..c1d7ed39d --- /dev/null +++ b/docker/bin/.gitignore @@ -0,0 +1 @@ +!swiftest_driver diff --git a/docker/bin/swiftest_driver b/docker/bin/swiftest_driver new file mode 100755 index 000000000..0553553a7 --- /dev/null +++ b/docker/bin/swiftest_driver @@ -0,0 +1,2 @@ +#!/bin/sh -- +singularity run --bind $(pwd):$(pwd) --env OMP_NUM_THREADS=${OMP_NUM_THREADS},FOR_COARRAY_NUM_IMAGES=${FOR_COARRAY_NUM_IMAGES} ${SWIFTEST_SIF} diff --git a/singularity/.gitignore b/singularity/.gitignore new file mode 100644 index 000000000..c15d31235 --- /dev/null +++ b/singularity/.gitignore @@ -0,0 +1,2 @@ +!swiftest.def +!bin/ diff --git a/singularity/bin/.gitignore b/singularity/bin/.gitignore new file mode 100644 index 000000000..c1d7ed39d --- /dev/null +++ b/singularity/bin/.gitignore @@ -0,0 +1 @@ +!swiftest_driver diff --git a/singularity/bin/swiftest_driver b/singularity/bin/swiftest_driver new file mode 100755 index 000000000..45765b4a7 --- /dev/null +++ b/singularity/bin/swiftest_driver @@ -0,0 +1,2 @@ +#!/bin/sh -- +docker run -v $(pwd):$(pwd) -w $(pwd) -t -e OMP_NUM_THREADS -e FOR_COARRAY_NUM_IMAGES swiftest:latest \ No newline at end of file diff --git a/swiftest.def b/singularity/swiftest.def similarity index 100% rename from swiftest.def rename to singularity/swiftest.def