From 93e69a47fb4ffae861533abf956b8264a4d78a8c Mon Sep 17 00:00:00 2001 From: MintoDA1 <51412913+MintoDA1@users.noreply.github.com> Date: Tue, 29 Aug 2023 16:06:06 -0400 Subject: [PATCH] Made a number of changes aimed at getting it to compile using older gfortran versions that don't support quad precision. Also fixed the version statement. --- buildscripts/build_swiftest.sh | 8 ++++++ cmake/Modules/SetFortranFlags.cmake | 31 +++++++++++++---------- src/CMakeLists.txt | 38 +++++++++++++++++++++-------- src/coarray/coarray_clone.f90 | 2 ++ src/coarray/coarray_module.f90 | 2 ++ src/globals/globals_module.f90 | 6 ++++- src/globals/globals_module.f90.in | 6 ++++- src/misc/solver_module.f90 | 6 +++-- src/operator/operator_cross.f90 | 4 +++ src/operator/operator_mag.f90 | 2 ++ src/operator/operator_module.f90 | 14 ++++++++++- src/operator/operator_unit.f90 | 6 +++-- src/swiftest/swiftest_io.f90 | 4 +-- src/swiftest/swiftest_module.f90 | 2 ++ src/swiftest/swiftest_util.f90 | 32 ++++++++++++------------ 15 files changed, 115 insertions(+), 48 deletions(-) diff --git a/buildscripts/build_swiftest.sh b/buildscripts/build_swiftest.sh index d2da64c91..b3e3cdc87 100755 --- a/buildscripts/build_swiftest.sh +++ b/buildscripts/build_swiftest.sh @@ -33,12 +33,19 @@ if [ $OS = "Linux" ]; then else SKBUILD_CONFIGURE_OPTIONS="-DBUILD_SHARED_LIBS=OFF" SKBUILD_CONFIGURE_OPTIONS="${SKBUILD_CONFIGURE_OPTIONS} -DMACHINE_CODE_VALUE=\"generic\"" + OMPROOT=${DEVTOOLDIR}/MacOSX${MACOSX_DEPLOYMENT_TARGET}/${ARCH}/usr/local + CPPFLAGS="${CPPFLAGS} -Xclang -fopenmp" + LIBS="${LIBS} -lomp" + LDFLAGS="-Wl,-rpath,${OMPROOT}/lib" + CPATH="${OMPROOT}/include:${CPATH}" + LD_LIBRARY_PATH="${OMPROOT}/lib:${LD_LIBRARY_PATH}" cd $ROOT_DIR printf "\n" printf "*********************************************************\n" printf "* BUILDING SWIFTEST *\n" printf "*********************************************************\n" + printf "OMPROOT: ${OMPROOT}\n" printf "LIBS: ${LIBS}\n" printf "CFLAGS: ${CFLAGS}\n" printf "FFLAGS: ${FFLAGS}\n" @@ -47,6 +54,7 @@ else printf "CPATH: ${CPATH}\n" printf "LD_LIBRARY_PATH: ${LD_LIBRARY_PATH}\n" printf "LDFLAGS: ${LDFLAGS}\n" + printf "LIBS: ${LIBS}\n" printf "NETCDF_FORTRAN_HOME: ${NETCDF_FORTRAN_HOME}\n" printf "NETCDF_INCLUDE: ${NETCDF_INCLUDE}\n" printf "SKBUILD_CONFIGURE_OPTIONS: ${SKBUILD_CONFIGURE_OPTIONS}\n" diff --git a/cmake/Modules/SetFortranFlags.cmake b/cmake/Modules/SetFortranFlags.cmake index 360edda2b..610a428ec 100644 --- a/cmake/Modules/SetFortranFlags.cmake +++ b/cmake/Modules/SetFortranFlags.cmake @@ -93,6 +93,11 @@ IF (COMPILER_OPTIONS STREQUAL "GNU") SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}" Fortran "-ffree-line-length-512" # GNU (gfortran) ) + + # Sets the dialect standard + SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}" + Fortran "-std=f2018" + ) ELSEIF (COMPILER_OPTIONS STREQUAL "Intel") # Disables right margin wrapping in list-directed output IF (WINOPT) @@ -144,19 +149,19 @@ IF (NOT BUILD_SHARED_LIBS AND NOT WINOPT) ENDIF (USE_OPENMP) ELSEIF (COMPILER_OPTIONS STREQUAL "GNU") - # Set GNU static libraries - SET_COMPILE_FLAG(CMAKE_Fortran_LINK_FLAGS "${CMAKE_Fortran_LINK_FLAGS}" - Fortran "-static-libgfortran" - ) - SET_COMPILE_FLAG(CMAKE_Fortran_LINK_FLAGS "${CMAKE_Fortran_LINK_FLAGS}" - Fortran "-static-libgcc" - ) - SET_COMPILE_FLAG(CMAKE_Fortran_LINK_FLAGS "${CMAKE_Fortran_LINK_FLAGS}" - Fortran "-static-libstdc++" - ) - SET_COMPILE_FLAG(CMAKE_Fortran_LINK_FLAGS "${CMAKE_Fortran_LINK_FLAGS}" - Fortran "-static-libquadmath" - ) + # # Set GNU static libraries + # SET_COMPILE_FLAG(CMAKE_Fortran_LINK_FLAGS "${CMAKE_Fortran_LINK_FLAGS}" + # Fortran "-static-libgfortran" + # ) + # SET_COMPILE_FLAG(CMAKE_Fortran_LINK_FLAGS "${CMAKE_Fortran_LINK_FLAGS}" + # Fortran "-static-libgcc" + # ) + # SET_COMPILE_FLAG(CMAKE_Fortran_LINK_FLAGS "${CMAKE_Fortran_LINK_FLAGS}" + # Fortran "-static-libstdc++" + # ) + # SET_COMPILE_FLAG(CMAKE_Fortran_LINK_FLAGS "${CMAKE_Fortran_LINK_FLAGS}" + # Fortran "-static-libquadmath" + # ) IF (USE_OPENMP) SET_COMPILE_FLAG(CMAKE_Fortran_LINK_FLAGS "${CMAKE_Fortran_LINK_FLAGS}" diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 082d881f4..661c72cb8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -168,10 +168,9 @@ IF(USE_COARRAY) ENDIF(USE_COARRAY) # Check to see if the compiler allows for local-spec in do concurrent statements. Set a preprocessor variable if it does -IF (USE_OPENMP) - SET(TESTFILE "${CMAKE_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}") - SET(TESTFILE "${TESTFILE}/CMakeTmp/testFortranDoConcurrentLoc.f90") - FILE(WRITE "${TESTFILE}" +SET(TESTFILE "${CMAKE_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}") +SET(TESTFILE "${TESTFILE}/CMakeTmp/testFortranDoConcurrentLoc.f90") +FILE(WRITE "${TESTFILE}" " program TestDoConcurrentLoc integer :: i @@ -181,12 +180,31 @@ do concurrent(i = 1:10) shared(a) end do end program TestDoConcurrentLoc ") - TRY_COMPILE(DOCONLOC_WORKS ${CMAKE_BINARY_DIR} ${TESTFILE} - COMPILE_DEFINITIONS "${CMAKE_Fortran_FLAGS}" OUTPUT_VARIABLE OUTPUT) - IF (DOCONLOC_WORKS) - TARGET_COMPILE_DEFINITIONS(${SWIFTEST_DRIVER} PRIVATE -DDOCONLOC) - ENDIF (DOCONLOC_WORKS) -ENDIF (USE_OPENMP) +TRY_COMPILE(DOCONLOC_WORKS ${CMAKE_BINARY_DIR} ${TESTFILE} COMPILE_DEFINITIONS "${CMAKE_Fortran_FLAGS}" OUTPUT_VARIABLE OUTPUT) +IF (DOCONLOC_WORKS) + MESSAGE(STATUS "DO CONCURRENT supports locality-spec") + TARGET_COMPILE_DEFINITIONS(${SWIFTEST_DRIVER} PRIVATE -DDOCONLOC) +ELSE () + MESSAGE(STATUS "DO CONCURRENT does not support locality-spec") +ENDIF (DOCONLOC_WORKS) + +# Check to see if quad precision is supported +SET(TESTFILE "${CMAKE_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}") +SET(TESTFILE "${TESTFILE}/CMakeTmp/testFortranQuadPrecisionReal.f90") +FILE(WRITE "${TESTFILE}" +" +program TestQuadPrecisionReal +integer, parameter :: QP = selected_Real_kind(30) +real(QP) :: x +end program TestQuadPrecisionReal +") +TRY_COMPILE(QUADPREC ${CMAKE_BINARY_DIR} ${TESTFILE} COMPILE_DEFINITIONS "${CMAKE_Fortran_FLAGS}" OUTPUT_VARIABLE OUTPUT) +IF (QUADPREC) + MESSAGE(STATUS "Quad precision real is supported") + TARGET_COMPILE_DEFINITIONS(${SWIFTEST_DRIVER} PRIVATE -DQUADPREC) +ELSE () + MESSAGE(STATUS "Quad precision real is not supported") +ENDIF () ##################################### diff --git a/src/coarray/coarray_clone.f90 b/src/coarray/coarray_clone.f90 index 893cff147..ea33f8544 100644 --- a/src/coarray/coarray_clone.f90 +++ b/src/coarray/coarray_clone.f90 @@ -469,6 +469,7 @@ module subroutine coarray_component_clone_lgt_arr1D(var,src_img) end subroutine coarray_component_clone_lgt_arr1D +#ifdef QUADPREC module subroutine coarray_component_clone_QP(var,src_img) !! author: David A. Minton !! @@ -503,5 +504,6 @@ module subroutine coarray_component_clone_QP(var,src_img) return end subroutine coarray_component_clone_QP +#endif end submodule s_coarray_clone \ No newline at end of file diff --git a/src/coarray/coarray_module.f90 b/src/coarray/coarray_module.f90 index b034f8786..22ce10c55 100644 --- a/src/coarray/coarray_module.f90 +++ b/src/coarray/coarray_module.f90 @@ -71,11 +71,13 @@ module subroutine coarray_component_clone_lgt_arr1D(var,src_img) integer(I4B), intent(in),optional :: src_img end subroutine coarray_component_clone_lgt_arr1D +#ifdef QUADPREC module subroutine coarray_component_clone_QP(var,src_img) implicit none real(QP), intent(inout) :: var integer(I4B), intent(in),optional :: src_img end subroutine coarray_component_clone_QP +#endif end interface diff --git a/src/globals/globals_module.f90 b/src/globals/globals_module.f90 index 183c21b09..ece47b07f 100644 --- a/src/globals/globals_module.f90 +++ b/src/globals/globals_module.f90 @@ -24,7 +24,11 @@ module globals integer, parameter :: SP = real32 !! Symbolic name for kind types of single-precision reals integer, parameter :: DP = real64 !! Symbolic name for kind types of double-precision reals - integer, parameter :: QP = real128 !! Symbolic name for kind types of quad-precision reals +#ifdef QUADPREC + integer, parameter :: QP = selected_Real_kind(30) !! Symbolic name for kind types of quad-precision reals +#else + integer, parameter :: QP = real64 !! Stick to DP +#endif real(DP), parameter :: PIBY2 = 1.570796326794896619231321691639751442099_DP !! Definition of /(\pi / 2\) real(DP), parameter :: PI = 3.141592653589793238462643383279502884197_DP !! Definition of /(\pi\) diff --git a/src/globals/globals_module.f90.in b/src/globals/globals_module.f90.in index 8d107af1e..ef22ab97a 100644 --- a/src/globals/globals_module.f90.in +++ b/src/globals/globals_module.f90.in @@ -24,7 +24,11 @@ module globals integer, parameter :: SP = real32 !! Symbolic name for kind types of single-precision reals integer, parameter :: DP = real64 !! Symbolic name for kind types of double-precision reals - integer, parameter :: QP = real128 !! Symbolic name for kind types of quad-precision reals +#ifdef QUADPREC + integer, parameter :: QP = selected_Real_kind(30) !! Symbolic name for kind types of quad-precision reals +#else + integer, parameter :: QP = real64 !! Stick to DP +#endif real(DP), parameter :: PIBY2 = 1.570796326794896619231321691639751442099_DP !! Definition of /(\pi / 2\) real(DP), parameter :: PI = 3.141592653589793238462643383279502884197_DP !! Definition of /(\pi\) diff --git a/src/misc/solver_module.f90 b/src/misc/solver_module.f90 index 872db6428..81f2cab40 100644 --- a/src/misc/solver_module.f90 +++ b/src/misc/solver_module.f90 @@ -20,7 +20,9 @@ module solver interface solve_linear_system module procedure solve_linear_system_dp +#ifdef QUADPREC module procedure solve_linear_system_qp +#endif end interface interface solve_roots @@ -81,7 +83,7 @@ function solve_linear_system_dp(A,b,n,lerr) result(x) return end function solve_linear_system_dp - +#ifdef QUADPREC function solve_linear_system_qp(A,b,n,lerr) result(x) !! Author: David A. Minton !! @@ -115,7 +117,7 @@ function solve_linear_system_qp(A,b,n,lerr) result(x) return end function solve_linear_system_qp - +#endif function solve_wbs(u) result(x) ! solve with backward substitution !! Based on code available on Rosetta Code: https://rosettacode.org/wiki/Gaussian_elimination#Fortran diff --git a/src/operator/operator_cross.f90 b/src/operator/operator_cross.f90 index 72c24a176..3ca3e28cf 100644 --- a/src/operator/operator_cross.f90 +++ b/src/operator/operator_cross.f90 @@ -42,6 +42,7 @@ pure module function operator_cross_dp(A, B) result(C) return end function operator_cross_dp +#ifdef QUADPREC pure module function operator_cross_qp(A, B) result(C) implicit none real(QP), dimension(:), intent(in) :: A, B @@ -53,6 +54,7 @@ pure module function operator_cross_qp(A, B) result(C) C(3) = A(1) * B(2) - A(2) * B(1) return end function operator_cross_qp +#endif pure module function operator_cross_i1b(A, B) result(C) implicit none @@ -124,6 +126,7 @@ pure module function operator_cross_el_dp(A, B) result(C) return end function operator_cross_el_dp +#ifdef QUADPREC pure module function operator_cross_el_qp(A, B) result(C) implicit none real(QP), dimension(:,:), intent(in) :: A, B @@ -137,6 +140,7 @@ pure module function operator_cross_el_qp(A, B) result(C) end do return end function operator_cross_el_qp +#endif pure module function operator_cross_el_i1b(A, B) result(C) implicit none diff --git a/src/operator/operator_mag.f90 b/src/operator/operator_mag.f90 index 721e4a930..5c3d6538e 100644 --- a/src/operator/operator_mag.f90 +++ b/src/operator/operator_mag.f90 @@ -65,6 +65,7 @@ pure module function operator_mag_el_dp(A) result(B) return end function operator_mag_el_dp +#ifdef QUADPREC pure module function operator_mag_el_qp(A) result(B) implicit none real(QP), dimension(:,:), intent(in) :: A @@ -79,6 +80,7 @@ pure module function operator_mag_el_qp(A) result(B) end do return end function operator_mag_el_qp +#endif end submodule s_operator_mag diff --git a/src/operator/operator_module.f90 b/src/operator/operator_module.f90 index 8c351236b..93879117a 100644 --- a/src/operator/operator_module.f90 +++ b/src/operator/operator_module.f90 @@ -37,12 +37,14 @@ pure module function operator_cross_dp(A, B) result(C) real(DP), dimension(NDIM) :: C end function operator_cross_dp +#ifdef QUADPREC pure module function operator_cross_qp(A, B) result(C) !$omp declare simd(operator_cross_qp) implicit none real(QP), dimension(:), intent(in) :: A, B real(QP), dimension(NDIM) :: C end function operator_cross_qp +#endif pure module function operator_cross_i1b(A, B) result(C) !$omp declare simd(operator_cross_i1b) @@ -84,11 +86,13 @@ pure module function operator_cross_el_dp(A, B) result(C) real(DP), dimension(:,:), allocatable :: C end function operator_cross_el_dp +#ifdef QUADPREC pure module function operator_cross_el_qp(A, B) result(C) implicit none real(QP), dimension(:,:), intent(in) :: A, B real(QP), dimension(:,:), allocatable :: C end function operator_cross_el_qp +#endif pure module function operator_cross_el_i1b(A, B) result(C) implicit none @@ -134,13 +138,14 @@ pure module function operator_mag_dp(A) result(B) real(DP) :: B end function operator_mag_dp +#ifdef QUADPREC pure module function operator_mag_qp(A) result(B) !$omp declare simd(operator_mag_qp) implicit none real(QP), dimension(:), intent(in) :: A real(QP) :: B end function operator_mag_qp - +#endif pure module function operator_mag_el_sp(A) result(B) implicit none real(SP), dimension(:,:), intent(in) :: A @@ -153,11 +158,14 @@ pure module function operator_mag_el_dp(A) result(B) real(DP), dimension(:), allocatable :: B end function operator_mag_el_dp +#ifdef QUADPREC pure module function operator_mag_el_qp(A) result(B) implicit none real(QP), dimension(:,:), intent(in) :: A real(QP), dimension(:), allocatable :: B end function operator_mag_el_qp +#endif + end interface @@ -180,12 +188,14 @@ pure module function operator_unit_dp(A) result(B) real(DP), dimension(NDIM) :: B end function operator_unit_dp +#ifdef QUADPREC pure module function operator_unit_qp(A) result(B) !$omp declare simd(operator_unit_qp) implicit none real(QP), dimension(:), intent(in) :: A real(QP), dimension(NDIM) :: B end function operator_unit_qp +#endif pure module function operator_unit_el_sp(A) result(B) implicit none @@ -199,11 +209,13 @@ pure module function operator_unit_el_dp(A) result(B) real(DP), dimension(:,:), allocatable :: B end function operator_unit_el_dp +#ifdef QUADPREC pure module function operator_unit_el_qp(A) result(B) implicit none real(QP), dimension(:,:), intent(in) :: A real(QP), dimension(:,:), allocatable :: B end function operator_unit_el_qp +#endif end interface diff --git a/src/operator/operator_unit.f90 b/src/operator/operator_unit.f90 index 2a14f6645..067df74eb 100644 --- a/src/operator/operator_unit.f90 +++ b/src/operator/operator_unit.f90 @@ -56,7 +56,7 @@ pure module function operator_unit_dp(A) result(B) return end function operator_unit_dp - +#ifdef QUADPREC pure module function operator_unit_qp(A) result(B) implicit none ! Arguments @@ -75,7 +75,7 @@ pure module function operator_unit_qp(A) result(B) return end function operator_unit_qp - +#endif pure module function operator_unit_el_sp(A) result(B) implicit none @@ -116,6 +116,7 @@ pure module function operator_unit_el_dp(A) result(B) return end function operator_unit_el_dp +#ifdef QUADPREC pure module function operator_unit_el_qp(A) result(B) implicit none ! Arguments @@ -134,6 +135,7 @@ pure module function operator_unit_el_qp(A) result(B) return end function operator_unit_el_qp +#endif end submodule s_operator_unit diff --git a/src/swiftest/swiftest_io.f90 b/src/swiftest/swiftest_io.f90 index 9eb3bed2c..9a8095116 100644 --- a/src/swiftest/swiftest_io.f90 +++ b/src/swiftest/swiftest_io.f90 @@ -2774,7 +2774,7 @@ module subroutine swiftest_io_param_writer_one_logical(param_name, param_value, return end subroutine swiftest_io_param_writer_one_logical - +#ifdef QUADPREC module subroutine swiftest_io_param_writer_one_QP(param_name, param_value, unit) !! author: David A. Minton !! @@ -2794,7 +2794,7 @@ module subroutine swiftest_io_param_writer_one_QP(param_name, param_value, unit) return end subroutine swiftest_io_param_writer_one_QP - +#endif module subroutine swiftest_io_read_in_body(self, param) !! author: The Purdue Swiftest Team - David A. Minton, Carlisle A. Wishard, Jennifer L.L. Pouplin, and Jacob R. Elliott diff --git a/src/swiftest/swiftest_module.f90 b/src/swiftest/swiftest_module.f90 index 7437c49bc..acddf4d04 100644 --- a/src/swiftest/swiftest_module.f90 +++ b/src/swiftest/swiftest_module.f90 @@ -850,12 +850,14 @@ module subroutine swiftest_io_param_writer_one_logical(param_name, param_value, integer(I4B), intent(in) :: unit !! Open file unit number to print parameter to end subroutine swiftest_io_param_writer_one_logical +#ifdef QUADPREC module subroutine swiftest_io_param_writer_one_QP(param_name, param_value, unit) implicit none character(len=*), intent(in) :: param_name !! Name of parameter to print real(QP), intent(in) :: param_value !! Value of parameter to print integer(I4B), intent(in) :: unit !! Open file unit number to print parameter to end subroutine swiftest_io_param_writer_one_QP +#endif end interface io_param_writer_one interface diff --git a/src/swiftest/swiftest_util.f90 b/src/swiftest/swiftest_util.f90 index 6659bf69e..94813be38 100644 --- a/src/swiftest/swiftest_util.f90 +++ b/src/swiftest/swiftest_util.f90 @@ -3331,22 +3331,22 @@ module subroutine swiftest_util_version() !! Adapted from David E. Kaufmann's Swifter routine: util_version.f90 implicit none write(*, 200) VERSION - 200 format(/, "************* Swiftest: Version ", f3.1, " *************", //, & - "Based off of Swifter:", //, & - "Authors:", //, & - " The Purdue University Swiftest Development team ", /, & - " Lead by David A. Minton ", /, & - " Carlisle Wishard, Jennifer Pouplin, Jacob Elliott, Dana Singh." & - "Please address comments and questions to:", //, & - " David A. Minton", /, & - " Department Earth, Atmospheric, & Planetary Sciences ",/, & - " Purdue University", /, & - " 550 Stadium Mall Drive", /, & - " West Lafayette, Indiana 47907", /, & - " 765-250-8034 ", /, & - " daminton@purdue.edu", /, & - "Special thanks to Hal Levison and Martin Duncan for the original",/,& - "SWIFTER and SWIFT codes that made this possible.", //, & + 200 format(/, "************* Swiftest: Version ", f3.1, " *************",/, & + "Based off of Swifter:",/, & + "Authors:",/, & + " The Purdue University Swiftest Development team ",/, & + " Lead by David A. Minton ",/, & + " Carlisle Wishard, Jennifer Pouplin, Jacob Elliott, Dana Singh.",/,& + "Please address comments and questions to:",/, & + " David A. Minton",/, & + " Department Earth, Atmospheric, & Planetary Sciences ",/, & + " Purdue University",/, & + " 550 Stadium Mall Drive",/, & + " West Lafayette, Indiana 47907", /, & + " 765-494-3292 ",/, & + " daminton@purdue.edu",/, & + "Special thanks to Hal Levison, Martin Duncan, and David Kaufmann",/, & + "for the original SWIFTER and SWIFT codes that made this possible.",/, & "************************************************", /)