diff --git a/CMakeLists.txt b/CMakeLists.txt index 3125fc3e2..96ce5efa9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,7 @@ # You should have received a copy of the GNU General Public License along with Swiftest. # If not, see: https://www.gnu.org/licenses. -# CMake project file for FOO +# CMake project file for SWIFTEST ################################################## # Define the project and the depencies that it has @@ -63,7 +63,7 @@ SET(BIN ${CMAKE_SOURCE_DIR}/bin) # Have the .mod files placed in the lib folder SET(CMAKE_Fortran_MODULE_DIRECTORY ${LIB}) -# The source for the FOO binary and have it placed in the bin folder +# The source for the SWIFTEST binary and have it placed in the bin folder ADD_SUBDIRECTORY(${SRC} ${BIN}) # Add a distclean target to the Makefile diff --git a/README.md b/README.md index 74c1a652c..5e935af08 100644 --- a/README.md +++ b/README.md @@ -88,10 +88,14 @@ To build Swiftest with the release flags (default), type the following: ``` $ cmake .. ``` -To buid with the debug flags, type: +To build with the debug flags, type: ``` $ cmake .. -DCMAKE_BUILD_TYPE=DEBUG ``` +To build with profiling flags, type: +``` +$ cmake .. -DCMAKE_BUILD_TYPE=PROFILE +``` Finally, to build with the testing flags, type: ``` $ cmake .. -DCMAKE_BUILD_TYPE=TESTING diff --git a/cmake/Modules/SetCompileFlag.cmake b/cmake/Modules/SetCompileFlag.cmake index 1d110ae6d..4141c4773 100644 --- a/cmake/Modules/SetCompileFlag.cmake +++ b/cmake/Modules/SetCompileFlag.cmake @@ -23,12 +23,12 @@ # "-Wall" # GNU # "-warn all" # Intel # ) -# The optin "-Wall" will be checked first, and if it works, will be +# The option "-Wall" will be checked first, and if it works, will be # appended to the CMAKE_C_FLAGS variable. If it doesn't work, then # "-warn all" will be tried. If this doesn't work then checking will # terminate because REQUIRED was given. # -# The reasong that the variable must be given twice (first as the name then +# The reasoning that the variable must be given twice (first as the name then # as the value in quotes) is because of the way CMAKE handles the passing # of variables in functions; it is difficult to extract a variable's # contents and assign new values to it from within a function. diff --git a/cmake/Modules/SetFortranFlags.cmake b/cmake/Modules/SetFortranFlags.cmake index e0b21862b..7850fbdb8 100644 --- a/cmake/Modules/SetFortranFlags.cmake +++ b/cmake/Modules/SetFortranFlags.cmake @@ -21,32 +21,36 @@ STRING(TOUPPER "${CMAKE_BUILD_TYPE}" BT) IF(BT STREQUAL "RELEASE") SET(CMAKE_BUILD_TYPE RELEASE CACHE STRING - "Choose the type of build, options are DEBUG, RELEASE, or TESTING." + "Choose the type of build, options are DEBUG, RELEASE, PROFILE, or TESTING." FORCE) ELSEIF(BT STREQUAL "DEBUG") SET (CMAKE_BUILD_TYPE DEBUG CACHE STRING - "Choose the type of build, options are DEBUG, RELEASE, or TESTING." + "Choose the type of build, options are DEBUG, RELEASE, PROFILE, or TESTING." FORCE) ELSEIF(BT STREQUAL "TESTING") SET (CMAKE_BUILD_TYPE TESTING CACHE STRING - "Choose the type of build, options are DEBUG, RELEASE, or TESTING." + "Choose the type of build, options are DEBUG, RELEASE, PROFILE, or TESTING." 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) ELSEIF(NOT BT) SET(CMAKE_BUILD_TYPE RELEASE CACHE STRING - "Choose the type of build, options are DEBUG, RELEASE, or TESTING." + "Choose the type of build, options are DEBUG, RELEASE, PROFILE, or TESTING." FORCE) MESSAGE(STATUS "CMAKE_BUILD_TYPE not given, defaulting to RELEASE") ELSE() - MESSAGE(FATAL_ERROR "CMAKE_BUILD_TYPE not valid, choices are DEBUG, RELEASE, or TESTING") + MESSAGE(FATAL_ERROR "CMAKE_BUILD_TYPE not valid, choices are DEBUG, RELEASE, PROFILE, or TESTING") 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) +IF(CMAKE_Fortran_FLAGS_RELEASE AND CMAKE_Fortran_FLAGS_TESTING AND CMAKE_Fortran_FLAGS_DEBUG AND CMAKE_Fortran_FLAGS_PROFILE) RETURN () -ENDIF(CMAKE_Fortran_FLAGS_RELEASE AND CMAKE_Fortran_FLAGS_TESTING AND CMAKE_Fortran_FLAGS_DEBUG) +ENDIF(CMAKE_Fortran_FLAGS_RELEASE AND CMAKE_Fortran_FLAGS_TESTING AND CMAKE_Fortran_FLAGS_DEBUG AND CMAKE_Fortran_FLAGS_PROFILE) ######################################################################## # Determine the appropriate flags for this compiler for each build type. @@ -81,7 +85,6 @@ SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}" ################### ### DEBUG FLAGS ### ################### - # NOTE: debugging symbols (-g or /debug:full) are already on by default # Disable optimizations @@ -163,7 +166,7 @@ SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" # Aligns a variable to a specified boundary and offset SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" - Fortran "-align all" # Intel + Fortran "-align all -align array64byte" # Intel ) # Enables changing the variable and array memory layout @@ -215,7 +218,6 @@ SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_TESTING "${CMAKE_Fortran_FLAGS_TESTING}" ##################### ### RELEASE FLAGS ### ##################### - # NOTE: agressive optimizations (-O3) are already turned on by default # Unroll loops @@ -234,19 +236,6 @@ SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE}" "-Minline" # Portland Group ) -# Interprocedural (link-time) optimizations -SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE}" - Fortran "-ipo" # Intel - "/Qipo" # Intel Windows - "-flto" # GNU - "-Mipa" # Portland Group - ) - -# Single-file optimizations -SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE}" - Fortran "-ip" # Intel - "/Qip" # Intel Windows - ) # Allows for lines longer than 80 characters without truncation SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE}" @@ -299,7 +288,28 @@ SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE}" Fortran "-fma" # Intel ) -# Enables agressive optimixation on floating-points -SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE}" - Fortran "-fp-model=fast" # Intel + +##################### +### MATH FLAGS ### +##################### +# Some subroutines require more strict floating point operation optimizations for repeatability +SET_COMPILE_FLAG(STRICTMATH_FLAGS "${STRICTMATH_FLAGS}" + Fortran "-fp-model=precise -prec-div -prec-sqrt -assume protect-parens" # Intel + "/fp:precise /Qprec-div /Qprec-sqrt /assume:protect-parens" # Intel Windows + ) + +# Most subroutines can use aggressive optimization of floating point operations without problems. +SET_COMPILE_FLAG(FASTMATH_FLAGS "${FASTMATH_FLAGS}" + Fortran "-fp-model=fast" + "/fp:fast" + ) + +##################### +### PROFILE FLAGS ### +##################### +# Enables the optimization reports to be generated +SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_PROFILE "${CMAKE_Fortran_FLAGS_RELEASE}" + Fortran "-pg -qopt-report=5 -traceback -p -g3" # Intel + "/Qopt-report:5 /traceback -g3" # Windows Intel + "-pg -fbacktrace" ) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b4204732c..d467332f8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -12,7 +12,7 @@ ######################################## # Add the source files -SET(FOO_src +SET(FAST_MATH_FILES ${SRC}/modules/encounter_classes.f90 ${SRC}/modules/fraggle_classes.f90 ${SRC}/modules/helio_classes.f90 @@ -41,12 +41,10 @@ SET(FOO_src ${SRC}/gr/gr.f90 ${SRC}/helio/helio_drift.f90 ${SRC}/helio/helio_gr.f90 - ${SRC}/helio/helio_kick.f90 ${SRC}/helio/helio_setup.f90 ${SRC}/helio/helio_step.f90 ${SRC}/helio/helio_util.f90 ${SRC}/io/io.f90 - ${SRC}/kick/kick.f90 ${SRC}/netcdf/netcdf.f90 ${SRC}/obl/obl.f90 ${SRC}/operators/operator_cross.f90 @@ -55,7 +53,6 @@ SET(FOO_src ${SRC}/rmvs/rmvs_discard.f90 ${SRC}/rmvs/rmvs_encounter_check.f90 ${SRC}/rmvs/rmvs_io.f90 - ${SRC}/rmvs/rmvs_kick.f90 ${SRC}/rmvs/rmvs_setup.f90 ${SRC}/rmvs/rmvs_step.f90 ${SRC}/rmvs/rmvs_util.f90 @@ -66,7 +63,6 @@ SET(FOO_src ${SRC}/symba/symba_encounter_check.f90 ${SRC}/symba/symba_gr.f90 ${SRC}/symba/symba_io.f90 - ${SRC}/symba/symba_kick.f90 ${SRC}/symba/symba_setup.f90 ${SRC}/symba/symba_step.f90 ${SRC}/symba/symba_util.f90 @@ -96,24 +92,31 @@ SET(FOO_src ${SRC}/whm/whm_coord.f90 ${SRC}/whm/whm_drift.f90 ${SRC}/whm/whm_gr.f90 - ${SRC}/whm/whm_kick.f90 ${SRC}/whm/whm_setup.f90 ${SRC}/whm/whm_step.f90 ${SRC}/whm/whm_util.f90 ${SRC}/main/swiftest_driver.f90 ) +SET(STRICT_MATH_FILES + ${SRC}/kick/kick.f90 + ${SRC}/helio/helio_kick.f90 + ${SRC}/rmvs/rmvs_kick.f90 + ${SRC}/symba/symba_kick.f90 + ${SRC}/whm/whm_kick.f90 +) + +set(SWIFTEST_src ${FAST_MATH_FILES} ${STRICT_MATH_FILES}) # Define the executable in terms of the source files -ADD_EXECUTABLE(${SWIFTEST_DRIVER} ${FOO_src}) +ADD_EXECUTABLE(${SWIFTEST_DRIVER} ${SWIFTEST_src}) ##################################################### # Add the needed libraries and special compiler flags ##################################################### -# Uncomment if you need to link to BLAS and LAPACK +# # Uncomment if you need to link to BLAS and LAPACK TARGET_LINK_LIBRARIES(${SWIFTEST_DRIVER} ${NETCDF_LIBRARIES} ${NETCDF_FORTRAN_LIBRARIES}) -# Uncomment if you have parallization IF(USE_OPENMP) SET_TARGET_PROPERTIES(${SWIFTEST_DRIVER} PROPERTIES COMPILE_FLAGS "${OpenMP_Fortran_FLAGS}" @@ -127,7 +130,6 @@ ELSEIF(USE_MPI) ENDIF(USE_OPENMP) - ##################################### # Tell how to install this executable ##################################### @@ -137,4 +139,13 @@ IF(WIN32) ELSE() SET(CMAKE_INSTALL_PREFIX /usr/local) ENDIF(WIN32) -INSTALL(TARGETS ${SWIFTEST_DRIVER} RUNTIME DESTINATION bin) \ No newline at end of file +INSTALL(TARGETS ${SWIFTEST_DRIVER} RUNTIME DESTINATION bin) + + +#Set strict vs fast math flags +STRING(TOUPPER "${CMAKE_BUILD_TYPE}" BT) +IF(BT STREQUAL "RELEASE" OR BT STREQUAL "PROFILE") + SET_PROPERTY(SOURCE ${STRICT_MATH_FILES} APPEND_STRING PROPERTY COMPILE_FLAGS "${STRICTMATH_FLAGS}") + SET_PROPERTY(SOURCE ${FAST_MATH_FILES} APPEND_STRING PROPERTY COMPILE_FLAGS "${FASTMATH_FLAGS}") +ENDIF() +