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

Commit

Permalink
Made a number of changes aimed at getting it to compile using older g…
Browse files Browse the repository at this point in the history
…fortran versions that don't support quad precision. Also fixed the version statement.
  • Loading branch information
MintoDA1 authored and MintoDA1 committed Aug 29, 2023
1 parent 1551c09 commit 93e69a4
Show file tree
Hide file tree
Showing 15 changed files with 115 additions and 48 deletions.
8 changes: 8 additions & 0 deletions buildscripts/build_swiftest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
31 changes: 18 additions & 13 deletions cmake/Modules/SetFortranFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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}"
Expand Down
38 changes: 28 additions & 10 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 ()


#####################################
Expand Down
2 changes: 2 additions & 0 deletions src/coarray/coarray_clone.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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
!!
Expand Down Expand Up @@ -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
2 changes: 2 additions & 0 deletions src/coarray/coarray_module.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
6 changes: 5 additions & 1 deletion src/globals/globals_module.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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\)
Expand Down
6 changes: 5 additions & 1 deletion src/globals/globals_module.f90.in
Original file line number Diff line number Diff line change
Expand Up @@ -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\)
Expand Down
6 changes: 4 additions & 2 deletions src/misc/solver_module.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
!!
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/operator/operator_cross.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/operator/operator_mag.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

14 changes: 13 additions & 1 deletion src/operator/operator_module.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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


Expand All @@ -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
Expand All @@ -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


Expand Down
6 changes: 4 additions & 2 deletions src/operator/operator_unit.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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

4 changes: 2 additions & 2 deletions src/swiftest/swiftest_io.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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
!!
Expand All @@ -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
Expand Down
Loading

0 comments on commit 93e69a4

Please sign in to comment.