From cda911fc309516f61ed1878104664c95c1d131e8 Mon Sep 17 00:00:00 2001 From: David Minton Date: Fri, 19 May 2023 15:52:07 -0400 Subject: [PATCH] Added cmake option to test whether do concurrent accepts local-spec. Newer versions of ifort segfault without it. Old ones can't compile with it. --- src/CMakeLists.txt | 23 ++++++++++++++++++++++- src/encounter/encounter_check.f90 | 19 +++++++++---------- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4d731373d..ef23fadc8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -150,4 +150,25 @@ IF(BT STREQUAL "DEBUG") ADD_DEFINITIONS(-DDEBUG) ELSEIF(BT STREQUAL "PROFILE") ADD_DEFINITIONS(-DPROFILE) -ENDIF() \ No newline at end of file +ENDIF() + +# 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}" +" +program TestDoConcurrentLoc +integer :: i +real,dimension(10) :: a +do concurrent(i = 1:10) shared(a) + a(i) = i +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) diff --git a/src/encounter/encounter_check.f90 b/src/encounter/encounter_check.f90 index 06d0a76d4..a539486b5 100644 --- a/src/encounter/encounter_check.f90 +++ b/src/encounter/encounter_check.f90 @@ -61,11 +61,6 @@ module subroutine encounter_check_all_plplm(param, nplm, nplt, rplm, vplm, rplt, integer(I4B), dimension(:), allocatable, intent(out) :: index2 !! List of indices for body 2 in each encounter logical, dimension(:), allocatable, intent(out) :: lvdotr !! Logical flag indicating the sign of v .dot. x ! Internals - ! type(interaction_timer), save :: itimer - logical, save :: lfirst = .true. - logical, save :: skipit = .false. - integer(I8B) :: nplplm = 0_I8B - integer(I4B) :: npl logical, dimension(:), allocatable :: plmplt_lvdotr !! Logical flag indicating the sign of v .dot. x in the plm-plt group integer(I4B), dimension(:), allocatable :: plmplt_index1 !! List of indices for body 1 in each encounter in the plm-plt group integer(I4B), dimension(:), allocatable :: plmplt_index2 !! List of indices for body 2 in each encounter in the plm-lt group @@ -387,7 +382,11 @@ subroutine encounter_check_all_triangular_one(i, n, xi, yi, zi, vxi, vyi, vzi, x real(DP) :: xr, yr, zr, vxr, vyr, vzr, renc12 logical, dimension(n) :: lencounteri, lvdotri +#ifdef DOCONLOC + do concurrent(j = i+1:n) shared(lencounteri, lvdotri) +#else do concurrent(j = i+1:n) +#endif xr = x(j) - xi yr = y(j) - yi zr = z(j) - zi @@ -605,11 +604,11 @@ module subroutine encounter_check_collapse_ragged_list(ragged_list, n1, nenc, in implicit none ! Arguments class(encounter_list), dimension(:), intent(in) :: ragged_list !! The ragged encounter list - integer(I4B), intent(in) :: n1 !! Number of bodies 1 - integer(I8B), intent(out) :: nenc !! Total number of encountersj - integer(I4B), dimension(:), allocatable, intent(out) :: index1 !! Array of indices for body 1 - integer(I4B), dimension(:), allocatable, intent(out) :: index2 !! Array of indices for body 1 - logical, dimension(:), allocatable, intent(out), optional :: lvdotr !! Array indicating which bodies are approaching + integer(I4B), intent(in) :: n1 !! Number of bodies 1 + integer(I8B), intent(out) :: nenc !! Total number of encountersj + integer(I4B), dimension(:), allocatable, intent(out) :: index1 !! Array of indices for body 1 + integer(I4B), dimension(:), allocatable, intent(out) :: index2 !! Array of indices for body 1 + logical, dimension(:), allocatable, intent(out), optional :: lvdotr !! Array indicating which bodies are approaching ! Internals integer(I4B) :: i integer(I8B) :: j1, j0, nenci