Skip to content
This repository was archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
Updated structure of project to better handle containerization, inclu…
Browse files Browse the repository at this point in the history
…ding a new cmake option to build with a lower level of vector support
  • Loading branch information
daminton committed May 23, 2023
1 parent 9ada3e7 commit ffb8f30
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 31 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ dump*
!README_figs/*

#Docker and Singularity files
!docker/
!singularity/
!Dockerfile
!swiftest.def

Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
93 changes: 62 additions & 31 deletions cmake/Modules/SetFortranFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 ###
Expand Down Expand Up @@ -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)
2 changes: 2 additions & 0 deletions docker/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
!Dockerfile
!bin/
File renamed without changes.
1 change: 1 addition & 0 deletions docker/bin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!swiftest_driver
2 changes: 2 additions & 0 deletions docker/bin/swiftest_driver
Original file line number Diff line number Diff line change
@@ -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}
2 changes: 2 additions & 0 deletions singularity/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
!swiftest.def
!bin/
1 change: 1 addition & 0 deletions singularity/bin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!swiftest_driver
2 changes: 2 additions & 0 deletions singularity/bin/swiftest_driver
Original file line number Diff line number Diff line change
@@ -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
File renamed without changes.

0 comments on commit ffb8f30

Please sign in to comment.