From c10d708aa2c4657e6f3e120acf63ab52d850a6b9 Mon Sep 17 00:00:00 2001 From: carlislewishard <70146819+carlislewishard@users.noreply.github.com> Date: Wed, 5 Apr 2023 16:09:41 -0400 Subject: [PATCH 01/95] updated the affiliations of collaborators --- paper/paper.md | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/paper/paper.md b/paper/paper.md index 7dc8b772c..f5c8c6310 100644 --- a/paper/paper.md +++ b/paper/paper.md @@ -17,21 +17,15 @@ authors: equal-contrib: true affiliation: 1 - name: Jennifer Pouplin - affiliation: "1, 2" + affiliation: "1" - name: Jake Elliott - affiliation: "1, 3" + affiliation: "1" - name: Dana Singh - affiliation: "1, 4" + affiliation: "1" affiliations: - name: Department of Earth, Atmospheric, and Planetary Sciences, Purdue University, USA index: 1 - - name: Metrea Orbital Effects, USA - index: 2 - - name: Verisk, USA - index: 3 - - name: SAIC, USA - index: 4 -date: 03 March 2023 +date: 05 April 2023 bibliography: paper.bib --- @@ -59,4 +53,4 @@ Modeling the behavior of thousands of fully interacting bodies over long timesca `Swiftest` was developed at Purdue University and was funded under the NASA Emerging Worlds and Solar System Workings programs. Active development by the Purdue Swiftest Team is ongoing and contributions from the community are highly encouraged. -# References \ No newline at end of file +# References From 91029f8ae54e6a2439b50e99456c56178957f8f0 Mon Sep 17 00:00:00 2001 From: carlislewishard <70146819+carlislewishard@users.noreply.github.com> Date: Fri, 21 Apr 2023 14:15:55 -0400 Subject: [PATCH 02/95] updated description of J2 and J4 input terms --- README_tables/add_body_kwargs.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README_tables/add_body_kwargs.md b/README_tables/add_body_kwargs.md index 778bda864..c01e343c7 100644 --- a/README_tables/add_body_kwargs.md +++ b/README_tables/add_body_kwargs.md @@ -17,5 +17,5 @@ | ```rhill``` | Hill Radius value(s) of bodies. Only for massive bodies. | float or array-like of floats | ```rot``` | Rotation rate vector(s) of bodies in radians/sec. Only for massive bodies. Only used if ```rotation``` is set to ```True```. | (n,3) array-like of floats | ```Ip``` | Principal axes moments of inertia vector(s) of bodies. Only for massive bodies. Only used if ```rotation``` is set to ```True```. | (n,3) array-like of floats -| ```J2``` | The J2 term of the central body. | float or array-like of floats -| ```J4``` | The J4 term of the central body. | float or array-like of floats \ No newline at end of file +| ```J2``` | The unitless value equal to J2*R^2 where R is the radius of the central body. | float or array-like of floats +| ```J4``` | The unitless value equal to J4*R^4 where R is the radius of the central body. | float or array-like of floats From 2d49d8e79e6d01f81f66165cca5e0ea52379a2c9 Mon Sep 17 00:00:00 2001 From: carlislewishard <70146819+carlislewishard@users.noreply.github.com> Date: Fri, 21 Apr 2023 14:21:15 -0400 Subject: [PATCH 03/95] further updated the J2 and J4 descriptions --- README_tables/add_body_kwargs.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README_tables/add_body_kwargs.md b/README_tables/add_body_kwargs.md index c01e343c7..4e341a83d 100644 --- a/README_tables/add_body_kwargs.md +++ b/README_tables/add_body_kwargs.md @@ -17,5 +17,5 @@ | ```rhill``` | Hill Radius value(s) of bodies. Only for massive bodies. | float or array-like of floats | ```rot``` | Rotation rate vector(s) of bodies in radians/sec. Only for massive bodies. Only used if ```rotation``` is set to ```True```. | (n,3) array-like of floats | ```Ip``` | Principal axes moments of inertia vector(s) of bodies. Only for massive bodies. Only used if ```rotation``` is set to ```True```. | (n,3) array-like of floats -| ```J2``` | The unitless value equal to J2*R^2 where R is the radius of the central body. | float or array-like of floats -| ```J4``` | The unitless value equal to J4*R^4 where R is the radius of the central body. | float or array-like of floats +| ```J2``` | The unitless value of the spherical harmonic term equal to J2*R^2 where R is the radius of the central body. | float or array-like of floats +| ```J4``` | The unitless value of the spherical harmonic term equal to J4*R^4 where R is the radius of the central body. | float or array-like of floats From 297dedf577f0a22955f488b8e64a9985cc676352 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Thu, 18 May 2023 09:28:37 -0400 Subject: [PATCH 04/95] Bug fixes uncovered when compiling in gfortran with coarrays turned off --- src/misc/solver_module.f90 | 15 +++++++++------ src/netcdf_io/netcdf_io_implementations.f90 | 4 ++++ src/swiftest/swiftest_driver.f90 | 2 ++ 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/misc/solver_module.f90 b/src/misc/solver_module.f90 index 410116b2a..936914561 100644 --- a/src/misc/solver_module.f90 +++ b/src/misc/solver_module.f90 @@ -424,22 +424,25 @@ end function f ! returns the minimum of two real numbers real(DP) Function Minimum(x1,x2) real(DP) x1,x2,resultat + if (x1 < x2) then - resultat = x1 + resultat = x1 else - resultat = x2 + resultat = x2 endif + Minimum = resultat end function Minimum ! TRUE if x1*x2 negative - integer Function RootBracketed(x1,x2) + logical Function RootBracketed(x1,x2) real(DP) x1,x2 - integer resultat + logical resultat + if ((x1 > 0.and.x2 > 0).or.(x1 < 0.and.x2 < 0)) then - resultat = 0 + resultat = .false. else - resultat = 1 + resultat = .true. endif RootBracketed = resultat end function RootBracketed diff --git a/src/netcdf_io/netcdf_io_implementations.f90 b/src/netcdf_io/netcdf_io_implementations.f90 index 40c561183..831b17902 100644 --- a/src/netcdf_io/netcdf_io_implementations.f90 +++ b/src/netcdf_io/netcdf_io_implementations.f90 @@ -40,8 +40,12 @@ module subroutine netcdf_io_close(self) character(namelen) :: message if (self%lfile_is_open) then +#ifdef COARRAY write(message,*) this_image() message = "netcdf_io_close on image " // trim(adjustl(message)) +#else + message = "netcdf_io_close" +#endif call netcdf_io_check( nf90_close(self%id), message) self%lfile_is_open = .false. end if diff --git a/src/swiftest/swiftest_driver.f90 b/src/swiftest/swiftest_driver.f90 index d8e2ae219..6cec24feb 100644 --- a/src/swiftest/swiftest_driver.f90 +++ b/src/swiftest/swiftest_driver.f90 @@ -33,7 +33,9 @@ program swiftest_driver param%integrator = trim(adjustl(integrator)) param%display_style = trim(adjustl(display_style)) call param%read_in(param_file_name) +#ifdef COARRAY if (.not.param%lcoarray .and. (this_image() /= 1)) stop ! Single image mode +#endif associate(t0 => param%t0, & tstart => param%tstart, & From 29afacf2e187dc1fdd866dfcf683173384d9c43f Mon Sep 17 00:00:00 2001 From: David A Minton Date: Thu, 18 May 2023 10:50:02 -0400 Subject: [PATCH 05/95] Changed how coarray preprocessor variable is defined to use the older CMAKE TARGET_COMPILE_DEFINITIONS instead of the newer ADD_DEFINITIONS --- CMakeLists.txt | 4 ---- src/CMakeLists.txt | 3 +++ 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1a9ed99c0..0aed20380 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,10 +31,6 @@ 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) -IF (USE_COARRAY) - ADD_DEFINITIONS(-DCOARRAY) -ENDIF() - # 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 # about Fortran. diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a0ae5a554..4d731373d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -111,6 +111,8 @@ SET_SOURCE_FILES_PROPERTIES(${SWIFTEST_src} PROPERTIES Fortran_PREPROCESS ON) # # Uncomment if you need to link to BLAS and LAPACK TARGET_LINK_LIBRARIES(${SWIFTEST_DRIVER} ${NETCDF_LIBRARIES} ${NETCDF_FORTRAN_LIBRARIES}) + + IF(USE_OPENMP) SET_TARGET_PROPERTIES(${SWIFTEST_DRIVER} PROPERTIES COMPILE_FLAGS "${OpenMP_Fortran_FLAGS}" @@ -118,6 +120,7 @@ IF(USE_OPENMP) ENDIF(USE_OPENMP) IF(USE_COARRAY) + TARGET_COMPILE_DEFINITIONS(${SWIFTEST_DRIVER} PRIVATE -DCOARRAY) SET_TARGET_PROPERTIES(${SWIFTEST_DRIVER} PROPERTIES COMPILE_FLAGS "${Coarray_Fortran_FLAGS}" LINK_FLAGS "${Coarray_Fortran_FLAGS}") From db6ad98ada6f7ed11ca5a87a6d406b7fef01b58b Mon Sep 17 00:00:00 2001 From: David A Minton Date: Thu, 18 May 2023 10:50:55 -0400 Subject: [PATCH 06/95] Fixed issue where the undefined nplm was being reported in non-SyMBA runs --- src/swiftest/swiftest_io.f90 | 2 +- src/swiftest/swiftest_module.f90 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/swiftest/swiftest_io.f90 b/src/swiftest/swiftest_io.f90 index 96f974362..e5485c24a 100644 --- a/src/swiftest/swiftest_io.f90 +++ b/src/swiftest/swiftest_io.f90 @@ -285,7 +285,7 @@ module subroutine swiftest_io_display_run_information(self, param, integration_t call self%compact_output(param,integration_timer) end if - if (self%pl%nplm > 0) then + if (param%lmtiny_pl) then #ifdef COARRAY if (param%lcoarray) then write(param%display_unit, co_symbastatfmt) this_image(),self%t, tfrac, self%pl%nbody, self%pl%nplm, self%tp%nbody diff --git a/src/swiftest/swiftest_module.f90 b/src/swiftest/swiftest_module.f90 index f7be030d1..e3664a9ed 100644 --- a/src/swiftest/swiftest_module.f90 +++ b/src/swiftest/swiftest_module.f90 @@ -248,7 +248,7 @@ module swiftest integer(I8B) :: nplpl !! Number of body-body comparisons in the flattened upper triangular matrix type(swiftest_kinship), dimension(:), allocatable :: kin !! Array of merger relationship structures that can account for multiple pairwise mergers in a single step logical, dimension(:), allocatable :: lmtiny !! flag indicating whether this body is below the GMTINY cutoff value - integer(I4B) :: nplm !! number of bodies above the GMTINY limit + integer(I4B) :: nplm = 0 !! number of bodies above the GMTINY limit integer(I8B) :: nplplm !! Number of body (all massive)-body (only those above GMTINY) comparisons in the flattened upper triangular matrix integer(I4B), dimension(:), allocatable :: nplenc !! number of encounters with other planets this time step integer(I4B), dimension(:), allocatable :: ntpenc !! number of encounters with test particles this time step From 43ae5edd07e5c3f2ced9ae46b88626d850ab2b58 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Thu, 18 May 2023 15:04:33 -0400 Subject: [PATCH 07/95] Switched variable from associated to integer based on an error that came up when compiling with ifx --- src/collision/collision_util.f90 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/collision/collision_util.f90 b/src/collision/collision_util.f90 index 95152c0aa..74e634931 100644 --- a/src/collision/collision_util.f90 +++ b/src/collision/collision_util.f90 @@ -21,14 +21,15 @@ module subroutine collision_util_add_fragments_to_collider(self, nbody_system, p class(base_nbody_system), intent(inout) :: nbody_system !! Swiftest nbody system object class(base_parameters), intent(in) :: param !! Current Swiftest run configuration parameters ! Internals - integer(I4B) :: i, npl_before, npl_after + integer(I4B) :: i, npl_before, npl_after, nfrag logical, dimension(:), allocatable :: lexclude select type(nbody_system) class is (swiftest_nbody_system) - associate(fragments => self%fragments, impactors => self%impactors, nfrag => self%fragments%nbody, pl => nbody_system%pl, cb => nbody_system%cb) + associate(fragments => self%fragments, impactors => self%impactors, pl => nbody_system%pl, cb => nbody_system%cb) npl_after = pl%nbody npl_before = npl_after - nfrag + nfrag = self%fragments%nbody allocate(lexclude(npl_after)) pl%status(npl_before+1:npl_after) = ACTIVE From 9d78839a97235e4253b97bdb21acd4186a52a41e Mon Sep 17 00:00:00 2001 From: David Minton Date: Thu, 18 May 2023 15:18:05 -0400 Subject: [PATCH 08/95] Added a regex expression to catch compiler options that are not supported by ifx --- cmake/Modules/SetCompileFlag.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/cmake/Modules/SetCompileFlag.cmake b/cmake/Modules/SetCompileFlag.cmake index 4141c4773..d094009ed 100644 --- a/cmake/Modules/SetCompileFlag.cmake +++ b/cmake/Modules/SetCompileFlag.cmake @@ -45,6 +45,7 @@ FUNCTION(SET_COMPILE_FLAG FLAGVAR FLAGVAL LANG) SET(FAIL_REGEX "ignoring unknown option" # Intel "invalid argument" # Intel + "not supported" # Intel ifx "unrecognized .*option" # GNU "[Uu]nknown switch" # Portland Group "ignoring unknown option" # MSVC From 862888f64c490aedfc834712999531913edabccf Mon Sep 17 00:00:00 2001 From: David Minton Date: Thu, 18 May 2023 15:19:21 -0400 Subject: [PATCH 09/95] Another variable that needed to be set to integer due to ifx rules on do concurrent --- src/collision/collision_util.f90 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/collision/collision_util.f90 b/src/collision/collision_util.f90 index 74e634931..f4f8e341b 100644 --- a/src/collision/collision_util.f90 +++ b/src/collision/collision_util.f90 @@ -150,7 +150,7 @@ module subroutine collision_util_get_energy_and_momentum(self, nbody_system, par class(base_parameters), intent(inout) :: param !! Current Swiftest run configuration parameters character(len=*), intent(in) :: phase !! One of "before" or "after", indicating which phase of the calculation this needs to be done ! Internals - integer(I4B) :: i, phase_val + integer(I4B) :: i, phase_val, nfrag select case(phase) case("before") @@ -166,7 +166,8 @@ module subroutine collision_util_get_energy_and_momentum(self, nbody_system, par class is (swiftest_nbody_system) select type(param) class is (swiftest_parameters) - associate(fragments => self%fragments, impactors => self%impactors, nfrag => self%fragments%nbody, pl => nbody_system%pl, cb => nbody_system%cb) + associate(fragments => self%fragments, impactors => self%impactors, pl => nbody_system%pl, cb => nbody_system%cb) + nfrag = self%fragments%nbody if (phase_val == 1) then do concurrent(i = 1:2) impactors%ke_orbit(i) = 0.5_DP * impactors%mass(i) * dot_product(impactors%vc(:,i), impactors%vc(:,i)) From 4d527678850526806261d9a917861cae81b0d102 Mon Sep 17 00:00:00 2001 From: David Minton Date: Thu, 18 May 2023 16:36:30 -0400 Subject: [PATCH 10/95] Fixed do concurrents to remove the associated variables from loop index --- src/collision/collision_resolve.f90 | 2 +- src/collision/collision_util.f90 | 2 +- src/fraggle/fraggle_generate.f90 | 15 ++++---- src/helio/helio_gr.f90 | 10 +++--- src/helio/helio_kick.f90 | 10 +++--- src/rmvs/rmvs_kick.f90 | 6 ++-- src/swiftest/swiftest_obl.f90 | 15 ++++---- src/swiftest/swiftest_util.f90 | 35 ++++++++++-------- src/whm/whm_gr.f90 | 13 ++++--- src/whm/whm_kick.f90 | 56 +++++++++++++++-------------- 10 files changed, 94 insertions(+), 70 deletions(-) diff --git a/src/collision/collision_resolve.f90 b/src/collision/collision_resolve.f90 index dadde1dfd..befc4ba8a 100644 --- a/src/collision/collision_resolve.f90 +++ b/src/collision/collision_resolve.f90 @@ -350,7 +350,7 @@ module subroutine collision_resolve_mergeaddsub(nbody_system, param, t, status) class is (swiftest_nbody_system) select type(param) class is (swiftest_parameters) - associate(pl => nbody_system%pl, pl_discards => nbody_system%pl_discards, info => nbody_system%pl%info, pl_adds => nbody_system%pl_adds, cb => nbody_system%cb, npl => nbody_system%pl%nbody, & + associate(pl => nbody_system%pl, pl_discards => nbody_system%pl_discards, info => nbody_system%pl%info, pl_adds => nbody_system%pl_adds, cb => nbody_system%cb, & collider => nbody_system%collider, impactors => nbody_system%collider%impactors,fragments => nbody_system%collider%fragments) ! Add the impactors%id bodies to the subtraction list diff --git a/src/collision/collision_util.f90 b/src/collision/collision_util.f90 index f4f8e341b..45f4f516d 100644 --- a/src/collision/collision_util.f90 +++ b/src/collision/collision_util.f90 @@ -536,7 +536,7 @@ module subroutine collision_util_set_coordinate_collider(self) ! Arguments class(collision_basic), intent(inout) :: self !! Collisional nbody_system - associate(fragments => self%fragments, impactors => self%impactors, nfrag => self%fragments%nbody) + associate(fragments => self%fragments, impactors => self%impactors) call impactors%set_coordinate_system() if (.not.allocated(self%fragments)) return diff --git a/src/fraggle/fraggle_generate.f90 b/src/fraggle/fraggle_generate.f90 index 93b4c3431..f1ba8d606 100644 --- a/src/fraggle/fraggle_generate.f90 +++ b/src/fraggle/fraggle_generate.f90 @@ -350,7 +350,7 @@ module subroutine fraggle_generate_pos_vec(collider, nbody_system, param, lfailu real(DP), dimension(2) :: fragment_cloud_radius logical, dimension(collider%fragments%nbody) :: loverlap real(DP), dimension(collider%fragments%nbody) :: mass_rscale, phi, theta, u - integer(I4B) :: i, j, loop, istart + integer(I4B) :: i, j, loop, istart, nfrag, npl, ntp logical :: lsupercat, lhitandrun integer(I4B), parameter :: MAXLOOP = 10000 real(DP), parameter :: cloud_size_scale_factor = 3.0_DP ! Scale factor to apply to the size of the cloud relative to the distance from the impact point. @@ -358,8 +358,10 @@ module subroutine fraggle_generate_pos_vec(collider, nbody_system, param, lfailu real(DP), parameter :: rbuffer = 1.01_DP ! Body radii are inflated by this scale factor to prevent secondary collisions real(DP), parameter :: pack_density = 0.5236_DP ! packing density of loose spheres - associate(fragments => collider%fragments, impactors => collider%impactors, nfrag => collider%fragments%nbody, & - pl => nbody_system%pl, tp => nbody_system%tp, npl => nbody_system%pl%nbody, ntp => nbody_system%tp%nbody) + associate(fragments => collider%fragments, impactors => collider%impactors, pl => nbody_system%pl, tp => nbody_system%tp) + nfrag = collider%fragments%nbody + npl = nbody_system%pl%nbody + ntp = nbody_system%tp%nbody lsupercat = (impactors%regime == COLLRESOLVE_REGIME_SUPERCATASTROPHIC) lhitandrun = (impactors%regime == COLLRESOLVE_REGIME_HIT_AND_RUN) @@ -508,7 +510,7 @@ module subroutine fraggle_generate_rot_vec(collider, nbody_system, param) class(swiftest_nbody_system), intent(inout) :: nbody_system !! Swiftest nbody system object class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters ! Internals - integer(I4B) :: i + integer(I4B) :: i, nfrag real(DP), parameter :: frag_rot_fac = 0.1_DP ! Fraction of projectile rotation magnitude to add as random noise to fragment rotation real(DP), parameter :: hitandrun_momentum_transfer = 0.01_DP ! Fraction of projectile momentum transfered to target in a hit and run real(DP) :: mass_fac @@ -516,7 +518,8 @@ module subroutine fraggle_generate_rot_vec(collider, nbody_system, param) integer(I4B), parameter :: MAXLOOP = 10 logical :: lhitandrun - associate(fragments => collider%fragments, impactors => collider%impactors, nfrag => collider%fragments%nbody) + associate(fragments => collider%fragments, impactors => collider%impactors) + nfrag = collider%fragments%nbody lhitandrun = (impactors%regime == COLLRESOLVE_REGIME_HIT_AND_RUN) ! Initialize fragment rotations and velocities to be pre-impact rotation for body 1, and randomized for bodies >1 and scaled to the original rotation. @@ -805,7 +808,7 @@ module subroutine fraggle_generate_vel_vec(collider, nbody_system, param, lfailu L_residual(:) = (collider%L_total(:,2) - collider%L_total(:,1)) call collision_util_velocity_torque(-L_residual(:), collider%fragments%mtot, impactors%rbcom, impactors%vbcom) - do concurrent(i = 1:collider%fragments%nbody) + do concurrent(i = 1:nfrag) collider%fragments%vb(:,i) = collider%fragments%vc(:,i) + impactors%vbcom(:) end do diff --git a/src/helio/helio_gr.f90 b/src/helio/helio_gr.f90 index 2092fca6a..def25224d 100644 --- a/src/helio/helio_gr.f90 +++ b/src/helio/helio_gr.f90 @@ -71,11 +71,12 @@ pure module subroutine helio_gr_p4_pl(self, nbody_system, param, dt) class(swiftest_parameters), intent(in) :: param !! Current run configuration parameters real(DP), intent(in) :: dt !! Step size ! Internals - integer(I4B) :: i + integer(I4B) :: i, npl if (self%nbody == 0) return - associate(pl => self, npl => self%nbody) + associate(pl => self) + npl = self%nbody do concurrent(i = 1:npl, pl%lmask(i)) call swiftest_gr_p4_pos_kick(param, pl%rh(:, i), pl%vb(:, i), dt) end do @@ -99,11 +100,12 @@ pure module subroutine helio_gr_p4_tp(self, nbody_system, param, dt) class(swiftest_parameters), intent(in) :: param !! Current run configuration parameters real(DP), intent(in) :: dt !! Step size ! Internals - integer(I4B) :: i + integer(I4B) :: i, ntp if (self%nbody == 0) return - associate(tp => self, ntp => self%nbody) + associate(tp => self) + ntp = self%nbody do concurrent(i = 1:ntp, tp%lmask(i)) call swiftest_gr_p4_pos_kick(param, tp%rh(:, i), tp%vb(:, i), dt) end do diff --git a/src/helio/helio_kick.f90 b/src/helio/helio_kick.f90 index 6fb4fad43..89c93a7ed 100644 --- a/src/helio/helio_kick.f90 +++ b/src/helio/helio_kick.f90 @@ -104,11 +104,12 @@ module subroutine helio_kick_vb_pl(self, nbody_system, param, t, dt, lbeg) real(DP), intent(in) :: dt !! Stepsize logical, intent(in) :: lbeg !! Logical flag indicating whether this is the beginning of the half step or not. ! Internals - integer(I4B) :: i + integer(I4B) :: i, npl if (self%nbody == 0) return - associate(pl => self, npl => self%nbody) + associate(pl => self) + npl = self%nbody pl%ah(:, 1:npl) = 0.0_DP call pl%accel(nbody_system, param, t, lbeg) if (lbeg) then @@ -143,11 +144,12 @@ module subroutine helio_kick_vb_tp(self, nbody_system, param, t, dt, lbeg) real(DP), intent(in) :: dt !! Stepsize logical, intent(in) :: lbeg !! Logical flag indicating whether this is the beginning of the half step or not. ! Internals - integer(I4B) :: i + integer(I4B) :: i, ntp if (self%nbody == 0) return - associate(tp => self, ntp => self%nbody) + associate(tp => self) + ntp = self%nbody tp%ah(:, 1:ntp) = 0.0_DP call tp%accel(nbody_system, param, t, lbeg) do concurrent(i = 1:ntp, tp%lmask(i)) diff --git a/src/rmvs/rmvs_kick.f90 b/src/rmvs/rmvs_kick.f90 index 7d113f863..8fb6c14ce 100644 --- a/src/rmvs/rmvs_kick.f90 +++ b/src/rmvs/rmvs_kick.f90 @@ -29,11 +29,13 @@ module subroutine rmvs_kick_getacch_tp(self, nbody_system, param, t, lbeg) class(swiftest_parameters), allocatable :: param_planetocen real(DP), dimension(:, :), allocatable :: rh_original real(DP) :: GMcb_original - integer(I4B) :: i + integer(I4B) :: i, ntp, inner_index if (self%nbody == 0) return - associate(tp => self, ntp => self%nbody, ipleP => self%ipleP, inner_index => self%index) + associate(tp => self, ipleP => self%ipleP) + ntp = self%nbody + inner_index = self%index select type(nbody_system) class is (rmvs_nbody_system) if (nbody_system%lplanetocentric) then ! This is a close encounter step, so any accelerations requiring heliocentric position values diff --git a/src/swiftest/swiftest_obl.f90 b/src/swiftest/swiftest_obl.f90 index 6bd7480fb..7a6463677 100644 --- a/src/swiftest/swiftest_obl.f90 +++ b/src/swiftest/swiftest_obl.f90 @@ -73,11 +73,12 @@ module subroutine swiftest_obl_acc_pl(self, nbody_system) class(swiftest_pl), intent(inout) :: self !! Swiftest massive body object class(swiftest_nbody_system), intent(inout) :: nbody_system !! Swiftest nbody system object ! Internals - integer(I4B) :: i + integer(I4B) :: i, npl if (self%nbody == 0) return - associate(pl => self, npl => self%nbody, cb => nbody_system%cb) + associate(pl => self, cb => nbody_system%cb) + npl = self%nbody call swiftest_obl_acc(npl, cb%Gmass, cb%j2rp2, cb%j4rp4, pl%rh, pl%lmask, pl%aobl, pl%Gmass, cb%aobl) do concurrent(i = 1:npl, pl%lmask(i)) @@ -103,11 +104,12 @@ module subroutine swiftest_obl_acc_tp(self, nbody_system) class(swiftest_nbody_system), intent(inout) :: nbody_system !! Swiftest nbody system object ! Internals real(DP), dimension(NDIM) :: aoblcb - integer(I4B) :: i + integer(I4B) :: i, ntp if (self%nbody == 0) return - associate(tp => self, ntp => self%nbody, cb => nbody_system%cb) + associate(tp => self, cb => nbody_system%cb) + ntp = self%nbody call swiftest_obl_acc(ntp, cb%Gmass, cb%j2rp2, cb%j4rp4, tp%rh, tp%lmask, tp%aobl) if (nbody_system%lbeg) then aoblcb = cb%aoblbeg @@ -139,10 +141,11 @@ module subroutine swiftest_obl_pot_system(self) ! Arguments class(swiftest_nbody_system), intent(inout) :: self !! Swiftest nbody system object ! Internals - integer(I4B) :: i + integer(I4B) :: i, npl real(DP), dimension(self%pl%nbody) :: oblpot_arr - associate(nbody_system => self, pl => self%pl, npl => self%pl%nbody, cb => self%cb) + associate(nbody_system => self, pl => self%pl, cb => self%cb) + npl = self%pl%nbody if (.not. any(pl%lmask(1:npl))) return do concurrent (i = 1:npl, pl%lmask(i)) oblpot_arr(i) = swiftest_obl_pot_one(cb%Gmass, pl%Gmass(i), cb%j2rp2, cb%j4rp4, pl%rh(3,i), 1.0_DP / norm2(pl%rh(:,i))) diff --git a/src/swiftest/swiftest_util.f90 b/src/swiftest/swiftest_util.f90 index b620a7f9d..1784a1252 100644 --- a/src/swiftest/swiftest_util.f90 +++ b/src/swiftest/swiftest_util.f90 @@ -277,10 +277,11 @@ module subroutine swiftest_util_coord_h2b_tp(self, cb) class(swiftest_tp), intent(inout) :: self !! Swiftest test particle object class(swiftest_cb), intent(in) :: cb !! Swiftest central body object ! Internals - integer(I4B) :: i + integer(I4B) :: i, ntp if (self%nbody == 0) return - associate(tp => self, ntp => self%nbody) + associate(tp => self) + ntp = self%nbody do concurrent (i = 1:ntp, tp%status(i) /= INACTIVE) tp%rb(:, i) = tp%rh(:, i) + cb%rb(:) tp%vb(:, i) = tp%vh(:, i) + cb%vb(:) @@ -303,11 +304,12 @@ module subroutine swiftest_util_coord_b2h_pl(self, cb) class(swiftest_pl), intent(inout) :: self !! Swiftest massive body object class(swiftest_cb), intent(inout) :: cb !! Swiftest central body object ! Internals - integer(I4B) :: i + integer(I4B) :: i, npl if (self%nbody == 0) return - associate(pl => self, npl => self%nbody) + associate(pl => self) + npl = self%nbody do concurrent (i = 1:npl, pl%status(i) /= INACTIVE) pl%rh(:, i) = pl%rb(:, i) - cb%rb(:) pl%vh(:, i) = pl%vb(:, i) - cb%vb(:) @@ -330,11 +332,12 @@ module subroutine swiftest_util_coord_b2h_tp(self, cb) class(swiftest_tp), intent(inout) :: self !! Swiftest massive body object class(swiftest_cb), intent(in) :: cb !! Swiftest central body object ! Internals - integer(I4B) :: i + integer(I4B) :: i, ntp if (self%nbody == 0) return - associate(tp => self, ntp => self%nbody) + associate(tp => self) + ntp = self%nbody do concurrent(i = 1:ntp, tp%status(i) /= INACTIVE) tp%rh(:, i) = tp%rb(:, i) - cb%rb(:) tp%vh(:, i) = tp%vb(:, i) - cb%vb(:) @@ -357,11 +360,12 @@ module subroutine swiftest_util_coord_vb2vh_pl(self, cb) class(swiftest_pl), intent(inout) :: self !! Swiftest massive body object class(swiftest_cb), intent(inout) :: cb !! Swiftest central body object ! Internals - integer(I4B) :: i + integer(I4B) :: i, npl if (self%nbody == 0) return - associate(pl => self, npl => self%nbody) + associate(pl => self) + npl = self%nbody cb%vb(:) = 0.0_DP do i = npl, 1, -1 if (pl%status(i) /= INACTIVE) cb%vb(:) = cb%vb(:) - pl%Gmass(i) * pl%vb(:, i) / cb%Gmass @@ -413,12 +417,13 @@ module subroutine swiftest_util_coord_vh2vb_pl(self, cb) class(swiftest_pl), intent(inout) :: self !! Swiftest massive body object class(swiftest_cb), intent(inout) :: cb !! Swiftest central body object ! Internals - integer(I4B) :: i + integer(I4B) :: i, npl real(DP) :: Gmtot if (self%nbody == 0) return - associate(pl => self, npl => self%nbody) + associate(pl => self) + npl = self%nbody Gmtot = cb%Gmass + sum(pl%Gmass(1:npl)) cb%vb(:) = 0.0_DP do i = 1, npl @@ -508,10 +513,11 @@ module subroutine swiftest_util_coord_rh2rb_tp(self, cb) class(swiftest_tp), intent(inout) :: self !! Swiftest test particle object class(swiftest_cb), intent(in) :: cb !! Swiftest central body object ! Internals - integer(I4B) :: i + integer(I4B) :: i, ntp if (self%nbody == 0) return - associate(tp => self, ntp => self%nbody) + associate(tp => self) + ntp = self%nbody do concurrent (i = 1:ntp, tp%status(i) /= INACTIVE) tp%rb(:, i) = tp%rh(:, i) + cb%rb(:) end do @@ -1145,7 +1151,7 @@ module subroutine swiftest_util_get_energy_and_momentum_system(self, param) class(swiftest_nbody_system), intent(inout) :: self !! Swiftest nbody system object class(swiftest_parameters), intent(in) :: param !! Current run configuration parameters ! Internals - integer(I4B) :: i,j + integer(I4B) :: i,j, npl real(DP) :: kecb, kespincb real(DP), dimension(self%pl%nbody) :: kepl, kespinpl real(DP), dimension(NDIM,self%pl%nbody) :: Lplorbit @@ -1153,7 +1159,8 @@ module subroutine swiftest_util_get_energy_and_momentum_system(self, param) real(DP), dimension(NDIM) :: Lcborbit, Lcbspin real(DP), dimension(NDIM) :: h - associate(nbody_system => self, pl => self%pl, npl => self%pl%nbody, cb => self%cb) + associate(nbody_system => self, pl => self%pl, cb => self%cb) + npl = self%pl%nbody nbody_system%L_orbit(:) = 0.0_DP nbody_system%L_spin(:) = 0.0_DP nbody_system%L_total(:) = 0.0_DP diff --git a/src/whm/whm_gr.f90 b/src/whm/whm_gr.f90 index b0891f006..8eb69abc6 100644 --- a/src/whm/whm_gr.f90 +++ b/src/whm/whm_gr.f90 @@ -84,10 +84,12 @@ pure module subroutine whm_gr_p4_pl(self, nbody_system, param, dt) class(swiftest_parameters), intent(in) :: param !! Current run configuration parameters real(DP), intent(in) :: dt !! Step size ! Internals - integer(I4B) :: i + integer(I4B) :: i, npl - associate(pl => self, npl => self%nbody) - if (npl == 0) return + if (self%nbody == 0) return + + associate(pl => self) + npl = self%nbody do concurrent(i = 1:npl, pl%lmask(i)) call swiftest_gr_p4_pos_kick(param, pl%xj(:, i), pl%vj(:, i), dt) end do @@ -111,9 +113,10 @@ pure module subroutine whm_gr_p4_tp(self, nbody_system, param, dt) class(swiftest_parameters), intent(in) :: param !! Current run configuration parameters real(DP), intent(in) :: dt !! Step size ! Internals - integer(I4B) :: i + integer(I4B) :: i, ntp - associate(tp => self, ntp => self%nbody) + associate(tp => self) + ntp = self%nbody if (ntp == 0) return do concurrent(i = 1:ntp, tp%lmask(i)) call swiftest_gr_p4_pos_kick(param, tp%rh(:, i), tp%vh(:, i), dt) diff --git a/src/whm/whm_kick.f90 b/src/whm/whm_kick.f90 index 403678ed6..a1d4b0dc6 100644 --- a/src/whm/whm_kick.f90 +++ b/src/whm/whm_kick.f90 @@ -82,10 +82,12 @@ module subroutine whm_kick_getacch_tp(self, nbody_system, param, t, lbeg) real(DP), intent(in) :: t !! Current time logical, intent(in) :: lbeg !! Logical flag that determines whether or not this is the beginning or end of the step ! Internals - integer(I4B) :: i + integer(I4B) :: i, npl, ntp real(DP), dimension(NDIM) :: ah0 - associate(tp => self, ntp => self%nbody, pl => nbody_system%pl, cb => nbody_system%cb, npl => nbody_system%pl%nbody) + associate(tp => self, pl => nbody_system%pl, cb => nbody_system%cb) + npl = nbody_system%pl%nbody + ntp = self%nbody if (ntp == 0 .or. npl == 0) return nbody_system%lbeg = lbeg @@ -151,16 +153,15 @@ pure subroutine whm_kick_getacch_ah1(cb, pl) class(swiftest_cb), intent(in) :: cb !! WHM central body object class(whm_pl), intent(inout) :: pl !! WHM massive body object ! Internals - integer(I4B) :: i + integer(I4B) :: i, npl real(DP), dimension(NDIM) :: ah1h, ah1j - associate(npl => pl%nbody) - do concurrent (i = 2:npl, pl%lmask(i)) - ah1j(:) = pl%xj(:, i) * pl%ir3j(i) - ah1h(:) = pl%rh(:, i) * pl%ir3h(i) - pl%ah(:, i) = pl%ah(:, i) + cb%Gmass * (ah1j(:) - ah1h(:)) - end do - end associate + npl = pl%nbody + do concurrent (i = 2:npl, pl%lmask(i)) + ah1j(:) = pl%xj(:, i) * pl%ir3j(i) + ah1h(:) = pl%rh(:, i) * pl%ir3h(i) + pl%ah(:, i) = pl%ah(:, i) + cb%Gmass * (ah1j(:) - ah1h(:)) + end do return end subroutine whm_kick_getacch_ah1 @@ -178,22 +179,21 @@ pure subroutine whm_kick_getacch_ah2(cb, pl) class(swiftest_cb), intent(in) :: cb !! Swiftest central body object class(whm_pl), intent(inout) :: pl !! WHM massive body object ! Internals - integer(I4B) :: i + integer(I4B) :: i, npl real(DP) :: etaj, fac real(DP), dimension(NDIM) :: ah2, ah2o - associate(npl => pl%nbody) - ah2(:) = 0.0_DP - ah2o(:) = 0.0_DP - etaj = cb%Gmass - do concurrent(i = 2:npl, pl%lmask(i)) - etaj = etaj + pl%Gmass(i - 1) - fac = pl%Gmass(i) * cb%Gmass * pl%ir3j(i) / etaj - ah2(:) = ah2o + fac * pl%xj(:, i) - pl%ah(:,i) = pl%ah(:, i) + ah2(:) - ah2o(:) = ah2(:) - end do - end associate + npl = pl%nbody + ah2(:) = 0.0_DP + ah2o(:) = 0.0_DP + etaj = cb%Gmass + do concurrent(i = 2:npl, pl%lmask(i)) + etaj = etaj + pl%Gmass(i - 1) + fac = pl%Gmass(i) * cb%Gmass * pl%ir3j(i) / etaj + ah2(:) = ah2o + fac * pl%xj(:, i) + pl%ah(:,i) = pl%ah(:, i) + ah2(:) + ah2o(:) = ah2(:) + end do return end subroutine whm_kick_getacch_ah2 @@ -215,9 +215,10 @@ module subroutine whm_kick_vh_pl(self, nbody_system, param, t, dt, lbeg) real(DP), intent(in) :: dt !! Stepsize logical, intent(in) :: lbeg !! Logical flag indicating whether this is the beginning of the half step or not. ! Internals - integer(I4B) :: i + integer(I4B) :: i, npl - associate(pl => self, npl => self%nbody, cb => nbody_system%cb) + associate(pl => self, cb => nbody_system%cb) + npl = self%nbody if (npl == 0) return if (lbeg) then if (pl%lfirst) then @@ -257,11 +258,12 @@ module subroutine whm_kick_vh_tp(self, nbody_system, param, t, dt, lbeg) real(DP), intent(in) :: dt !! Stepsize logical, intent(in) :: lbeg !! Logical flag indicating whether this is the beginning of the half step or not. ! Internals - integer(I4B) :: i + integer(I4B) :: i, ntp if (self%nbody == 0) return - associate(tp => self, ntp => self%nbody) + associate(tp => self) + ntp = self%nbody if (tp%lfirst) then do concurrent(i = 1:ntp, tp%lmask(i)) tp%ah(:, i) = 0.0_DP From 22bad3db298ddb0d34548c252ceb7af50dbb7c0c Mon Sep 17 00:00:00 2001 From: David Minton Date: Fri, 19 May 2023 12:03:18 -0400 Subject: [PATCH 11/95] Cleaned up some unused variables --- src/collision/collision_generate.f90 | 1 - src/misc/solver_module.f90 | 2 +- src/whm/whm_gr.f90 | 4 ---- 3 files changed, 1 insertion(+), 6 deletions(-) diff --git a/src/collision/collision_generate.f90 b/src/collision/collision_generate.f90 index f0fc6d9e7..6162122cf 100644 --- a/src/collision/collision_generate.f90 +++ b/src/collision/collision_generate.f90 @@ -46,7 +46,6 @@ module subroutine collision_generate_bounce(self, nbody_system, param, t) real(DP), intent(in) :: t !! The time of the collision ! Internals integer(I4B) :: i,j,nimp - real(DP), dimension(NDIM) :: rcom, vcom, rnorm logical, dimension(:), allocatable :: lmask select type(nbody_system) diff --git a/src/misc/solver_module.f90 b/src/misc/solver_module.f90 index 936914561..872db6428 100644 --- a/src/misc/solver_module.f90 +++ b/src/misc/solver_module.f90 @@ -16,7 +16,7 @@ module solver use lambda_function use, intrinsic :: ieee_exceptions private - public :: solve_linear_system, solve_rkf45, solve_roots + public :: solve_linear_system, solve_roots !, solve_rkf45 interface solve_linear_system module procedure solve_linear_system_dp diff --git a/src/whm/whm_gr.f90 b/src/whm/whm_gr.f90 index 8eb69abc6..1b1716800 100644 --- a/src/whm/whm_gr.f90 +++ b/src/whm/whm_gr.f90 @@ -25,8 +25,6 @@ pure module subroutine whm_gr_kick_getacch_pl(self, param) ! Internals integer(I4B) :: i real(DP), dimension(NDIM) :: suma - real(DP), dimension(:, :), allocatable :: aj - real(DP) :: beta, rjmag4 if (self%nbody == 0) return @@ -56,8 +54,6 @@ pure module subroutine whm_gr_kick_getacch_tp(self, param) class(whm_tp), intent(inout) :: self !! WHM massive body particle data structure class(swiftest_parameters), intent(in) :: param !! Current run configuration parameters ! Internals - integer(I4B) :: i - real(DP) :: rjmag4, beta if (self%nbody == 0) return From 922c3f00aac8a56d5d97c732f5062bad2d642b52 Mon Sep 17 00:00:00 2001 From: David Minton Date: Fri, 19 May 2023 12:04:53 -0400 Subject: [PATCH 12/95] Reviewed compiler flags and improved the consistency, and added ability to turn off OpenMP SIMD directives when building for CPU-agnostic container --- CMakeLists.txt | 1 + cmake/Modules/FindOpenMP_Fortran.cmake | 31 ++- cmake/Modules/SetFortranFlags.cmake | 272 ++++++++++++++----------- 3 files changed, 167 insertions(+), 137 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0aed20380..a047c0163 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,6 +30,7 @@ ENDIF(NOT CMAKE_Fortran_COMPILER_SUPPORTS_F90) # Set some options the user may choose 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) # 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 diff --git a/cmake/Modules/FindOpenMP_Fortran.cmake b/cmake/Modules/FindOpenMP_Fortran.cmake index 32777569e..06d679e7c 100644 --- a/cmake/Modules/FindOpenMP_Fortran.cmake +++ b/cmake/Modules/FindOpenMP_Fortran.cmake @@ -25,24 +25,19 @@ INCLUDE (${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake) -SET (OpenMP_Fortran_FLAG_CANDIDATES - #Intel - "-qopenmp" - #Intel windows - "/Qopenmp" - #Gnu - "-fopenmp" - #Portland Group - "-mp" - #Empty, if compiler automatically accepts openmp - " " - #Sun - "-xopenmp" - #HP - "+Oopenmp" - #IBM XL C/c++ - "-qsmp" -) +IF (USE_SIMD) + SET (OpenMP_Fortran_FLAG_CANDIDATES + "-qopenmp" # Intel + "/Qopenmp" # Intel Windows + "-fopenmp" # GNU + ) +ELSE () + SET (OpenMP_Fortran_FLAG_CANDIDATES + "-qopenmp -qno-openmp-simd" # Intel + "/Qopenmp-simd-" # Intel Windows + "-fopenmp" # GNU + ) +ENDIF (USE_SIMD) IF (DEFINED OpenMP_Fortran_FLAGS) SET (OpenMP_Fortran_FLAG_CANDIDATES) diff --git a/cmake/Modules/SetFortranFlags.cmake b/cmake/Modules/SetFortranFlags.cmake index 76f23f5cf..ecf9c34e1 100644 --- a/cmake/Modules/SetFortranFlags.cmake +++ b/cmake/Modules/SetFortranFlags.cmake @@ -64,9 +64,51 @@ ENDIF(CMAKE_Fortran_FLAGS_RELEASE AND CMAKE_Fortran_FLAGS_TESTING AND CMAKE_Fort ### GENERAL FLAGS ### ##################### +# Free form +SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}" + Fortran "-ffree-form" # GNU + ) + # Don't add underscores in symbols for C-compatability SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}" - Fortran "-fno-underscoring") + Fortran "-fno-underscoring" # GNU + ) + +# Determines whether the current Fortran Standard behavior of the compiler is fully implemented. +SET_COMPILE_FLAG(CMAKE_Fortran_Flags "${CMAKE_Fortran_FLAGS}" + Fortran "-standard-semantics" # Intel + "/standard-semantics" # Intel Windows + ) + +# Tells the compiler to issue compile-time messages for nonstandard language elements (Fortran 2018). +SET_COMPILE_FLAG(CMAKE_Fortran_Flags "${CMAKE_Fortran_FLAGS}" + Fortran "-stand f18" # Intel + "/stand:f18" # Intel Windows + "-fstd=f2018" # GNU + ) + +# Allows for lines longer than 80 characters without truncation +SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}" + Fortran "-ffree-line-length-none" # GNU (gfortran) + ) + +# Disables right margin wrapping in list-directed output +SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}" + Fortran "-no-wrap-margin" # Intel + "/wrap-margin-" # Intel Windows + ) + +# Aligns a variable to a specified boundary and offset +SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}" + Fortran "-align all -align array64byte" # Intel + "/align:all /align:array64byte" # Intel Windows + ) + +# Enables changing the variable and array memory layout +SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}" + Fortran "-pad" # Intel + "/Qpad" # Intel Windows + ) # There is some bug where -march=native doesn't work on Mac IF(APPLE) @@ -74,18 +116,10 @@ IF(APPLE) ELSE() SET(GNUNATIVE "-march=native") ENDIF() -# Optimize for the host's architecture -SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}" - Fortran "-xhost" # Intel - "/QxHost" # Intel Windows - ${GNUNATIVE} # GNU - ) - ################### ### DEBUG FLAGS ### ################### -# NOTE: debugging symbols (-g or /debug:full) are already on by default # Disable optimizations SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" @@ -106,33 +140,34 @@ SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" Fortran "-traceback" # Intel Group "/traceback" # Intel Windows "-fbacktrace" # GNU (gfortran) - "-ftrace=full" # GNU (g95) ) # Sanitize SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" - Fortran "-fsanitize=address" # Gnu + Fortran "-fsanitize=address, undefined" # Gnu ) # Check everything SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" - Fortran "-check" # Intel - "/check" # Intel Windows + Fortran "-check all" # Intel + "/check:all" # Intel Windows "-fcheck=all" # GNU ) SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" - Fortran "-fstack-check" # GNU + Fortran "-fstack-check" # GNU ) # Initializes matrices/arrays with NaN values SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" - Fortran "-init=snan,arrays" # Intel + Fortran "-init=snan,arrays" # Intel + "/Qinit:snan,arrays" # Intel Windows ) # Does not generate an interface block for each routine in a source file SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" Fortran "-nogen-interfaces" # Intel + "/nogen-interfaces" # Intel Windows ) # Does not generate aposition independent executable @@ -143,74 +178,43 @@ SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" # Does not set denormal results from floating-point calculations to zero SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" Fortran "-no-ftz" # Intel + "/Qftz-" # Intel Windows ) # Enables floating-point invalid, divide-by-zero, and overflow exceptions SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" - Fortran "-fpe-all=0" # Intel + Fortran "-fpe-all=0" # Intel + "/fpe-all:0" # Intel Windows "-ffpe-trap=zero,overflow,underflow" # GNU ) -# Improves floating-point precision and consistency -SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" - Fortran "-mp1" # Intel - ) - -# Strict model for floating-point calculations (precise and except) -SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" - Fortran "-fp-model=strict" # Intel - ) - # Enables floating-point invalid, divide-by-zero, and overflow exceptions SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" - Fortran "-fpe0" # Intel + Fortran "-fpe0" # Intel + "/fpe:0" # Intel Windows ) # Enables debug info SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" Fortran "-debug all" # Intel + "/debug:all" # Intel Windows ) -# Aligns a variable to a specified boundary and offset +# Disables additional interprocedural optimizations for a single file compilation SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" - Fortran "-align all -align array64byte" # Intel + Fortran "-no-ip" # Intel + "/Qip-" # Intel Windows ) -# Enables changing the variable and array memory layout -SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" - Fortran "-pad" # Intel - ) - -# Enables additional interprocedural optimizations for a single file cimpilation -SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" - Fortran "-ip" # Intel - ) - -# Improves precision when dividing floating-points -SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" - Fortran "-prec-div" # Intel - ) - -# Improves precision when taking the square root of floating-points -SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" - Fortran "-prec-sqrt" # Intel - ) - -# Treat parentheses in accordance with the Fortran standard (ifort 10 only) -SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" - Fortran "-assume protect-parens" # Intel - ) - -# Checks the bounds of arrays at run-time +# Disables prefetch insertion optimization SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" - Fortran "-CB" # Intel + Fortran "-qno-opt-prefetch" # Intel + "/Qopt-prefetch-" # Intel Windows ) - -# Allows for lines longer than 80 characters without truncation + SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" - Fortran "-no-wrap-margin" # Intel - "-ffree-line-length-none" # GNU (gfortran) - ) + Fortran "-fstack-check" # GNU + ) ##################### ### TESTING FLAGS ### @@ -218,8 +222,8 @@ SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" # Optimizations SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_TESTING "${CMAKE_Fortran_FLAGS_DEBUG}" - Fortran REQUIRED "-O3" # All compilers not on Windows - "/O3" # Intel Windows + Fortran REQUIRED "-O3" # All compilers not on Windows + "/O3" # Intel Windows ) ##################### @@ -229,9 +233,9 @@ SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_TESTING "${CMAKE_Fortran_FLAGS_DEBUG}" # Unroll loops SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE}" - Fortran "-unroll" # Intel - "/unroll" # Intel Windows - "-funroll-loops" # GNU + Fortran "-unroll" # Intel + "/unroll" # Intel Windows + "-funroll-loops" # GNU ) # Inline functions @@ -241,91 +245,121 @@ SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE}" "-finline-functions" # GNU ) - -# Allows for lines longer than 80 characters without truncation -SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE}" - Fortran "-no-wrap-margin" # Intel - "-ffree-line-length-none" # GNU (gfortran) - ) - -# Disables prefetch insertion optimization -SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE}" - Fortran "-qopt-prefetch=0" # Intel - ) - # Calls the Matrix Multiply library SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE}" - Fortran "-qopt-matmul" # Intel + Fortran "-qopt-matmul" # Intel + "/Qopt-matmul" # Intel Windows ) # Saves the compiler options and version number to the executable SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE}" - Fortran "-sox" # Intel - ) - -# Enforces vectorization of loops -SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE}" - Fortran "-simd" # Intel + Fortran "-sox" # Intel ) # Aligns a variable to a specified boundary and offset SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE}" - Fortran "-align all" # Intel - ) - -# Generate an extended set of vector functions -SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE}" - Fortran "-vecabi=cmdtarget" # Intel + Fortran "-align all" # Intel + "/align:all" # Intel Windows ) # No floating-point exceptions SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE}" - Fortran "-fp-model no-except" # Intel + Fortran "-fp-model no-except" # Intel + "/fp:no-except" # Intel Windows ) # Generate fused multiply-add instructions SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE}" - Fortran "-fma" # Intel - ) + Fortran "-fma" # Intel + "/Qfma" # Intel Windows + ) -# Generate fused multiply-add instructions +# Tells the compiler to link to certain libraries in the Intel oneAPI Math Kernel Library (oneMKL). SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE}" - Fortran "-qmkl=cluster" # Intel - Fortran "-qmkl" # Intel - Fortran "-mkl" # Old Intel - ) + Fortran "-qmkl=cluster" # Intel + "-qmkl" # Intel + "/Qmkl:cluster" # Intel Windows + "/Qmkl" # Intel Windows + ) + +# Enables additional interprocedural optimizations for a single file compilation +SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE}" + Fortran "-ip" # Intel + "/Qip" # Intel Windows + ) + ##################### ### 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 - ) + Fortran "-fp-model=precise" # Intel + "/fp:precise" # Intel Windows + ) + +SET_COMPILE_FLAG(STRICTMATH_FLAGS "${STRICTMATH_FLAGS}" + Fortran "-prec-div" # Intel + "/Qprec-div" # Intel Windows + ) + +SET_COMPILE_FLAG(STRICTMATH_FLAGS "${STRICTMATH_FLAGS}" + Fortran "-prec-sqrt" # Intel + "/Qprec-sqrt" # Intel Windows + ) + +SET_COMPILE_FLAG(STRICTMATH_FLAGS "${STRICTMATH_FLAGS}" + Fortran "-assume protect-parens" # Intel + "/assume:protect-parens" # Intel Windows + ) + +# Improves floating-point precision and consistency +SET_COMPILE_FLAG(STRICTMATH_FLAGS "${STRICTMATH_FLAGS}" + Fortran "-mp1" # Intel + "/Qprec" # 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" - ) + Fortran "-fp-model=fast" # Intel + "/fp:fast" # Intel Windows + "-ffast-math" # GNU + ) + + +SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" + Fortran ${STRICTMATH_FLAGS} + ) ##################### ### PROFILE FLAGS ### ##################### # Enables the optimization reports to be generated SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_PROFILE "${CMAKE_Fortran_FLAGS_RELEASE}" - Fortran "-O2 -pg -qopt-report=5 -traceback -p -g3" # Intel - "/O2 /Qopt-report:5 /traceback -g3" # Windows Intel - "-O2 -pg -fbacktrace" - ) - -# Sanitize -SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" - Fortran "-fsanitize=address,undefined" # Gnu - ) - - -SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" - Fortran "-fstack-check" # GNU - ) + Fortran "-O2 -pg -qopt-report=5 -traceback -p -g3" # Intel + "/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) + + # Optimize for the host's architecture + SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}" + Fortran "-xhost" # Intel + "/QxHost" # Intel Windows + ${GNUNATIVE} # GNU + ) + + # 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) \ No newline at end of file From 8a8e506ab5adc7c66a19232e1f955c755ccf82cc Mon Sep 17 00:00:00 2001 From: David A Minton Date: Fri, 19 May 2023 13:33:08 -0400 Subject: [PATCH 13/95] Simplified initial conditions of basic simulation to run from the Python script --- examples/Basic_Simulation/initial_conditions.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/Basic_Simulation/initial_conditions.py b/examples/Basic_Simulation/initial_conditions.py index 564c2ebee..1e7cd5cd6 100755 --- a/examples/Basic_Simulation/initial_conditions.py +++ b/examples/Basic_Simulation/initial_conditions.py @@ -74,10 +74,10 @@ capm_tp = default_rng().uniform(0.0, 360.0, ntp) sim.add_body(name=name_tp, a=a_tp, e=e_tp, inc=inc_tp, capom=capom_tp, omega=omega_tp, capm=capm_tp) - -# Run the simulation. Arguments may be defined here or thorugh the swiftest.Simulation() method. -#sim.run(tstart=0.0, tstop=1.0e3, dt=0.01, istep_out=100, dump_cadence=10) sim.set_parameter(tstart=0.0, tstop=1.0e3, dt=0.01, istep_out=100, dump_cadence=0) # Display the run configuration parameters. sim.get_parameter() sim.save() + +# Run the simulation. Arguments may be defined here or thorugh the swiftest.Simulation() method. +sim.run() From a85d5adf3d0ae59d3e6a9d2ae2334304fa1b5300 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Fri, 19 May 2023 13:33:24 -0400 Subject: [PATCH 14/95] Fixed bug that prevented progress bar from updating --- src/swiftest/swiftest_io.f90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/swiftest/swiftest_io.f90 b/src/swiftest/swiftest_io.f90 index e5485c24a..692a1a0b1 100644 --- a/src/swiftest/swiftest_io.f90 +++ b/src/swiftest/swiftest_io.f90 @@ -277,7 +277,7 @@ module subroutine swiftest_io_display_run_information(self, param, integration_t if (this_image() == 1) then #endif write(pbarmessage,fmt=pbarfmt) self%t, param%tstop - call pbar%update(1_I8B,message=pbarmessage) + call pbar%update(param%iloop,message=pbarmessage) #ifdef COARRAY end if !(this_image() == 1) #endif From 20c7e4e971893fcee2f34c69517166b75b15c46f Mon Sep 17 00:00:00 2001 From: David A Minton Date: Fri, 19 May 2023 14:09:42 -0400 Subject: [PATCH 15/95] Fixed bug that prevented the tqdm progress bar to start --- src/swiftest/swiftest_io.f90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/swiftest/swiftest_io.f90 b/src/swiftest/swiftest_io.f90 index 692a1a0b1..0f2f6be2b 100644 --- a/src/swiftest/swiftest_io.f90 +++ b/src/swiftest/swiftest_io.f90 @@ -265,7 +265,7 @@ module subroutine swiftest_io_display_run_information(self, param, integration_t if (param%display_style == "PROGRESS") then call pbar%reset(param%nloops) else if (param%display_style == "COMPACT") then - write(param%display_unit,*) "SWIFTEST START " // trim(adjustl(param%integrator)) + write(*,*) "SWIFTEST START " // trim(adjustl(param%integrator)) end if end if #ifdef COARRAY From cda911fc309516f61ed1878104664c95c1d131e8 Mon Sep 17 00:00:00 2001 From: David Minton Date: Fri, 19 May 2023 15:52:07 -0400 Subject: [PATCH 16/95] 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 From 9bd9aca223399882f347ab4a858667d37ff8e1c6 Mon Sep 17 00:00:00 2001 From: David Minton Date: Fri, 19 May 2023 17:51:12 -0400 Subject: [PATCH 17/95] Set locality-spec for a bunch of do concurrents --- src/fraggle/fraggle_generate.f90 | 10 +++++++++- src/swiftest/swiftest_obl.f90 | 4 ++++ src/swiftest/swiftest_util.f90 | 23 +++++++++++++++++++++-- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/fraggle/fraggle_generate.f90 b/src/fraggle/fraggle_generate.f90 index f1ba8d606..ee4466c11 100644 --- a/src/fraggle/fraggle_generate.f90 +++ b/src/fraggle/fraggle_generate.f90 @@ -299,7 +299,7 @@ module subroutine fraggle_generate_merge(self, nbody_system, param, t) real(DP), intent(in) :: t !! The time of the collision ! Internals - integer(I4B) :: i, j + integer(I4B) :: i real(DP), dimension(NDIM) :: L_spin_new, Ip, rot real(DP) :: rotmag, mass, volume, radius @@ -413,7 +413,11 @@ module subroutine fraggle_generate_pos_vec(collider, nbody_system, param, lfailu end do ! Randomly place the n>2 fragments inside their cloud until none are overlapping +#ifdef DOCONLOC + do concurrent(i = istart:nfrag, loverlap(i)) shared(loverlap, mass_rscale, u, phi, theta, lhitandrun) local(j, direction) +#else do concurrent(i = istart:nfrag, loverlap(i)) +#endif j = fragments%origin_body(i) ! Scale the cloud size @@ -452,7 +456,11 @@ module subroutine fraggle_generate_pos_vec(collider, nbody_system, param, lfailu ! Because body 1 and 2 are initialized near the original impactor positions, then if these bodies are still overlapping ! when the rest are not, we will randomly walk their position in space so as not to move them too far from their starting position if (all(.not.loverlap(istart:nfrag)) .and. any(loverlap(1:istart-1))) then +#ifdef DOCONLOC + do concurrent(i = 1:istart-1,loverlap(i)) shared(loverlap, u, theta, i) local(rwalk, dis) +#else do concurrent(i = 1:istart-1,loverlap(i)) +#endif dis = 0.1_DP * fragments%radius(i) * u(i)**(THIRD) rwalk(1) = fragments%rmag(i) * sin(theta(i)) * cos(phi(i)) rwalk(2) = fragments%rmag(i) * sin(theta(i)) * sin(phi(i)) diff --git a/src/swiftest/swiftest_obl.f90 b/src/swiftest/swiftest_obl.f90 index 7a6463677..85f88bc7d 100644 --- a/src/swiftest/swiftest_obl.f90 +++ b/src/swiftest/swiftest_obl.f90 @@ -147,7 +147,11 @@ module subroutine swiftest_obl_pot_system(self) associate(nbody_system => self, pl => self%pl, cb => self%cb) npl = self%pl%nbody if (.not. any(pl%lmask(1:npl))) return +#ifdef DOCONLOC + do concurrent (i = 1:npl, pl%lmask(i)) shared(oblpot_arr) +#else do concurrent (i = 1:npl, pl%lmask(i)) +#endif oblpot_arr(i) = swiftest_obl_pot_one(cb%Gmass, pl%Gmass(i), cb%j2rp2, cb%j4rp4, pl%rh(3,i), 1.0_DP / norm2(pl%rh(:,i))) end do nbody_system%oblpot = sum(oblpot_arr, pl%lmask(1:npl)) diff --git a/src/swiftest/swiftest_util.f90 b/src/swiftest/swiftest_util.f90 index 1784a1252..b3e43c7e2 100644 --- a/src/swiftest/swiftest_util.f90 +++ b/src/swiftest/swiftest_util.f90 @@ -1178,7 +1178,11 @@ module subroutine swiftest_util_get_energy_and_momentum_system(self, param) nbody_system%be_cb = -3*cb%Gmass * cb%mass / (5 * cb%radius) Lcborbit(:) = cb%mass * (cb%rb(:) .cross. cb%vb(:)) +#ifdef DOCONLOC + do concurrent (i = 1:npl, pl%lmask(i)) local(h) shared(Lplorbit, kepl) +#else do concurrent (i = 1:npl, pl%lmask(i)) +#endif h(:) = pl%rb(:,i) .cross. pl%vb(:,i) ! Angular momentum from orbit @@ -1194,7 +1198,11 @@ module subroutine swiftest_util_get_energy_and_momentum_system(self, param) ! For simplicity, we always assume that the rotation pole is the 3rd principal axis Lcbspin(:) = cb%Ip(3) * cb%mass * cb%radius**2 * cb%rot(:) +#ifdef DOCONLOC + do concurrent (i = 1:npl, pl%lmask(i)) shared(Lplspin, kespinpl) +#else do concurrent (i = 1:npl, pl%lmask(i)) +#endif ! Currently we assume that the rotation pole is the 3rd principal axis ! Angular momentum from spin Lplspin(:,i) = pl%mass(i) * pl%Ip(3,i) * pl%radius(i)**2 * pl%rot(:,i) @@ -1226,7 +1234,7 @@ module subroutine swiftest_util_get_energy_and_momentum_system(self, param) end if nbody_system%ke_orbit = 0.5_DP * (kecb + sum(kepl(1:npl), pl%lmask(1:npl))) - + do concurrent (j = 1:NDIM) nbody_system%L_orbit(j) = Lcborbit(j) + sum(Lplorbit(j,1:npl), pl%lmask(1:npl)) end do @@ -1271,7 +1279,11 @@ module subroutine swiftest_util_get_potential_energy_flat(npl, nplpl, k_plpl, lm pecb(1:npl) = 0.0_DP end where +#ifdef DOCONLOC + do concurrent(i = 1:npl, lmask(i)) shared(pecb) +#else do concurrent(i = 1:npl, lmask(i)) +#endif pecb(i) = -GMcb * mass(i) / norm2(rb(:,i)) end do @@ -1318,7 +1330,11 @@ module subroutine swiftest_util_get_potential_energy_triangular(npl, lmask, GMcb pecb(1:npl) = 0.0_DP end where +#ifdef DOCONLOC + do concurrent(i = 1:npl, lmask(i)) shared(pecb) +#else do concurrent(i = 1:npl, lmask(i)) +#endif pecb(i) = -GMcb * mass(i) / norm2(rb(:,i)) end do @@ -1329,7 +1345,11 @@ module subroutine swiftest_util_get_potential_energy_triangular(npl, lmask, GMcb !$omp reduction(+:pe) do i = 1, npl if (lmask(i)) then +#ifdef DOCONLOC + do concurrent(j = i+1:npl, lmask(i) .and. lmask(j)) shared(pepl) +#else do concurrent(j = i+1:npl, lmask(i) .and. lmask(j)) +#endif pepl(j) = - (Gmass(i) * mass(j)) / norm2(rb(:, i) - rb(:, j)) end do pe = pe + sum(pepl(i+1:npl), lmask(i+1:npl)) @@ -1523,7 +1543,6 @@ module subroutine swiftest_util_peri(n,m, r, v, atp, q, isperi) integer(I4B) :: i real(DP), dimension(n) :: e !! Temporary, just to make use of the xv2aeq subroutine real(DP) :: vdotr - character(len=NAMELEN) :: message do i = 1,n vdotr = dot_product(r(:,i),v(:,i)) From eff54b56be0f8b3ac8752c8436792518c607dbee Mon Sep 17 00:00:00 2001 From: David Minton Date: Fri, 19 May 2023 21:13:49 -0400 Subject: [PATCH 18/95] Added local-spec to every remaining do concurrent --- src/collision/collision_check.f90 | 9 +++++- src/collision/collision_regime.f90 | 4 +++ src/collision/collision_resolve.f90 | 4 +++ src/collision/collision_util.f90 | 16 ++++++++++ src/encounter/encounter_check.f90 | 40 ++++++++++++++++++++++-- src/fraggle/fraggle_generate.f90 | 38 ++++++++++++++++++++--- src/fraggle/fraggle_util.f90 | 16 ++++++++-- src/helio/helio_gr.f90 | 8 +++++ src/helio/helio_kick.f90 | 8 +++++ src/operator/operator_cross.f90 | 28 +++++++++++++++++ src/operator/operator_mag.f90 | 18 +++++++++-- src/operator/operator_unit.f90 | 12 ++++++++ src/rmvs/rmvs_kick.f90 | 12 ++++++++ src/swiftest/swiftest_drift.f90 | 4 +++ src/swiftest/swiftest_gr.f90 | 4 +++ src/swiftest/swiftest_kick.f90 | 41 +++++++++++++++++++++++-- src/swiftest/swiftest_obl.f90 | 14 ++++++++- src/swiftest/swiftest_orbel.f90 | 10 +++++- src/swiftest/swiftest_util.f90 | 47 +++++++++++++++++++++++++---- src/symba/symba_encounter_check.f90 | 9 +++++- src/symba/symba_kick.f90 | 9 +++++- src/whm/whm_gr.f90 | 8 +++++ src/whm/whm_kick.f90 | 34 ++++++++++++++++++++- 23 files changed, 366 insertions(+), 27 deletions(-) diff --git a/src/collision/collision_check.f90 b/src/collision/collision_check.f90 index 936963caa..0e69032bc 100644 --- a/src/collision/collision_check.f90 +++ b/src/collision/collision_check.f90 @@ -101,7 +101,11 @@ module subroutine collision_check_plpl(self, nbody_system, param, t, dt, irec, l lcollision(:) = .false. self%lclosest(:) = .false. +#ifdef DOCONLOC + do concurrent(k = 1:nenc, lmask(k)) shared(self,pl,lmask, dt, lcollision) local(i,j,xr,vr,rlim,Gmtot) +#else do concurrent(k = 1:nenc, lmask(k)) +#endif i = self%index1(k) j = self%index2(k) xr(:) = pl%rh(:, i) - pl%rh(:, j) @@ -204,8 +208,11 @@ module subroutine collision_check_pltp(self, nbody_system, param, t, dt, irec, l lcollision(:) = .false. self%lclosest(:) = .false. - +#ifdef DOCONLOC + do concurrent(k = 1:nenc, lmask(k)) shared(self,pl,tp,lmask, dt, lcollision) local(i,j,xr,vr) +#else do concurrent(k = 1:nenc, lmask(k)) +#endif i = self%index1(k) j = self%index2(k) xr(:) = pl%rh(:, i) - tp%rh(:, j) diff --git a/src/collision/collision_regime.f90 b/src/collision/collision_regime.f90 index a612eb37a..0c81eca14 100644 --- a/src/collision/collision_regime.f90 +++ b/src/collision/collision_regime.f90 @@ -111,7 +111,11 @@ subroutine collision_regime_LS12(collider, nbody_system, param) if (impactors%regime == COLLRESOLVE_REGIME_MERGE) then volume = 4._DP / 3._DP * PI * sum(impactors%radius(:)**3) radius = (3._DP * volume / (4._DP * PI))**(THIRD) +#ifdef DOCONLOC + do concurrent(i = 1:NDIM) shared(impactors,Ip,L_spin) +#else do concurrent(i = 1:NDIM) +#endif Ip(i) = sum(impactors%mass(:) * impactors%Ip(i,:)) L_spin(i) = sum(impactors%L_orbit(i,:) + impactors%L_spin(i,:)) end do diff --git a/src/collision/collision_resolve.f90 b/src/collision/collision_resolve.f90 index befc4ba8a..7aa76166c 100644 --- a/src/collision/collision_resolve.f90 +++ b/src/collision/collision_resolve.f90 @@ -387,7 +387,11 @@ module subroutine collision_resolve_mergeaddsub(nbody_system, param, t, status) ! plnew%tlag = pl%tlag(ibiggest) ! end if +#ifdef DOCONLOC + do concurrent(i = 1:nfrag) shared(plnew,fragments) local(volume) +#else do concurrent(i = 1:nfrag) +#endif volume = 4.0_DP/3.0_DP * PI * plnew%radius(i)**3 plnew%density(i) = fragments%mass(i) / volume end do diff --git a/src/collision/collision_util.f90 b/src/collision/collision_util.f90 index 45f4f516d..179fb289c 100644 --- a/src/collision/collision_util.f90 +++ b/src/collision/collision_util.f90 @@ -36,7 +36,11 @@ module subroutine collision_util_add_fragments_to_collider(self, nbody_system, p pl%mass(npl_before+1:npl_after) = fragments%mass(1:nfrag) pl%Gmass(npl_before+1:npl_after) = fragments%mass(1:nfrag) * param%GU pl%radius(npl_before+1:npl_after) = fragments%radius(1:nfrag) +#ifdef DOCONLOC + do concurrent (i = 1:nfrag) shared(cb,pl,fragments) +#else do concurrent (i = 1:nfrag) +#endif pl%rb(:,npl_before+i) = fragments%rb(:,i) pl%vb(:,npl_before+i) = fragments%vb(:,i) pl%rh(:,npl_before+i) = fragments%rb(:,i) - cb%rb(:) @@ -169,7 +173,11 @@ module subroutine collision_util_get_energy_and_momentum(self, nbody_system, par associate(fragments => self%fragments, impactors => self%impactors, pl => nbody_system%pl, cb => nbody_system%cb) nfrag = self%fragments%nbody if (phase_val == 1) then +#ifdef DOCONLOC + do concurrent(i = 1:2) shared(impactors) +#else do concurrent(i = 1:2) +#endif impactors%ke_orbit(i) = 0.5_DP * impactors%mass(i) * dot_product(impactors%vc(:,i), impactors%vc(:,i)) impactors%ke_spin(i) = 0.5_DP * impactors%mass(i) * impactors%radius(i)**2 * impactors%Ip(3,i) * dot_product(impactors%rot(:,i), impactors%rot(:,i)) impactors%be(i) = -3 * impactors%Gmass(i) * impactors%mass(i) / (5 * impactors%radius(i)) @@ -185,7 +193,11 @@ module subroutine collision_util_get_energy_and_momentum(self, nbody_system, par call swiftest_util_get_potential_energy(2, [(.true., i = 1, 2)], 0.0_DP, impactors%Gmass, impactors%mass, impactors%rb, self%pe(phase_val)) self%te(phase_val) = self%ke_orbit(phase_val) + self%ke_spin(phase_val) + self%be(phase_val) + self%pe(phase_val) else if (phase_val == 2) then +#ifdef DOCONLOC + do concurrent(i = 1:nfrag) shared(fragments) +#else do concurrent(i = 1:nfrag) +#endif fragments%ke_orbit(i) = 0.5_DP * fragments%mass(i) * dot_product(fragments%vc(:,i), fragments%vc(:,i)) fragments%ke_spin(i) = 0.5_DP * fragments%mass(i) * fragments%radius(i)**2 * fragments%Ip(3,i) * dot_product(fragments%rot(:,i), fragments%rot(:,i)) fragments%L_orbit(:,i) = fragments%mass(i) * fragments%rc(:,i) .cross. fragments%vc(:,i) @@ -918,7 +930,11 @@ module subroutine collision_util_set_original_scale_factors(self) impactors%L_orbit = impactors%L_orbit * collider%Lscale impactors%ke_orbit = impactors%ke_orbit * collider%Escale impactors%ke_spin = impactors%ke_spin * collider%Escale +#ifdef DOCONLOC + do concurrent(i = 1:2) shared(impactors) +#else do concurrent(i = 1:2) +#endif impactors%rot(:,i) = impactors%L_spin(:,i) * (impactors%mass(i) * impactors%radius(i)**2 * impactors%Ip(3,i)) end do diff --git a/src/encounter/encounter_check.f90 b/src/encounter/encounter_check.f90 index a539486b5..b987f8799 100644 --- a/src/encounter/encounter_check.f90 +++ b/src/encounter/encounter_check.f90 @@ -174,7 +174,11 @@ subroutine encounter_check_all_sort_and_sweep_plpl(npl, r, v, renc, dt, nenc, in npl_last = npl end if +#ifdef DOCONLOC + do concurrent (i = 1:npl) shared(r,renc,rmin,rmax) local(rmag) +#else do concurrent (i = 1:npl) +#endif rmag = .mag.r(:,i) rmax(i) = rmag + RSWEEP_FACTOR * renc(i) rmin(i) = rmag - RSWEEP_FACTOR * renc(i) @@ -227,12 +231,20 @@ subroutine encounter_check_all_sort_and_sweep_plplm(nplm, nplt, rplm, vplm, rplt ntot_last = ntot end if +#ifdef DOCONLOC + do concurrent (i = 1:nplm) shared(rmin,rmax,rplm,rencm) local(rmag) +#else do concurrent (i = 1:nplm) +#endif rmag = .mag.rplm(:,i) rmax(i) = rmag + RSWEEP_FACTOR * rencm(i) rmin(i) = rmag - RSWEEP_FACTOR * rencm(i) end do +#ifdef DOCONLOC + do concurrent (i = 1:nplt) shared(rmin,rmax,rplt,renct) local(rmag) +#else do concurrent (i = 1:nplt) +#endif rmag = .mag.rplt(:,i) rmax(nplm+i) = rmag + RSWEEP_FACTOR * renct(i) rmin(nplm+i) = rmag - RSWEEP_FACTOR * renct(i) @@ -287,12 +299,20 @@ subroutine encounter_check_all_sort_and_sweep_pltp(npl, ntp, rpl, vpl, rtp, vtp, renctp(:) = 0.0_DP +#ifdef DOCONLOC + do concurrent (i = 1:npl) shared(rmin,rmax,rpl,rencpl) local(rmag) +#else do concurrent (i = 1:npl) +#endif rmag = .mag.rpl(:,i) rmax(i) = rmag + RSWEEP_FACTOR * rencpl(i) rmin(i) = rmag - RSWEEP_FACTOR * rencpl(i) end do - do concurrent (i = 1:ntp) +#ifdef DOCONLOC + do concurrent (i = 1:ntp) shared(rmin,rmax,rtp,renctp) local(rmag) +#else + do concurrent (i = 1:ntp) +#endif rmag = .mag.rtp(:,i) rmax(npl+i) = rmag + RSWEEP_FACTOR * renctp(i) rmin(npl+i) = rmag - RSWEEP_FACTOR * renctp(i) @@ -335,7 +355,11 @@ pure subroutine encounter_check_all_sweep_one(i, n, xi, yi, zi, vxi, vyi, vzi, x logical, dimension(n) :: lencounteri, lvdotri lencounteri(:) = .false. +#ifdef DOCONLOC + do concurrent(j = 1:n, lgood(j)) shared(lgood,lencounteri,lvdotri,x,y,z,vx,vy,vz,renci,renc) local(xr,yr,zr,vxr,vyr,vzr,renc12) +#else do concurrent(j = 1:n, lgood(j)) +#endif xr = x(j) - xi yr = y(j) - yi zr = z(j) - zi @@ -383,7 +407,7 @@ subroutine encounter_check_all_triangular_one(i, n, xi, yi, zi, vxi, vyi, vzi, x logical, dimension(n) :: lencounteri, lvdotri #ifdef DOCONLOC - do concurrent(j = i+1:n) shared(lencounteri, lvdotri) + do concurrent(j = i+1:n) shared(lencounteri, lvdotri, renci, renc) local(xr,yr,zr,vxr,vyr,vzr,renc12) #else do concurrent(j = i+1:n) #endif @@ -700,7 +724,11 @@ subroutine encounter_check_remove_duplicates(n, nenc, index1, index2, lvdotr) ! Sort on the second index and remove duplicates if (allocated(itmp)) deallocate(itmp) allocate(itmp, source=index2) +#ifdef DOCONLOC + do concurrent(i = 1:n, iend(i) - ibeg(i) > 0_I8B) shared(iend,ibeg,index2,lencounter,itmp) local(klo,khi,nenci,j) +#else do concurrent(i = 1:n, iend(i) - ibeg(i) > 0_I8B) +#endif klo = ibeg(i) khi = iend(i) nenci = khi - klo + 1_I8B @@ -747,7 +775,11 @@ pure module subroutine encounter_check_sort_aabb_1D(self, n, extent_arr) call util_sort(extent_arr, self%ind) +#ifdef DOCONLOC + do concurrent(k = 1_I8B:2_I8B * n) shared(self,n) local(i) +#else do concurrent(k = 1_I8B:2_I8B * n) +#endif i = self%ind(k) if (i <= n) then self%ibeg(i) = k @@ -940,7 +972,11 @@ module subroutine encounter_check_sweep_aabb_single_list(self, n, r, v, renc, dt call encounter_check_collapse_ragged_list(lenc, n, nenc, index1, index2, lvdotr) ! By convention, we always assume that index1 < index2, and so we must swap any that are out of order +#ifdef DOCONLOC + do concurrent(k = 1_I8B:nenc, index1(k) > index2(k)) shared(index1,index2) local(itmp) +#else do concurrent(k = 1_I8B:nenc, index1(k) > index2(k)) +#endif itmp = index1(k) index1(k) = index2(k) index2(k) = itmp diff --git a/src/fraggle/fraggle_generate.f90 b/src/fraggle/fraggle_generate.f90 index ee4466c11..0dec13fde 100644 --- a/src/fraggle/fraggle_generate.f90 +++ b/src/fraggle/fraggle_generate.f90 @@ -68,7 +68,11 @@ module subroutine fraggle_generate(self, nbody_system, param, t) ! Get the energy and momentum of the system before and after the collision call self%get_energy_and_momentum(nbody_system, param, phase="before") nfrag = fragments%nbody +#ifdef DOCONLOC + do concurrent(i = 1:2) shared(fragments,impactors) +#else do concurrent(i = 1:2) +#endif fragments%rc(:,i) = fragments%rb(:,i) - impactors%rbcom(:) fragments%vc(:,i) = fragments%vb(:,i) - impactors%vbcom(:) end do @@ -309,7 +313,11 @@ module subroutine fraggle_generate_merge(self, nbody_system, param, t) mass = sum(impactors%mass(:)) volume = 4._DP / 3._DP * PI * sum(impactors%radius(:)**3) radius = (3._DP * volume / (4._DP * PI))**(THIRD) +#ifdef DOCONLOC + do concurrent(i = 1:NDIM) shared(impactors, Ip, L_spin_new) +#else do concurrent(i = 1:NDIM) +#endif Ip(i) = sum(impactors%mass(:) * impactors%Ip(i,:)) L_spin_new(i) = sum(impactors%L_orbit(i,:) + impactors%L_spin(i,:)) end do @@ -414,7 +422,7 @@ module subroutine fraggle_generate_pos_vec(collider, nbody_system, param, lfailu ! Randomly place the n>2 fragments inside their cloud until none are overlapping #ifdef DOCONLOC - do concurrent(i = istart:nfrag, loverlap(i)) shared(loverlap, mass_rscale, u, phi, theta, lhitandrun) local(j, direction) + do concurrent(i = istart:nfrag, loverlap(i)) shared(fragments, impactors, fragment_cloud_radius, fragment_cloud_center, loverlap, mass_rscale, u, phi, theta, lhitandrun) local(j, direction) #else do concurrent(i = istart:nfrag, loverlap(i)) #endif @@ -457,7 +465,7 @@ module subroutine fraggle_generate_pos_vec(collider, nbody_system, param, lfailu ! when the rest are not, we will randomly walk their position in space so as not to move them too far from their starting position if (all(.not.loverlap(istart:nfrag)) .and. any(loverlap(1:istart-1))) then #ifdef DOCONLOC - do concurrent(i = 1:istart-1,loverlap(i)) shared(loverlap, u, theta, i) local(rwalk, dis) + do concurrent(i = 1:istart-1,loverlap(i)) shared(fragments,loverlap, u, theta, i) local(rwalk, dis) #else do concurrent(i = 1:istart-1,loverlap(i)) #endif @@ -519,7 +527,7 @@ module subroutine fraggle_generate_rot_vec(collider, nbody_system, param) class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters ! Internals integer(I4B) :: i, nfrag - real(DP), parameter :: frag_rot_fac = 0.1_DP ! Fraction of projectile rotation magnitude to add as random noise to fragment rotation + real(DP), parameter :: FRAG_ROT_FAC = 0.1_DP ! Fraction of projectile rotation magnitude to add as random noise to fragment rotation real(DP), parameter :: hitandrun_momentum_transfer = 0.01_DP ! Fraction of projectile momentum transfered to target in a hit and run real(DP) :: mass_fac real(DP), dimension(NDIM) :: drot, dL @@ -568,9 +576,13 @@ module subroutine fraggle_generate_rot_vec(collider, nbody_system, param) end if call random_number(fragments%rot(:,2:nfrag)) +#ifdef DOCONLOC + do concurrent (i = 2:nfrag) shared(fragments,impactors) local(mass_fac) +#else do concurrent (i = 2:nfrag) +#endif mass_fac = fragments%mass(i) / impactors%mass(2) - fragments%rot(:,i) = mass_fac**(5.0_DP/3.0_DP) * impactors%rot(:,2) + 2 * (fragments%rot(:,i) - 1.0_DP) * frag_rot_fac * .mag.impactors%rot(:,2) + fragments%rot(:,i) = mass_fac**(5.0_DP/3.0_DP) * impactors%rot(:,2) + 2 * (fragments%rot(:,i) - 1.0_DP) * FRAG_ROT_FAC * .mag.impactors%rot(:,2) end do fragments%rotmag(:) = .mag.fragments%rot(:,:) @@ -662,7 +674,11 @@ module subroutine fraggle_generate_vel_vec(collider, nbody_system, param, lfailu ! Scale the magnitude of the velocity by the distance from the impact point ! This will reduce the chances of fragments colliding with each other immediately, and is more physically correct - do concurrent(i = 1:fragments%nbody) +#ifdef DOCONLOC + do concurrent(i = 1:fragments%nbody) shared(fragments,impactors,vscale) local(rimp) +#else + do concurrent(i = 1:fragments%nbody) +#endif rimp(:) = fragments%rc(:,i) - impactors%rcimp(:) vscale(i) = .mag. rimp(:) / sum(impactors%radius(1:2)) end do @@ -673,7 +689,11 @@ module subroutine fraggle_generate_vel_vec(collider, nbody_system, param, lfailu ! Set the velocities of all fragments using all of the scale factors determined above if (istart > 1) fragments%vc(:,1) = impactors%vc(:,1) * impactors%mass(1) / fragments%mass(1) +#ifdef DOCONLOC + do concurrent(i = istart:fragments%nbody) shared(fragments,impactors,lhitandrun, vscale, vesc, vsign) local(j,vrot,vmag,vdisp,rimp,vimp_unit) +#else do concurrent(i = istart:fragments%nbody) +#endif j = fragments%origin_body(i) vrot(:) = impactors%rot(:,j) .cross. (fragments%rc(:,i) - impactors%rc(:,j)) if (lhitandrun) then @@ -704,7 +724,11 @@ module subroutine fraggle_generate_vel_vec(collider, nbody_system, param, lfailu if (nsteps == 1) L_residual_best(:) = L_residual(:) ! Use equipartition of spin kinetic energy to distribution spin angular momentum +#ifdef DOCONLOC + do concurrent(i = istart:fragments%nbody) shared(DLi_mag, fragments) +#else do concurrent(i = istart:fragments%nbody) +#endif dLi_mag(i) = ((fragments%mass(i) / fragments%mass(istart)) * & (fragments%radius(i) / fragments%radius(istart))**2 * & (fragments%Ip(3,i) / fragments%Ip(3,istart)))**(1.5_DP) @@ -816,7 +840,11 @@ module subroutine fraggle_generate_vel_vec(collider, nbody_system, param, lfailu L_residual(:) = (collider%L_total(:,2) - collider%L_total(:,1)) call collision_util_velocity_torque(-L_residual(:), collider%fragments%mtot, impactors%rbcom, impactors%vbcom) +#ifdef DOCONLOC + do concurrent(i = 1:nfrag) shared(collider, impactors) +#else do concurrent(i = 1:nfrag) +#endif collider%fragments%vb(:,i) = collider%fragments%vc(:,i) + impactors%vbcom(:) end do diff --git a/src/fraggle/fraggle_util.f90 b/src/fraggle/fraggle_util.f90 index 3b0c42d6a..351bd05fa 100644 --- a/src/fraggle/fraggle_util.f90 +++ b/src/fraggle/fraggle_util.f90 @@ -44,7 +44,11 @@ module subroutine fraggle_util_restructure(self, nbody_system, param, lfailure) new_fragments%Gmass(1) =sum(old_fragments%Gmass(1:2)) new_fragments%density(1) = new_fragments%mass(1) / volume new_fragments%radius(1) = (3._DP * volume / (4._DP * PI))**(THIRD) +#ifdef DOCONLOC + do concurrent(i = 1:NDIM) shared(old_fragments, new_fragments) +#else do concurrent(i = 1:NDIM) +#endif new_fragments%Ip(i,1) = sum(old_fragments%mass(1:2) * old_fragments%Ip(i,1:2)) end do new_fragments%Ip(:,1) = new_fragments%Ip(:,1) / new_fragments%mass(1) @@ -55,7 +59,11 @@ module subroutine fraggle_util_restructure(self, nbody_system, param, lfailure) new_fragments%Gmass(2:nnew) = old_fragments%Gmass(3:nold) new_fragments%density(2:nnew) = old_fragments%density(3:nold) new_fragments%radius(2:nnew) = old_fragments%radius(3:nold) +#ifdef DOCONLOC + do concurrent(i = 1:NDIM) shared(old_fragments,new_fragments) +#else do concurrent(i = 1:NDIM) +#endif new_fragments%Ip(i,2:nnew) = old_fragments%Ip(i,3:nold) end do new_fragments%origin_body(2:nnew) = old_fragments%origin_body(3:nold) @@ -87,10 +95,10 @@ module subroutine fraggle_util_set_mass_dist(self, param) class(collision_fraggle), intent(inout) :: self !! Fraggle collision system object class(swiftest_parameters), intent(in) :: param !! Current Swiftest run configuration parameters ! Internals - integer(I4B) :: i, j, k, jproj, jtarg, nfrag, istart, nfragmax, nrem + integer(I4B) :: i, j, jproj, jtarg, nfrag, istart, nfragmax real(DP), dimension(2) :: volume real(DP), dimension(NDIM) :: Ip_avg - real(DP) :: mremaining, mtot, mcumul, G, mass_noise, Mslr, x0, x1, ymid, y0, y1, y, yp, eps, Mrat + real(DP) :: mremaining, mtot, mcumul, G, mass_noise, Mslr, Mrat real(DP), dimension(:), allocatable :: mass real(DP) :: beta integer(I4B), parameter :: MASS_NOISE_FACTOR = 5 !! The number of digits of random noise that get added to the minimum mass value to prevent identical masses from being generated in a single run @@ -207,7 +215,11 @@ module subroutine fraggle_util_set_mass_dist(self, param) fragments%density(istart:nfrag) = fragments%mtot / sum(volume(:)) fragments%radius(istart:nfrag) = (3 * fragments%mass(istart:nfrag) / (4 * PI * fragments%density(istart:nfrag)))**(1.0_DP / 3.0_DP) +#ifdef DOCONLOC + do concurrent(i = istart:nfrag) shared(fragments,Ip_avg) +#else do concurrent(i = istart:nfrag) +#endif fragments%Ip(:, i) = Ip_avg(:) end do diff --git a/src/helio/helio_gr.f90 b/src/helio/helio_gr.f90 index def25224d..6de300cae 100644 --- a/src/helio/helio_gr.f90 +++ b/src/helio/helio_gr.f90 @@ -77,7 +77,11 @@ pure module subroutine helio_gr_p4_pl(self, nbody_system, param, dt) associate(pl => self) npl = self%nbody +#ifdef DOCONLOC + do concurrent(i = 1:npl, pl%lmask(i)) shared(param,pl,dt) +#else do concurrent(i = 1:npl, pl%lmask(i)) +#endif call swiftest_gr_p4_pos_kick(param, pl%rh(:, i), pl%vb(:, i), dt) end do end associate @@ -106,7 +110,11 @@ pure module subroutine helio_gr_p4_tp(self, nbody_system, param, dt) associate(tp => self) ntp = self%nbody +#ifdef DOCONLOC + do concurrent(i = 1:ntp, tp%lmask(i)) shared(param,tp,dt) +#else do concurrent(i = 1:ntp, tp%lmask(i)) +#endif call swiftest_gr_p4_pos_kick(param, tp%rh(:, i), tp%vb(:, i), dt) end do end associate diff --git a/src/helio/helio_kick.f90 b/src/helio/helio_kick.f90 index 89c93a7ed..755a385d9 100644 --- a/src/helio/helio_kick.f90 +++ b/src/helio/helio_kick.f90 @@ -117,7 +117,11 @@ module subroutine helio_kick_vb_pl(self, nbody_system, param, t, dt, lbeg) else call pl%set_beg_end(rend = pl%rh) end if +#ifdef DOCONLOC + do concurrent(i = 1:npl, pl%lmask(i)) shared(pl,dt) +#else do concurrent(i = 1:npl, pl%lmask(i)) +#endif pl%vb(1, i) = pl%vb(1, i) + pl%ah(1, i) * dt pl%vb(2, i) = pl%vb(2, i) + pl%ah(2, i) * dt pl%vb(3, i) = pl%vb(3, i) + pl%ah(3, i) * dt @@ -152,7 +156,11 @@ module subroutine helio_kick_vb_tp(self, nbody_system, param, t, dt, lbeg) ntp = self%nbody tp%ah(:, 1:ntp) = 0.0_DP call tp%accel(nbody_system, param, t, lbeg) +#ifdef DOCONLOC + do concurrent(i = 1:ntp, tp%lmask(i)) shared(tp,dt) +#else do concurrent(i = 1:ntp, tp%lmask(i)) +#endif tp%vb(:, i) = tp%vb(:, i) + tp%ah(:, i) * dt end do end associate diff --git a/src/operator/operator_cross.f90 b/src/operator/operator_cross.f90 index f784a1c98..ef80e1fb8 100644 --- a/src/operator/operator_cross.f90 +++ b/src/operator/operator_cross.f90 @@ -104,7 +104,11 @@ pure module function operator_cross_el_sp(A, B) result(C) n = size(A, 2) if (allocated(C)) deallocate(C) allocate(C, mold = A) +#ifdef DOCONLOC + do concurrent (i = 1:n) shared(A,B,C) +#else do concurrent (i = 1:n) +#endif C(:,i) = operator_cross_sp(A(:,i), B(:,i)) end do return @@ -118,7 +122,11 @@ pure module function operator_cross_el_dp(A, B) result(C) n = size(A, 2) if (allocated(C)) deallocate(C) allocate(C, mold = A) +#ifdef DOCONLOC + do concurrent (i = 1:n) shared(A,B,C) +#else do concurrent (i = 1:n) +#endif C(:,i) = operator_cross_dp(A(:,i), B(:,i)) end do return @@ -132,7 +140,11 @@ pure module function operator_cross_el_qp(A, B) result(C) n = size(A, 2) if (allocated(C)) deallocate(C) allocate(C, mold = A) +#ifdef DOCONLOC + do concurrent (i = 1:n) shared(A,B,C) +#else do concurrent (i = 1:n) +#endif C(:,i) = operator_cross_qp(A(:,i), B(:,i)) end do return @@ -146,7 +158,11 @@ pure module function operator_cross_el_i1b(A, B) result(C) n = size(A, 2) if (allocated(C)) deallocate(C) allocate(C, mold = A) +#ifdef DOCONLOC + do concurrent (i = 1:n) shared(A,B,C) +#else do concurrent (i = 1:n) +#endif C(:,i) = operator_cross_i1b(A(:,i), B(:,i)) end do return @@ -160,7 +176,11 @@ pure module function operator_cross_el_i2b(A, B) result(C) n = size(A, 2) if (allocated(C)) deallocate(C) allocate(C, mold = A) +#ifdef DOCONLOC + do concurrent (i = 1:n) shared(A,B,C) +#else do concurrent (i = 1:n) +#endif C(:,i) = operator_cross_i2b(A(:,i), B(:,i)) end do return @@ -174,7 +194,11 @@ pure module function operator_cross_el_i4b(A, B) result(C) n = size(A, 2) if (allocated(C)) deallocate(C) allocate(C, mold = A) +#ifdef DOCONLOC + do concurrent (i = 1:n) shared(A,B,C) +#else do concurrent (i = 1:n) +#endif C(:,i) = operator_cross_i4b(A(:,i), B(:,i)) end do return @@ -188,7 +212,11 @@ pure module function operator_cross_el_i8b(A, B) result(C) n = size(A, 2) if (allocated(C)) deallocate(C) allocate(C, mold = A) +#ifdef DOCONLOC + do concurrent (i = 1:n) shared(A,B,C) +#else do concurrent (i = 1:n) +#endif C(:,i) = operator_cross_i8b(A(:,i), B(:,i)) end do return diff --git a/src/operator/operator_mag.f90 b/src/operator/operator_mag.f90 index 8bf6bff5b..55f653fb9 100644 --- a/src/operator/operator_mag.f90 +++ b/src/operator/operator_mag.f90 @@ -44,7 +44,11 @@ pure module function operator_mag_el_sp(A) result(B) if (allocated(B)) deallocate(B) allocate(B(n)) call ieee_set_halting_mode(ieee_underflow, .false.) - do concurrent (i=1:n) +#ifdef DOCONLOC + do concurrent (i = 1:n) shared(A,B) +#else + do concurrent (i = 1:n) +#endif B(i) = norm2(A(:, i)) end do return @@ -59,7 +63,11 @@ pure module function operator_mag_el_dp(A) result(B) if (allocated(B)) deallocate(B) allocate(B(n)) call ieee_set_halting_mode(ieee_underflow, .false.) - do concurrent (i=1:n) +#ifdef DOCONLOC + do concurrent (i = 1:n) shared(A,B) +#else + do concurrent (i = 1:n) +#endif B(i) = norm2(A(:, i)) end do return @@ -74,7 +82,11 @@ pure module function operator_mag_el_qp(A) result(B) if (allocated(B)) deallocate(B) allocate(B(n)) call ieee_set_halting_mode(ieee_underflow, .false.) - do concurrent (i=1:n) +#ifdef DOCONLOC + do concurrent (i = 1:n) shared(A,B) +#else + do concurrent (i = 1:n) +#endif B(i) = norm2(A(:, i)) end do return diff --git a/src/operator/operator_unit.f90 b/src/operator/operator_unit.f90 index 39f3fce53..a25ee1bb1 100644 --- a/src/operator/operator_unit.f90 +++ b/src/operator/operator_unit.f90 @@ -89,7 +89,11 @@ pure module function operator_unit_el_sp(A) result(B) if (allocated(B)) deallocate(B) allocate(B(NDIM,n)) +#ifdef DOCONLOC + do concurrent (i=1:n) shared(A,B) +#else do concurrent (i=1:n) +#endif B(:,i) = operator_unit_sp(A(:,i)) end do @@ -109,7 +113,11 @@ pure module function operator_unit_el_dp(A) result(B) if (allocated(B)) deallocate(B) allocate(B(NDIM,n)) +#ifdef DOCONLOC + do concurrent (i=1:n) shared(A,B) +#else do concurrent (i=1:n) +#endif B(:,i) = operator_unit_dp(A(:,i)) end do @@ -128,7 +136,11 @@ pure module function operator_unit_el_qp(A) result(B) if (allocated(B)) deallocate(B) allocate(B(NDIM,n)) +#ifdef DOCONLOC + do concurrent (i=1:n) shared(A,B) +#else do concurrent (i=1:n) +#endif B(:,i) = operator_unit_qp(A(:,i)) end do diff --git a/src/rmvs/rmvs_kick.f90 b/src/rmvs/rmvs_kick.f90 index 8fb6c14ce..82d19463e 100644 --- a/src/rmvs/rmvs_kick.f90 +++ b/src/rmvs/rmvs_kick.f90 @@ -61,17 +61,29 @@ module subroutine rmvs_kick_getacch_tp(self, nbody_system, param, t, lbeg) ! Now compute any heliocentric values of acceleration if (tp%lfirst) then +#ifdef DOCONLOC + do concurrent(i = 1:ntp, tp%lmask(i)) shared(tp) +#else do concurrent(i = 1:ntp, tp%lmask(i)) +#endif tp%rheliocentric(:,i) = tp%rh(:,i) + cb%inner(inner_index - 1)%x(:,1) end do else +#ifdef DOCONLOC + do concurrent(i = 1:ntp, tp%lmask(i)) shared(tp) +#else do concurrent(i = 1:ntp, tp%lmask(i)) +#endif tp%rheliocentric(:,i) = tp%rh(:,i) + cb%inner(inner_index )%x(:,1) end do end if ! Swap the planetocentric and heliocentric position vectors and central body masses +#ifdef DOCONLOC + do concurrent(i = 1:ntp, tp%lmask(i)) shared(tp) +#else do concurrent(i = 1:ntp, tp%lmask(i)) +#endif tp%rh(:, i) = tp%rheliocentric(:, i) end do GMcb_original = cb%Gmass diff --git a/src/swiftest/swiftest_drift.f90 b/src/swiftest/swiftest_drift.f90 index 5c0427c62..82239e452 100644 --- a/src/swiftest/swiftest_drift.f90 +++ b/src/swiftest/swiftest_drift.f90 @@ -82,7 +82,11 @@ module subroutine swiftest_drift_all(mu, x, v, n, param, dt, lmask, iflag) allocate(dtp(n)) if (param%lgr) then +#ifdef DOCONLOC + do concurrent(i = 1:n, lmask(i)) shared(param,lmask,x,v,mu,dtp,dt) local(rmag,vmag2,energy) +#else do concurrent(i = 1:n, lmask(i)) +#endif rmag = norm2(x(:, i)) vmag2 = dot_product(v(:, i), v(:, i)) energy = 0.5_DP * vmag2 - mu(i) / rmag diff --git a/src/swiftest/swiftest_gr.f90 b/src/swiftest/swiftest_gr.f90 index 1c37d3da4..1985f6dd1 100644 --- a/src/swiftest/swiftest_gr.f90 +++ b/src/swiftest/swiftest_gr.f90 @@ -73,7 +73,11 @@ pure module subroutine swiftest_gr_kick_getacch(mu, x, lmask, n, inv_c2, agr) real(DP) :: beta, rjmag4 agr(:,:) = 0.0_DP +#ifdef DOCONLOC + do concurrent (i = 1:n, lmask(i)) shared(lmask,x,mu,agr,inv_c2) local(rjmag4,beta) +#else do concurrent (i = 1:n, lmask(i)) +#endif rjmag4 = (dot_product(x(:, i), x(:, i)))**2 beta = -mu(i)**2 * inv_c2 agr(:, i) = 2 * beta * x(:, i) / rjmag4 diff --git a/src/swiftest/swiftest_kick.f90 b/src/swiftest/swiftest_kick.f90 index 751702fa2..82cefd26c 100644 --- a/src/swiftest/swiftest_kick.f90 +++ b/src/swiftest/swiftest_kick.f90 @@ -21,7 +21,6 @@ module subroutine swiftest_kick_getacch_int_pl(self, param) class(swiftest_pl), intent(inout) :: self !! Swiftest massive body object class(swiftest_parameters), intent(inout) :: param !! Current swiftest run configuration parameters ! Internals - logical, save :: lfirst = .true. #ifdef PROFILE type(walltimer), save :: timer #endif @@ -136,7 +135,7 @@ module subroutine swiftest_kick_getacch_int_all_flat_norad_pl(npl, nplpl, k_plpl integer(I8B) :: k real(DP), dimension(NDIM,npl) :: ahi, ahj integer(I4B) :: i, j - real(DP) :: rji2, rlim2 + real(DP) :: rji2 real(DP) :: rx, ry, rz ahi(:,:) = 0.0_DP @@ -197,7 +196,11 @@ module subroutine swiftest_kick_getacch_int_all_tri_rad_pl(npl, nplm, r, Gmass, !$omp reduction(+:ahi) & !$omp reduction(-:ahj) do i = 1, nplm +#ifdef DOCONLOC + do concurrent(j = i+1:npl) shared(i,r,radius,ahi,ahj,Gmass) local(rx,ry,rz,rji2,rlim2) +#else do concurrent(j = i+1:npl) +#endif rx = r(1, j) - r(1, i) ry = r(2, j) - r(2, i) rz = r(3, j) - r(3, i) @@ -208,14 +211,22 @@ module subroutine swiftest_kick_getacch_int_all_tri_rad_pl(npl, nplm, r, Gmass, end do end do !$omp end parallel do +#ifdef DOCONLOC + do concurrent(i = 1:npl) shared(acc,ahi,ahj) +#else do concurrent(i = 1:npl) +#endif acc(:,i) = acc(:,i) + ahi(:,i) + ahj(:,i) end do else !$omp parallel do default(private) schedule(static)& !$omp shared(npl, nplm, r, Gmass, radius, acc) do i = 1, nplm +#ifdef DOCONLOC + do concurrent(j = 1:npl, i/=j) shared(i,r,radius,Gmass,acc) local(rx,ry,rz,rji2,rlim2,fac) +#else do concurrent(j = 1:npl, i/=j) +#endif rx = r(1,j) - r(1,i) ry = r(2,j) - r(2,i) rz = r(3,j) - r(3,i) @@ -235,7 +246,11 @@ module subroutine swiftest_kick_getacch_int_all_tri_rad_pl(npl, nplm, r, Gmass, !$omp parallel do default(private) schedule(static)& !$omp shared(npl, nplm, r, Gmass, radius, acc) do i = nplm+1,npl +#ifdef DOCONLOC + do concurrent(j = 1:nplm) shared(i,r,radius,Gmass,acc) local(rx,ry,rz,rji2,rlim2,fac) +#else do concurrent(j = 1:nplm) +#endif rx = r(1,j) - r(1,i) ry = r(2,j) - r(2,i) rz = r(3,j) - r(3,i) @@ -275,7 +290,7 @@ module subroutine swiftest_kick_getacch_int_all_tri_norad_pl(npl, nplm, r, Gmass real(DP), dimension(:,:), intent(inout) :: acc !! Acceleration vector array ! Internals integer(I4B) :: i, j, nplt - real(DP) :: rji2, rlim2, fac, rx, ry, rz + real(DP) :: rji2, fac, rx, ry, rz real(DP), dimension(NDIM,npl) :: ahi, ahj logical :: lmtiny @@ -290,7 +305,11 @@ module subroutine swiftest_kick_getacch_int_all_tri_norad_pl(npl, nplm, r, Gmass !$omp reduction(+:ahi) & !$omp reduction(-:ahj) do i = 1, nplm +#ifdef DOCONLOC + do concurrent(j = i+1:npl) shared(i,r,Gmass,ahi,ahj) local(rx,ry,rz,rji2) +#else do concurrent(j = i+1:npl) +#endif rx = r(1, j) - r(1, i) ry = r(2, j) - r(2, i) rz = r(3, j) - r(3, i) @@ -300,14 +319,22 @@ module subroutine swiftest_kick_getacch_int_all_tri_norad_pl(npl, nplm, r, Gmass end do end do !$omp end parallel do +#ifdef DOCONLOC + do concurrent(i = 1:npl) shared(acc,ahi,ahj) +#else do concurrent(i = 1:npl) +#endif acc(:,i) = acc(:,i) + ahi(:,i) + ahj(:,i) end do else !$omp parallel do default(private) schedule(static)& !$omp shared(npl, nplm, r, Gmass, acc) do i = 1, nplm +#ifdef DOCONLOC + do concurrent(j = 1:npl, j/=i) shared(i,r,Gmass, acc) local(rx,ry,rz,rji2,fac) +#else do concurrent(j = 1:npl, j/=i) +#endif rx = r(1,j) - r(1,i) ry = r(2,j) - r(2,i) rz = r(3,j) - r(3,i) @@ -324,7 +351,11 @@ module subroutine swiftest_kick_getacch_int_all_tri_norad_pl(npl, nplm, r, Gmass !$omp parallel do default(private) schedule(static)& !$omp shared(npl, nplm, r, Gmass, acc) do i = nplm+1,npl +#ifdef DOCONLOC + do concurrent(j = 1:nplm) shared(i,r,Gmass,acc) local(rx,ry,rz,rji2,fac) +#else do concurrent(j = 1:nplm) +#endif rx = r(1,j) - r(1,i) ry = r(2,j) - r(2,i) rz = r(3,j) - r(3,i) @@ -369,7 +400,11 @@ module subroutine swiftest_kick_getacch_int_all_tp(ntp, npl, rtp, rpl, GMpl, lma !$omp reduction(-:acc) do i = 1, ntp if (lmask(i)) then +#ifdef DOCONLOC + do concurrent (j = 1:npl) shared(rtp,rpl,GMpl,acc) local(rx,ry,rz,rji2) +#else do concurrent (j = 1:npl) +#endif rx = rtp(1, i) - rpl(1, j) ry = rtp(2, i) - rpl(2, j) rz = rtp(3, i) - rpl(3, j) diff --git a/src/swiftest/swiftest_obl.f90 b/src/swiftest/swiftest_obl.f90 index 85f88bc7d..21f4363ae 100644 --- a/src/swiftest/swiftest_obl.f90 +++ b/src/swiftest/swiftest_obl.f90 @@ -35,7 +35,11 @@ module subroutine swiftest_obl_acc(n, GMcb, j2rp2, j4rp4, rh, lmask, aobl, GMpl, if (n == 0) return aobl(:,:) = 0.0_DP +#ifdef DOCONLOC + do concurrent(i = 1:n, lmask(i)) shared(lmask,rh,aobl) local(r2,irh,rinv2,t0,t1,t2,t3,fac1,fac2) +#else do concurrent(i = 1:n, lmask(i)) +#endif r2 = dot_product(rh(:, i), rh(:, i)) irh = 1.0_DP / sqrt(r2) rinv2 = irh**2 @@ -81,7 +85,11 @@ module subroutine swiftest_obl_acc_pl(self, nbody_system) npl = self%nbody call swiftest_obl_acc(npl, cb%Gmass, cb%j2rp2, cb%j4rp4, pl%rh, pl%lmask, pl%aobl, pl%Gmass, cb%aobl) +#ifdef DOCONLOC + do concurrent(i = 1:npl, pl%lmask(i)) shared(cb,pl) +#else do concurrent(i = 1:npl, pl%lmask(i)) +#endif pl%ah(:, i) = pl%ah(:, i) + pl%aobl(:, i) - cb%aobl(:) end do end associate @@ -117,7 +125,11 @@ module subroutine swiftest_obl_acc_tp(self, nbody_system) aoblcb = cb%aoblend end if +#ifdef DOCONLOC + do concurrent(i = 1:ntp, tp%lmask(i)) shared(tp,aoblcb) +#else do concurrent(i = 1:ntp, tp%lmask(i)) +#endif tp%ah(:, i) = tp%ah(:, i) + tp%aobl(:, i) - aoblcb(:) end do @@ -148,7 +160,7 @@ module subroutine swiftest_obl_pot_system(self) npl = self%pl%nbody if (.not. any(pl%lmask(1:npl))) return #ifdef DOCONLOC - do concurrent (i = 1:npl, pl%lmask(i)) shared(oblpot_arr) + do concurrent (i = 1:npl, pl%lmask(i)) shared(cb,pl,oblpot_arr) #else do concurrent (i = 1:npl, pl%lmask(i)) #endif diff --git a/src/swiftest/swiftest_orbel.f90 b/src/swiftest/swiftest_orbel.f90 index a3ec6f424..dafb3e293 100644 --- a/src/swiftest/swiftest_orbel.f90 +++ b/src/swiftest/swiftest_orbel.f90 @@ -26,7 +26,11 @@ module subroutine swiftest_orbel_el2xv_vec(self, cb) if (self%nbody == 0) return call self%set_mu(cb) +#ifdef DOCONLOC + do concurrent (i = 1:self%nbody) shared(self) +#else do concurrent (i = 1:self%nbody) +#endif call swiftest_orbel_el2xv(self%mu(i), self%a(i), self%e(i), self%inc(i), self%capom(i), & self%omega(i), self%capm(i), self%rh(:, i), self%vh(:, i)) end do @@ -887,7 +891,11 @@ module subroutine swiftest_orbel_xv2el_vec(self, cb) if (allocated(self%capom)) deallocate(self%capom); allocate(self%capom(self%nbody)) if (allocated(self%omega)) deallocate(self%omega); allocate(self%omega(self%nbody)) if (allocated(self%capm)) deallocate(self%capm); allocate(self%capm(self%nbody)) +#ifdef DOCONLOC + do concurrent (i = 1:self%nbody) shared(self) local(varpi,lam,f,cape,capf) +#else do concurrent (i = 1:self%nbody) +#endif call swiftest_orbel_xv2el(self%mu(i), self%rh(1,i), self%rh(2,i), self%rh(3,i), & self%vh(1,i), self%vh(2,i), self%vh(3,i), & self%a(i), self%e(i), self%inc(i), & @@ -932,7 +940,7 @@ pure module subroutine swiftest_orbel_xv2el(mu, rx, ry, rz, vx, vy, vz, a, e, in real(DP), intent(out) :: capf !! hyperbolic anomaly (hyperbolic orbits) ! Internals integer(I4B) :: iorbit_type - real(DP) :: hx, hy, hz, r, v2, h2, h, rdotv, energy, fac, u, w, cw, sw, face, tmpf, sf, cf, rdot, h_over_r2 + real(DP) :: hx, hy, hz, r, v2, h2, h, rdotv, energy, fac, u, w, cw, sw, face, tmpf, sf, cf, rdot a = 0.0_DP e = 0.0_DP diff --git a/src/swiftest/swiftest_util.f90 b/src/swiftest/swiftest_util.f90 index b3e43c7e2..b063cb418 100644 --- a/src/swiftest/swiftest_util.f90 +++ b/src/swiftest/swiftest_util.f90 @@ -282,7 +282,11 @@ module subroutine swiftest_util_coord_h2b_tp(self, cb) if (self%nbody == 0) return associate(tp => self) ntp = self%nbody +#ifdef DOCONLOC + do concurrent (i = 1:ntp, tp%status(i) /= INACTIVE) shared(cb,tp) +#else do concurrent (i = 1:ntp, tp%status(i) /= INACTIVE) +#endif tp%rb(:, i) = tp%rh(:, i) + cb%rb(:) tp%vb(:, i) = tp%vh(:, i) + cb%vb(:) end do @@ -310,7 +314,11 @@ module subroutine swiftest_util_coord_b2h_pl(self, cb) associate(pl => self) npl = self%nbody +#ifdef DOCONLOC + do concurrent (i = 1:npl, pl%status(i) /= INACTIVE) shared(cb,pl) +#else do concurrent (i = 1:npl, pl%status(i) /= INACTIVE) +#endif pl%rh(:, i) = pl%rb(:, i) - cb%rb(:) pl%vh(:, i) = pl%vb(:, i) - cb%vb(:) end do @@ -338,7 +346,11 @@ module subroutine swiftest_util_coord_b2h_tp(self, cb) associate(tp => self) ntp = self%nbody +#ifdef DOCONLOC + do concurrent(i = 1:ntp, tp%status(i) /= INACTIVE) shared(cb,tp) +#else do concurrent(i = 1:ntp, tp%status(i) /= INACTIVE) +#endif tp%rh(:, i) = tp%rb(:, i) - cb%rb(:) tp%vh(:, i) = tp%vb(:, i) - cb%vb(:) end do @@ -370,7 +382,11 @@ module subroutine swiftest_util_coord_vb2vh_pl(self, cb) do i = npl, 1, -1 if (pl%status(i) /= INACTIVE) cb%vb(:) = cb%vb(:) - pl%Gmass(i) * pl%vb(:, i) / cb%Gmass end do +#ifdef DOCONLOC + do concurrent(i = 1:npl) shared(cb,pl) +#else do concurrent(i = 1:npl) +#endif pl%vh(:, i) = pl%vb(:, i) - cb%vb(:) end do end associate @@ -430,7 +446,11 @@ module subroutine swiftest_util_coord_vh2vb_pl(self, cb) cb%vb(:) = cb%vb(:) - pl%Gmass(i) * pl%vh(:, i) end do cb%vb(:) = cb%vb(:) / Gmtot +#ifdef DOCONLOC + do concurrent(i = 1:npl) shared(cb,pl) +#else do concurrent(i = 1:npl) +#endif pl%vb(:, i) = pl%vh(:, i) + cb%vb(:) end do end associate @@ -518,7 +538,11 @@ module subroutine swiftest_util_coord_rh2rb_tp(self, cb) if (self%nbody == 0) return associate(tp => self) ntp = self%nbody +#ifdef DOCONLOC + do concurrent (i = 1:ntp, tp%status(i) /= INACTIVE) shared(cb,tp) +#else do concurrent (i = 1:ntp, tp%status(i) /= INACTIVE) +#endif tp%rb(:, i) = tp%rh(:, i) + cb%rb(:) end do end associate @@ -1089,7 +1113,11 @@ module subroutine swiftest_util_flatten_eucl_plpl(self, param) if (err /=0) then ! An error occurred trying to allocate this big array. This probably means it's too big to fit in memory, and so we will force the run back into triangular mode param%lflatten_interactions = .false. else +#ifdef DOCONLOC + do concurrent (i=1:npl, j=1:npl, j>i) shared(self) local(k) +#else do concurrent (i=1:npl, j=1:npl, j>i) +#endif call swiftest_util_flatten_eucl_ij_to_k(self%nbody, i, j, k) self%k_plpl(1, k) = i self%k_plpl(2, k) = j @@ -1179,7 +1207,7 @@ module subroutine swiftest_util_get_energy_and_momentum_system(self, param) Lcborbit(:) = cb%mass * (cb%rb(:) .cross. cb%vb(:)) #ifdef DOCONLOC - do concurrent (i = 1:npl, pl%lmask(i)) local(h) shared(Lplorbit, kepl) + do concurrent (i = 1:npl, pl%lmask(i)) shared(pl,Lplorbit,kepl) local(h) #else do concurrent (i = 1:npl, pl%lmask(i)) #endif @@ -1199,7 +1227,7 @@ module subroutine swiftest_util_get_energy_and_momentum_system(self, param) Lcbspin(:) = cb%Ip(3) * cb%mass * cb%radius**2 * cb%rot(:) #ifdef DOCONLOC - do concurrent (i = 1:npl, pl%lmask(i)) shared(Lplspin, kespinpl) + do concurrent (i = 1:npl, pl%lmask(i)) shared(pl,Lplspin,kespinpl) #else do concurrent (i = 1:npl, pl%lmask(i)) #endif @@ -1213,7 +1241,11 @@ module subroutine swiftest_util_get_energy_and_momentum_system(self, param) nbody_system%ke_spin = 0.5_DP * (kespincb + sum(kespinpl(1:npl), pl%lmask(1:npl))) +#ifdef DOCONLOC + do concurrent (j = 1:NDIM) shared(nbody_system,pl,Lplspin,Lcbspin) +#else do concurrent (j = 1:NDIM) +#endif nbody_system%L_spin(j) = Lcbspin(j) + sum(Lplspin(j,1:npl), pl%lmask(1:npl)) end do else @@ -1234,8 +1266,11 @@ module subroutine swiftest_util_get_energy_and_momentum_system(self, param) end if nbody_system%ke_orbit = 0.5_DP * (kecb + sum(kepl(1:npl), pl%lmask(1:npl))) - +#ifdef DOCONLOC + do concurrent (j = 1:NDIM) shared(nbody_system,pl,Lcborbit,Lplorbit) +#else do concurrent (j = 1:NDIM) +#endif nbody_system%L_orbit(j) = Lcborbit(j) + sum(Lplorbit(j,1:npl), pl%lmask(1:npl)) end do @@ -1280,7 +1315,7 @@ module subroutine swiftest_util_get_potential_energy_flat(npl, nplpl, k_plpl, lm end where #ifdef DOCONLOC - do concurrent(i = 1:npl, lmask(i)) shared(pecb) + do concurrent(i = 1:npl, lmask(i)) shared(lmask,pecb,GMcb,mass,rb) #else do concurrent(i = 1:npl, lmask(i)) #endif @@ -1331,7 +1366,7 @@ module subroutine swiftest_util_get_potential_energy_triangular(npl, lmask, GMcb end where #ifdef DOCONLOC - do concurrent(i = 1:npl, lmask(i)) shared(pecb) + do concurrent(i = 1:npl, lmask(i)) shared(lmask, pecb, GMcb, mass, rb, lmask) #else do concurrent(i = 1:npl, lmask(i)) #endif @@ -1346,7 +1381,7 @@ module subroutine swiftest_util_get_potential_energy_triangular(npl, lmask, GMcb do i = 1, npl if (lmask(i)) then #ifdef DOCONLOC - do concurrent(j = i+1:npl, lmask(i) .and. lmask(j)) shared(pepl) + do concurrent(j = i+1:npl, lmask(i) .and. lmask(j)) shared(lmask, pepl, rb, mass, Gmass, lmask) #else do concurrent(j = i+1:npl, lmask(i) .and. lmask(j)) #endif diff --git a/src/symba/symba_encounter_check.f90 b/src/symba/symba_encounter_check.f90 index 895a9f34d..4bc92b79d 100644 --- a/src/symba/symba_encounter_check.f90 +++ b/src/symba/symba_encounter_check.f90 @@ -119,7 +119,11 @@ module function symba_encounter_check_list_plpl(self, param, nbody_system, dt, i eidx(:) = pack([(k, k = 1, self%nenc)], lencmask(:)) lencounter(:) = .false. +#ifdef DOCONLOC + do concurrent(lidx = 1:nenc_enc) shared(self,pl,eidx,lencounter,dt) local(i,j,k,xr,vr,rcrit12,rlim2,rji2) +#else do concurrent(lidx = 1:nenc_enc) +#endif k = eidx(lidx) i = self%index1(k) j = self%index2(k) @@ -188,8 +192,11 @@ module function symba_encounter_check_list_pltp(self, param, nbody_system, dt, i allocate(lencounter(nenc_enc)) eidx(:) = pack([(k, k = 1, self%nenc)], lencmask(:)) lencounter(:) = .false. - +#ifdef DOCONLOC + do concurrent(lidx = 1:nenc_enc) shared(self,pl,tp,eidx,lencounter,dt) local(i,j,k,xr,vr,rlim2,rji2) +#else do concurrent(lidx = 1:nenc_enc) +#endif k = eidx(lidx) i = self%index1(k) j = self%index2(k) diff --git a/src/symba/symba_kick.f90 b/src/symba/symba_kick.f90 index 0c75e1054..dc280ef1c 100644 --- a/src/symba/symba_kick.f90 +++ b/src/symba/symba_kick.f90 @@ -172,7 +172,11 @@ module subroutine symba_kick_list_plpl(self, nbody_system, dt, irec, sgn) allocate(good_idx(ngood)) good_idx(:) = pack([(i, i = 1, nenc)], lgoodlevel(:)) +#ifdef DOCONLOC + do concurrent (k = 1:ngood) shared(self,pl,good_idx) local(i,j) +#else do concurrent (k = 1:ngood) +#endif i = self%index1(good_idx(k)) j = self%index2(good_idx(k)) pl%ah(:,i) = 0.0_DP @@ -282,8 +286,11 @@ module subroutine symba_kick_list_pltp(self, nbody_system, dt, irec, sgn) allocate(good_idx(ngood)) good_idx(:) = pack([(i, i = 1, nenc)], lgoodlevel(:)) - +#ifdef DOCONLOC + do concurrent (k = 1_I8B:ngood) shared(self,tp,good_idx) local(j) +#else do concurrent (k = 1_I8B:ngood) +#endif j = self%index2(good_idx(k)) tp%ah(:,j) = 0.0_DP end do diff --git a/src/whm/whm_gr.f90 b/src/whm/whm_gr.f90 index 1b1716800..c46a5ce2d 100644 --- a/src/whm/whm_gr.f90 +++ b/src/whm/whm_gr.f90 @@ -86,7 +86,11 @@ pure module subroutine whm_gr_p4_pl(self, nbody_system, param, dt) associate(pl => self) npl = self%nbody +#ifdef DOCONLOC + do concurrent(i = 1:npl, pl%lmask(i)) shared(pl,dt) +#else do concurrent(i = 1:npl, pl%lmask(i)) +#endif call swiftest_gr_p4_pos_kick(param, pl%xj(:, i), pl%vj(:, i), dt) end do end associate @@ -114,7 +118,11 @@ pure module subroutine whm_gr_p4_tp(self, nbody_system, param, dt) associate(tp => self) ntp = self%nbody if (ntp == 0) return +#ifdef DOCONLOC + do concurrent(i = 1:ntp, tp%lmask(i)) shared(tp,dt) +#else do concurrent(i = 1:ntp, tp%lmask(i)) +#endif call swiftest_gr_p4_pos_kick(param, tp%rh(:, i), tp%vh(:, i), dt) end do end associate diff --git a/src/whm/whm_kick.f90 b/src/whm/whm_kick.f90 index a1d4b0dc6..bcddf0de7 100644 --- a/src/whm/whm_kick.f90 +++ b/src/whm/whm_kick.f90 @@ -93,13 +93,21 @@ module subroutine whm_kick_getacch_tp(self, nbody_system, param, t, lbeg) if (lbeg) then ah0(:) = whm_kick_getacch_ah0(pl%Gmass(1:npl), pl%rbeg(:, 1:npl), npl) +#ifdef DOCONLOC + do concurrent(i = 1:ntp, tp%lmask(i)) shared(tp,ah0) +#else do concurrent(i = 1:ntp, tp%lmask(i)) +#endif tp%ah(:, i) = tp%ah(:, i) + ah0(:) end do call tp%accel_int(param, pl%Gmass(1:npl), pl%rbeg(:, 1:npl), npl) else ah0(:) = whm_kick_getacch_ah0(pl%Gmass(1:npl), pl%rend(:, 1:npl), npl) +#ifdef DOCONLOC + do concurrent(i = 1:ntp, tp%lmask(i)) shared(tp,ah0) +#else do concurrent(i = 1:ntp, tp%lmask(i)) +#endif tp%ah(:, i) = tp%ah(:, i) + ah0(:) end do call tp%accel_int(param, pl%Gmass(1:npl), pl%rend(:, 1:npl), npl) @@ -157,7 +165,11 @@ pure subroutine whm_kick_getacch_ah1(cb, pl) real(DP), dimension(NDIM) :: ah1h, ah1j npl = pl%nbody +#ifdef DOCONLOC + do concurrent (i = 2:npl, pl%lmask(i)) shared(pl,cb) local(ah1j,ah1h) +#else do concurrent (i = 2:npl, pl%lmask(i)) +#endif ah1j(:) = pl%xj(:, i) * pl%ir3j(i) ah1h(:) = pl%rh(:, i) * pl%ir3h(i) pl%ah(:, i) = pl%ah(:, i) + cb%Gmass * (ah1j(:) - ah1h(:)) @@ -187,10 +199,14 @@ pure subroutine whm_kick_getacch_ah2(cb, pl) ah2(:) = 0.0_DP ah2o(:) = 0.0_DP etaj = cb%Gmass +#ifdef DOCONLOC + do concurrent(i = 2:npl, pl%lmask(i)) shared(pl,cb,ah2,ah2o) local(etaj,fac) +#else do concurrent(i = 2:npl, pl%lmask(i)) +#endif etaj = etaj + pl%Gmass(i - 1) fac = pl%Gmass(i) * cb%Gmass * pl%ir3j(i) / etaj - ah2(:) = ah2o + fac * pl%xj(:, i) + ah2(:) = ah2o(:) + fac * pl%xj(:, i) pl%ah(:,i) = pl%ah(:, i) + ah2(:) ah2o(:) = ah2(:) end do @@ -233,7 +249,11 @@ module subroutine whm_kick_vh_pl(self, nbody_system, param, t, dt, lbeg) call pl%accel(nbody_system, param, t, lbeg) call pl%set_beg_end(rend = pl%rh) end if +#ifdef DOCONLOC + do concurrent(i = 1:npl, pl%lmask(i)) shared(pl,dt) +#else do concurrent(i = 1:npl, pl%lmask(i)) +#endif pl%vh(:, i) = pl%vh(:, i) + pl%ah(:, i) * dt end do end associate @@ -265,19 +285,31 @@ module subroutine whm_kick_vh_tp(self, nbody_system, param, t, dt, lbeg) associate(tp => self) ntp = self%nbody if (tp%lfirst) then +#ifdef DOCONLOC + do concurrent(i = 1:ntp, tp%lmask(i)) shared(tp) +#else do concurrent(i = 1:ntp, tp%lmask(i)) +#endif tp%ah(:, i) = 0.0_DP end do call tp%accel(nbody_system, param, t, lbeg=.true.) tp%lfirst = .false. end if if (.not.lbeg) then +#ifdef DOCONLOC + do concurrent(i = 1:ntp, tp%lmask(i)) shared(tp) +#else do concurrent(i = 1:ntp, tp%lmask(i)) +#endif tp%ah(:, i) = 0.0_DP end do call tp%accel(nbody_system, param, t, lbeg) end if +#ifdef DOCONLOC + do concurrent(i = 1:ntp, tp%lmask(i)) shared(tp) +#else do concurrent(i = 1:ntp, tp%lmask(i)) +#endif tp%vh(:, i) = tp%vh(:, i) + tp%ah(:, i) * dt end do end associate From a2c5e5465f5f2e2172cb24472c32f1c92a01aaae Mon Sep 17 00:00:00 2001 From: David A Minton Date: Fri, 19 May 2023 23:01:01 -0400 Subject: [PATCH 19/95] Fixed typo that prevented Ip from being automatically set when rotation vectors were passed --- python/swiftest/swiftest/init_cond.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/swiftest/swiftest/init_cond.py b/python/swiftest/swiftest/init_cond.py index efaa6429f..1b140f119 100644 --- a/python/swiftest/swiftest/init_cond.py +++ b/python/swiftest/swiftest/init_cond.py @@ -283,7 +283,7 @@ def vec2xr(param: Dict, **kwargs: Any): # Check for valid keyword arguments kwargs = {k:kwargs[k] for k,v in kwargs.items() if v is not None} - if "rotation" in param and param['rotation'] == True: + if "ROTATION" in param and param['ROTATION'] == True: if "rot" not in kwargs and "Gmass" in kwargs: kwargs['rot'] = np.zeros((len(kwargs['Gmass']),3)) if "Ip" not in kwargs and "Gmass" in kwargs: From b6e61d353e9cae167c606ff35574394317de8e2c Mon Sep 17 00:00:00 2001 From: David A Minton Date: Sat, 20 May 2023 07:12:15 -0400 Subject: [PATCH 20/95] Fixed bug in example problem where escape velocity was miscalculated when setting test particle initial conditions --- .../rmvs_swifter_comparison/8pl_16tp_encounters/init_cond.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/rmvs_swifter_comparison/8pl_16tp_encounters/init_cond.py b/examples/rmvs_swifter_comparison/8pl_16tp_encounters/init_cond.py index d59c068d6..725c123b1 100755 --- a/examples/rmvs_swifter_comparison/8pl_16tp_encounters/init_cond.py +++ b/examples/rmvs_swifter_comparison/8pl_16tp_encounters/init_cond.py @@ -17,7 +17,7 @@ for i,n in enumerate(pl.name): pli = pl.sel(name=n) rstart = 2 * pli['radius'].data[0] # Start the test particles at a multiple of the planet radius away - vstart = 1.5 * np.sqrt(2 * pli['Gmass'].data[0]) / rstart # Start the test particle velocities at a multiple of the escape speed + vstart = 1.5 * np.sqrt(2 * pli['Gmass'].data[0] / rstart) # Start the test particle velocities at a multiple of the escape speed rstart_vec = np.array([rstart / np.sqrt(2.0), rstart / np.sqrt(2.0), 0.0]) vstart_vec = np.array([vstart, 0.0, 0.0]) rp = pli['rh'].data[0] From 4fa3506f561ff0589a9be5283c521c43eaaf331a Mon Sep 17 00:00:00 2001 From: David Minton Date: Sat, 20 May 2023 16:44:54 -0400 Subject: [PATCH 21/95] Cleaned up a few more unused variables caught during testing on fresh install --- src/encounter/encounter_util.f90 | 6 ++---- src/swiftest/swiftest_io.f90 | 10 +++++++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/encounter/encounter_util.f90 b/src/encounter/encounter_util.f90 index f935afe5a..7307eb9cb 100644 --- a/src/encounter/encounter_util.f90 +++ b/src/encounter/encounter_util.f90 @@ -22,7 +22,7 @@ module subroutine encounter_util_append_list(self, source, lsource_mask) class(encounter_list), intent(in) :: source !! Source object to append logical, dimension(:), intent(in) :: lsource_mask !! Logical mask indicating which elements to append to ! Internals - integer(I4B) :: nold, nsrc + integer(I4B) :: nold nold = int(self%nenc, kind=I4B) call util_append(self%tcollision, source%tcollision, nold, lsource_mask) @@ -100,8 +100,6 @@ module subroutine encounter_util_dealloc_bounding_box(self) implicit none ! Arguments class(encounter_bounding_box), intent(inout) :: self !! Bounding box structure - ! Internals - integer(I4B) :: i call self%aabb%dealloc() @@ -341,7 +339,7 @@ module subroutine encounter_util_setup_aabb(self, n, n_last) integer(I4B), intent(in) :: n !! Number of objects with bounding box extents integer(I4B), intent(in) :: n_last !! Number of objects with bounding box extents the previous time this was called ! Internals - integer(I4B) :: next, next_last, k, dim + integer(I4B) :: next, next_last, k integer(I4B), dimension(:), allocatable :: itmp next = 2 * n diff --git a/src/swiftest/swiftest_io.f90 b/src/swiftest/swiftest_io.f90 index 0f2f6be2b..1e02a7645 100644 --- a/src/swiftest/swiftest_io.f90 +++ b/src/swiftest/swiftest_io.f90 @@ -414,7 +414,9 @@ module subroutine swiftest_io_dump_storage(self, param) class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters ! Internals integer(I4B) :: i +#ifdef COARRAY type(walltimer) :: iotimer +#endif if (self%iframe == 0) return call self%make_index_map() @@ -1043,7 +1045,7 @@ module subroutine swiftest_io_netcdf_get_valid_masks(self, plmask, tpmask) real(DP), dimension(:,:), allocatable :: rh integer(I4B), dimension(:), allocatable :: body_status logical, dimension(:), allocatable :: lvalid - integer(I4B) :: idmax, status,i + integer(I4B) :: idmax, status call netcdf_io_check( nf90_inquire_dimension(self%id, self%name_dimid, len=idmax), "swiftest_io_netcdf_get_valid_masks nf90_inquire_dimension name_dimid" ) @@ -1615,11 +1617,14 @@ module subroutine swiftest_io_netcdf_write_frame_body(self, nc, param) class(swiftest_netcdf_parameters), intent(inout) :: nc !! Parameters used to for writing a NetCDF dataset to file class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters ! Internals - integer(I4B) :: i, j, idslot, old_mode, ntp + integer(I4B) :: i, j, idslot, old_mode integer(I4B), dimension(:), allocatable :: ind real(DP), dimension(NDIM) :: vh !! Temporary variable to store heliocentric velocity values when converting from pseudovelocity in GR-enabled runs real(DP) :: a, e, inc, omega, capom, capm, varpi, lam, f, cape, capf +#ifdef COARRAY + integer(I4B) :: ntp logical, dimension(:), allocatable :: tpmask, plmask +#endif call self%write_info(nc, param) @@ -1798,7 +1803,6 @@ module subroutine swiftest_io_netcdf_write_hdr_system(self, nc, param) class(swiftest_netcdf_parameters), intent(inout) :: nc !! Parameters used to for writing a NetCDF dataset to file class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters ! Internals - logical, dimension(:), allocatable :: tpmask, plmask integer(I4B) :: tslot call nc%find_tslot(self%t, tslot) From 9556d1812a71573db858a56b3703d39b2e2f41d8 Mon Sep 17 00:00:00 2001 From: David Minton Date: Mon, 22 May 2023 17:41:40 -0400 Subject: [PATCH 22/95] Draft Dockerfile for creating a container for Swftest. I've commented out everything after netcdf-c compilation to troubleshoot the location of mpiifort for compiling the rest. --- .gitignore | 7 +++++- Dockerfile | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++ swiftest.def | 2 ++ 3 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 Dockerfile create mode 100644 swiftest.def diff --git a/.gitignore b/.gitignore index 674a2f7f4..81a7fb376 100644 --- a/.gitignore +++ b/.gitignore @@ -30,6 +30,11 @@ dump* !docs/*/*/* !README_figs/* +#Docker and Singularity files +!Dockerfile +!swiftest.def + bin/ build/* -disruption_headon/swiftest_driver.sh + + diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..69f0d1288 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,64 @@ +FROM debian:stable-slim as build + +# kick everything off +RUN apt-get update && apt-get upgrade -y && \ + DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + ca-certificates curl git gpg-agent software-properties-common build-essential gnupg pkg-config libaec-dev && \ + rm -rf /var/lib/apt/lists/* + +# Get CMAKE and install it +RUN mkdir -p cmake/build && \ + cd cmake/build && \ + curl -LO https://github.com/Kitware/CMake/releases/download/v3.26.2/cmake-3.26.2-linux-x86_64.sh && \ + /bin/bash cmake-3.26.2-linux-x86_64.sh --prefix=/usr/local --skip-license + +# Get the Intel compilers +RUN curl -fsSL https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS-2023.PUB | apt-key add - +RUN echo "deb [trusted=yes] https://apt.repos.intel.com/oneapi all main " > /etc/apt/sources.list.d/oneAPI.list +RUN apt-get -y update && apt-get upgrade -y +RUN apt-get install -y intel-oneapi-dev-utilities intel-oneapi-compiler-dpcpp-cpp intel-oneapi-compiler-dpcpp-cpp-and-cpp-classic intel-oneapi-compiler-fortran intel-oneapi-mkl-devel intel-oneapi-mpi-devel +RUN . /opt/intel/oneapi/setvars.sh + +# Build the NetCDF libraries +RUN mkdir -p /opt/build && mkdir -p /opt/dist +ENV INDIR="/opt/dist//usr/local" +ENV INTEL_DIR="/opt/intel/oneapi/compiler/latest/linux" +ENV CC="${INTEL_DIR}/bin/icx-cc" +ENV FC="${INTEL_DIR}/mpi/latest/bin/mpiifort" + +RUN apt-get update && apt-get upgrade -y && \ + DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + libhdf5-dev hdf5-tools zlib1g zlib1g-dev libxml2-dev libcurl-dev && \ + rm -rf /var/lib/apt/lists/* + + +#NetCDF-c library +RUN git clone https://github.com/Unidata/netcdf-c.git +RUN cd netcdf-c && mkdir build && cd build && \ + cmake .. -DCMAKE_PREFIX_PATH="${LD_LIBRARY_PATH}" -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_INSTALL_PREFIX="${INDIR}" && \ + make && make install + +#NetCDF-Fortran library +RUN git clone https://github.com/Unidata/netcdf-fortran.git +RUN cd netcdf-fortran && mkdir build && cd build && \ + cmake .. -DCMAKE_INSTALL_PREFIX="${INDIR}" && \ + make && make install + +#Swiftest +RUN git clone -b debug https://github.com/carlislewishard/swiftest.git +RUN cd swiftest && cmake -P distclean.cmake && mkdir build && cd build && \ + cmake .. -DCMAKE_BUILD_TYPE=release -DCMAKE_INSTALL_PREFIX="${INDIR}" && \ + make && make install + +#Production container +FROM debian:stable-slim +COPY --from=build /opt/dist / + +# Get the Intel runtime libraries +RUN curl -fsSL https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS-2023.PUB | apt-key add - +RUN deb [trusted=yes] https://apt.repos.intel.com/oneapi all main " > /etc/apt/sources.list.d/oneAPI.list +RUN apt-get -y update && apt-get upgrade -y +RUN apt-get install -y intel-oneapi-runtime-openmp intel-oneapi-runtime-mkl intel-oneapi-runtime-mpi intel-oneapi-runtime-fortran +RUN . /opt/intel/oneapi/setvars.sh + +CMD ["/usr/bin/swiftest_driver"] \ No newline at end of file diff --git a/swiftest.def b/swiftest.def new file mode 100644 index 000000000..9eeb9d3ef --- /dev/null +++ b/swiftest.def @@ -0,0 +1,2 @@ +Bootstrap: docker +From: daminton:swiftest:latest \ No newline at end of file From 5b5b5c130ea1b486ea049aeb84c288594d8f07e9 Mon Sep 17 00:00:00 2001 From: David Minton Date: Mon, 22 May 2023 18:01:55 -0400 Subject: [PATCH 23/95] Added missing components to Dockerfile --- Dockerfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 69f0d1288..4a82504e0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,13 +22,13 @@ RUN . /opt/intel/oneapi/setvars.sh # Build the NetCDF libraries RUN mkdir -p /opt/build && mkdir -p /opt/dist ENV INDIR="/opt/dist//usr/local" -ENV INTEL_DIR="/opt/intel/oneapi/compiler/latest/linux" -ENV CC="${INTEL_DIR}/bin/icx-cc" +ENV INTEL_DIR="/opt/intel/oneapi" +ENV CC="${INTEL_DIR}/compiler/latest/linux/bin/icx-cc" ENV FC="${INTEL_DIR}/mpi/latest/bin/mpiifort" RUN apt-get update && apt-get upgrade -y && \ DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ - libhdf5-dev hdf5-tools zlib1g zlib1g-dev libxml2-dev libcurl-dev && \ + libhdf5-dev hdf5-tools zlib1g zlib1g-dev libxml2-dev libcurl4-gnutls-dev m4 && \ rm -rf /var/lib/apt/lists/* From 8abdaec193811e103a78af0505bc975f4b52cb99 Mon Sep 17 00:00:00 2001 From: David Minton Date: Mon, 22 May 2023 20:06:11 -0400 Subject: [PATCH 24/95] Able to build the Docker container up to swiftest by using the ifx compiler, though I know this doesn't work for swiftest --- Dockerfile | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4a82504e0..33b92e209 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,7 @@ FROM debian:stable-slim as build # kick everything off RUN apt-get update && apt-get upgrade -y && \ DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ - ca-certificates curl git gpg-agent software-properties-common build-essential gnupg pkg-config libaec-dev && \ + ca-certificates curl git wget gpg-agent software-properties-common build-essential gnupg pkg-config libaec-dev && \ rm -rf /var/lib/apt/lists/* # Get CMAKE and install it @@ -13,10 +13,13 @@ RUN mkdir -p cmake/build && \ /bin/bash cmake-3.26.2-linux-x86_64.sh --prefix=/usr/local --skip-license # Get the Intel compilers -RUN curl -fsSL https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS-2023.PUB | apt-key add - -RUN echo "deb [trusted=yes] https://apt.repos.intel.com/oneapi all main " > /etc/apt/sources.list.d/oneAPI.list +# download the key to system keyring +RUN wget -O- https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB \ +| gpg --dearmor | tee /usr/share/keyrings/oneapi-archive-keyring.gpg > /dev/null +# add signed entry to apt sources and configure the APT client to use Intel repository: +RUN echo "deb [signed-by=/usr/share/keyrings/oneapi-archive-keyring.gpg] https://apt.repos.intel.com/oneapi all main" | tee /etc/apt/sources.list.d/oneAPI.list RUN apt-get -y update && apt-get upgrade -y -RUN apt-get install -y intel-oneapi-dev-utilities intel-oneapi-compiler-dpcpp-cpp intel-oneapi-compiler-dpcpp-cpp-and-cpp-classic intel-oneapi-compiler-fortran intel-oneapi-mkl-devel intel-oneapi-mpi-devel +RUN apt-get install -y intel-hpckit RUN . /opt/intel/oneapi/setvars.sh # Build the NetCDF libraries @@ -24,7 +27,7 @@ RUN mkdir -p /opt/build && mkdir -p /opt/dist ENV INDIR="/opt/dist//usr/local" ENV INTEL_DIR="/opt/intel/oneapi" ENV CC="${INTEL_DIR}/compiler/latest/linux/bin/icx-cc" -ENV FC="${INTEL_DIR}/mpi/latest/bin/mpiifort" +ENV FC="${INTEL_DIR}/compiler/latest/linux/bin/ifx" RUN apt-get update && apt-get upgrade -y && \ DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ @@ -44,21 +47,21 @@ RUN cd netcdf-fortran && mkdir build && cd build && \ cmake .. -DCMAKE_INSTALL_PREFIX="${INDIR}" && \ make && make install -#Swiftest -RUN git clone -b debug https://github.com/carlislewishard/swiftest.git -RUN cd swiftest && cmake -P distclean.cmake && mkdir build && cd build && \ - cmake .. -DCMAKE_BUILD_TYPE=release -DCMAKE_INSTALL_PREFIX="${INDIR}" && \ - make && make install +# #Swiftest +# RUN git clone -b debug https://github.com/carlislewishard/swiftest.git +# RUN cd swiftest && cmake -P distclean.cmake && mkdir build && cd build && \ +# cmake .. -DCMAKE_BUILD_TYPE=release -DCMAKE_INSTALL_PREFIX="${INDIR}" && \ +# make && make install -#Production container -FROM debian:stable-slim -COPY --from=build /opt/dist / +# #Production container +# FROM debian:stable-slim +# COPY --from=build /opt/dist / -# Get the Intel runtime libraries -RUN curl -fsSL https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS-2023.PUB | apt-key add - -RUN deb [trusted=yes] https://apt.repos.intel.com/oneapi all main " > /etc/apt/sources.list.d/oneAPI.list -RUN apt-get -y update && apt-get upgrade -y -RUN apt-get install -y intel-oneapi-runtime-openmp intel-oneapi-runtime-mkl intel-oneapi-runtime-mpi intel-oneapi-runtime-fortran -RUN . /opt/intel/oneapi/setvars.sh +# # Get the Intel runtime libraries +# RUN curl -fsSL https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS-2023.PUB | apt-key add - +# RUN deb [trusted=yes] https://apt.repos.intel.com/oneapi all main " > /etc/apt/sources.list.d/oneAPI.list +# RUN apt-get -y update && apt-get upgrade -y +# RUN apt-get install -y intel-oneapi-runtime-openmp intel-oneapi-runtime-mkl intel-oneapi-runtime-mpi intel-oneapi-runtime-fortran +# RUN . /opt/intel/oneapi/setvars.sh -CMD ["/usr/bin/swiftest_driver"] \ No newline at end of file +# ENTRYPOINT ["/usr/bin/swiftest_driver"] \ No newline at end of file From b1620a7ad4e7f36bd7010ed4066476efdeb6f0bf Mon Sep 17 00:00:00 2001 From: David Minton Date: Mon, 22 May 2023 22:41:17 -0400 Subject: [PATCH 25/95] Added another missing package --- Dockerfile | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/Dockerfile b/Dockerfile index 33b92e209..fe92b3728 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,7 @@ FROM debian:stable-slim as build # kick everything off RUN apt-get update && apt-get upgrade -y && \ DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ - ca-certificates curl git wget gpg-agent software-properties-common build-essential gnupg pkg-config libaec-dev && \ + ca-certificates curl git wget gpg-agent software-properties-common build-essential gnupg pkg-config libaec-dev procps && \ rm -rf /var/lib/apt/lists/* # Get CMAKE and install it @@ -47,21 +47,21 @@ RUN cd netcdf-fortran && mkdir build && cd build && \ cmake .. -DCMAKE_INSTALL_PREFIX="${INDIR}" && \ make && make install -# #Swiftest -# RUN git clone -b debug https://github.com/carlislewishard/swiftest.git -# RUN cd swiftest && cmake -P distclean.cmake && mkdir build && cd build && \ -# cmake .. -DCMAKE_BUILD_TYPE=release -DCMAKE_INSTALL_PREFIX="${INDIR}" && \ -# make && make install +#Swiftest +RUN git clone -b debug https://github.com/carlislewishard/swiftest.git +RUN cd swiftest && cmake -P distclean.cmake && mkdir build && cd build && \ + FC="${INTEL_DIR}/mpi/latest/bin/mpiifort" cmake .. -DCMAKE_BUILD_TYPE=release -DCMAKE_INSTALL_PREFIX="${INDIR}" && \ + make && make install -# #Production container -# FROM debian:stable-slim -# COPY --from=build /opt/dist / +#Production container +FROM debian:stable-slim +COPY --from=build /opt/dist / -# # Get the Intel runtime libraries -# RUN curl -fsSL https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS-2023.PUB | apt-key add - -# RUN deb [trusted=yes] https://apt.repos.intel.com/oneapi all main " > /etc/apt/sources.list.d/oneAPI.list -# RUN apt-get -y update && apt-get upgrade -y -# RUN apt-get install -y intel-oneapi-runtime-openmp intel-oneapi-runtime-mkl intel-oneapi-runtime-mpi intel-oneapi-runtime-fortran -# RUN . /opt/intel/oneapi/setvars.sh +# Get the Intel runtime libraries +RUN curl -fsSL https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS-2023.PUB | apt-key add - +RUN deb [trusted=yes] https://apt.repos.intel.com/oneapi all main " > /etc/apt/sources.list.d/oneAPI.list +RUN apt-get -y update && apt-get upgrade -y +RUN apt-get install -y intel-oneapi-runtime-openmp intel-oneapi-runtime-mkl intel-oneapi-runtime-mpi intel-oneapi-runtime-fortran +RUN . /opt/intel/oneapi/setvars.sh -# ENTRYPOINT ["/usr/bin/swiftest_driver"] \ No newline at end of file +ENTRYPOINT ["/usr/bin/swiftest_driver"] \ No newline at end of file From 3dfb89a100e89ee11f878f8d7de740c8a2e46649 Mon Sep 17 00:00:00 2001 From: David Minton Date: Tue, 23 May 2023 08:51:36 -0400 Subject: [PATCH 26/95] More improvements to Dockerfile. Now testing. --- Dockerfile | 67 +++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 61 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index fe92b3728..a6572206b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,7 +20,6 @@ RUN wget -O- https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRO RUN echo "deb [signed-by=/usr/share/keyrings/oneapi-archive-keyring.gpg] https://apt.repos.intel.com/oneapi all main" | tee /etc/apt/sources.list.d/oneAPI.list RUN apt-get -y update && apt-get upgrade -y RUN apt-get install -y intel-hpckit -RUN . /opt/intel/oneapi/setvars.sh # Build the NetCDF libraries RUN mkdir -p /opt/build && mkdir -p /opt/dist @@ -47,11 +46,65 @@ RUN cd netcdf-fortran && mkdir build && cd build && \ cmake .. -DCMAKE_INSTALL_PREFIX="${INDIR}" && \ make && make install -#Swiftest +# #Swiftest RUN git clone -b debug https://github.com/carlislewishard/swiftest.git -RUN cd swiftest && cmake -P distclean.cmake && mkdir build && cd build && \ - FC="${INTEL_DIR}/mpi/latest/bin/mpiifort" cmake .. -DCMAKE_BUILD_TYPE=release -DCMAKE_INSTALL_PREFIX="${INDIR}" && \ - make && make install +ENV FC="${INTEL_DIR}/mpi/latest/bin/mpiifort" +ENV NETCDF_HOME="${INDIR}" +ENV NETCDF_FORTRAN_HOME="${INDIR}" +ENV LANG=C.UTF-8 +ENV ACL_BOARD_VENDOR_PATH='/opt/Intel/OpenCLFPGA/oneAPI/Boards' +ENV ADVISOR_2023_DIR='/opt/intel/oneapi/advisor/2023.1.0' +ENV APM='/opt/intel/oneapi/advisor/2023.1.0/perfmodels' +ENV CCL_CONFIGURATION='cpu_gpu_dpcpp' +ENV CCL_ROOT='/opt/intel/oneapi/ccl/2021.9.0' +ENV CLASSPATH='/opt/intel/oneapi/mpi/2021.9.0//lib/mpi.jar:/opt/intel/oneapi/dal/2023.1.0/lib/onedal.jar' +ENV CLCK_ROOT='/opt/intel/oneapi/clck/2021.7.3' +ENV CMAKE_PREFIX_PATH='/opt/intel/oneapi/tbb/2021.9.0/env/..:/opt/intel/oneapi/dnnl/2023.1.0/cpu_dpcpp_gpu_dpcpp/../lib/cmake:/opt/intel/oneapi/dal/2023.1.0:/opt/intel/oneapi/compiler/2023.1.0/linux/IntelDPCPP:/opt/intel/oneapi/ccl/2021.9.0/lib/cmake/oneCCL' +ENV CMPLR_ROOT='/opt/intel/oneapi/compiler/2023.1.0' +ENV CPATH='/opt/intel/oneapi/tbb/2021.9.0/env/../include:/opt/intel/oneapi/mpi/2021.9.0//include:/opt/intel/oneapi/mkl/2023.1.0/include:/opt/intel/oneapi/ippcp/2021.7.0/include:/opt/intel/oneapi/ipp/2021.8.0/include:/opt/intel/oneapi/dpl/2022.1.0/linux/include:/opt/intel/oneapi/dnnl/2023.1.0/cpu_dpcpp_gpu_dpcpp/include:/opt/intel/oneapi/dev-utilities/2021.9.0/include:/opt/intel/oneapi/dal/2023.1.0/include:/opt/intel/oneapi/ccl/2021.9.0/include/cpu_gpu_dpcpp' +ENV CPLUS_INCLUDE_PATH='/opt/intel/oneapi/clck/2021.7.3/include' +ENV DAALROOT='/opt/intel/oneapi/dal/2023.1.0' +ENV DALROOT='/opt/intel/oneapi/dal/2023.1.0' +ENV DAL_MAJOR_BINARY='1' +ENV DAL_MINOR_BINARY='1' +ENV DIAGUTIL_PATH='/opt/intel/oneapi/vtune/2023.1.0/sys_check/vtune_sys_check.py:/opt/intel/oneapi/debugger/2023.1.0/sys_check/debugger_sys_check.py:/opt/intel/oneapi/compiler/2023.1.0/sys_check/sys_check.sh:/opt/intel/oneapi/advisor/2023.1.0/sys_check/advisor_sys_check.py:' +ENV DNNLROOT='/opt/intel/oneapi/dnnl/2023.1.0/cpu_dpcpp_gpu_dpcpp' +ENV DPL_ROOT='/opt/intel/oneapi/dpl/2022.1.0' +ENV FI_PROVIDER_PATH='/opt/intel/oneapi/mpi/2021.9.0//libfabric/lib/prov:/usr/lib64/libfabric' +ENV FPGA_VARS_ARGS='' +ENV FPGA_VARS_DIR='/opt/intel/oneapi/compiler/2023.1.0/linux/lib/oclfpga' +ENV GDB_INFO='/opt/intel/oneapi/debugger/2023.1.0/documentation/info/' +ENV INFOPATH='/opt/intel/oneapi/debugger/2023.1.0/gdb/intel64/lib' +ENV INSPECTOR_2023_DIR='/opt/intel/oneapi/inspector/2023.1.0' +ENV INTELFPGAOCLSDKROOT='/opt/intel/oneapi/compiler/2023.1.0/linux/lib/oclfpga' +ENV INTEL_LICENSE_FILE='/opt/intel/licenses:/root/intel/licenses:/opt/intel/oneapi/clck/2021.7.3/licensing:/opt/intel/licenses:/root/intel/licenses:/Users/Shared/Library/Application Support/Intel/Licenses' +ENV INTEL_PYTHONHOME='/opt/intel/oneapi/debugger/2023.1.0/dep' +ENV IPPCP_TARGET_ARCH='intel64' +ENV IPPCRYPTOROOT='/opt/intel/oneapi/ippcp/2021.7.0' +ENV IPPROOT='/opt/intel/oneapi/ipp/2021.8.0' +ENV IPP_TARGET_ARCH='intel64' +ENV I_MPI_ROOT='/opt/intel/oneapi/mpi/2021.9.0' +ENV LD_LIBRARY_PATH='/opt/intel/oneapi/tbb/2021.9.0/env/../lib/intel64/gcc4.8:/opt/intel/oneapi/mpi/2021.9.0//libfabric/lib:/opt/intel/oneapi/mpi/2021.9.0//lib/release:/opt/intel/oneapi/mpi/2021.9.0//lib:/opt/intel/oneapi/mkl/2023.1.0/lib/intel64:/opt/intel/oneapi/itac/2021.9.0/slib:/opt/intel/oneapi/ippcp/2021.7.0/lib/intel64:/opt/intel/oneapi/ipp/2021.8.0/lib/intel64:/opt/intel/oneapi/dnnl/2023.1.0/cpu_dpcpp_gpu_dpcpp/lib:/opt/intel/oneapi/debugger/2023.1.0/gdb/intel64/lib:/opt/intel/oneapi/debugger/2023.1.0/libipt/intel64/lib:/opt/intel/oneapi/debugger/2023.1.0/dep/lib:/opt/intel/oneapi/dal/2023.1.0/lib/intel64:/opt/intel/oneapi/compiler/2023.1.0/linux/lib:/opt/intel/oneapi/compiler/2023.1.0/linux/lib/x64:/opt/intel/oneapi/compiler/2023.1.0/linux/lib/oclfpga/host/linux64/lib:/opt/intel/oneapi/compiler/2023.1.0/linux/compiler/lib/intel64_lin:/opt/intel/oneapi/ccl/2021.9.0/lib/cpu_gpu_dpcpp' +ENV LIBRARY_PATH='/opt/intel/oneapi/tbb/2021.9.0/env/../lib/intel64/gcc4.8:/opt/intel/oneapi/mpi/2021.9.0//libfabric/lib:/opt/intel/oneapi/mpi/2021.9.0//lib/release:/opt/intel/oneapi/mpi/2021.9.0//lib:/opt/intel/oneapi/mkl/2023.1.0/lib/intel64:/opt/intel/oneapi/ippcp/2021.7.0/lib/intel64:/opt/intel/oneapi/ipp/2021.8.0/lib/intel64:/opt/intel/oneapi/dnnl/2023.1.0/cpu_dpcpp_gpu_dpcpp/lib:/opt/intel/oneapi/dal/2023.1.0/lib/intel64:/opt/intel/oneapi/compiler/2023.1.0/linux/compiler/lib/intel64_lin:/opt/intel/oneapi/compiler/2023.1.0/linux/lib:/opt/intel/oneapi/clck/2021.7.3/lib/intel64:/opt/intel/oneapi/ccl/2021.9.0/lib/cpu_gpu_dpcpp' +ENV MANPATH='/opt/intel/oneapi/mpi/2021.9.0/man:/opt/intel/oneapi/itac/2021.9.0/man:/opt/intel/oneapi/debugger/2023.1.0/documentation/man:/opt/intel/oneapi/compiler/2023.1.0/documentation/en/man/common:/opt/intel/oneapi/clck/2021.7.3/man::' +ENV MKLROOT='/opt/intel/oneapi/mkl/2023.1.0' +ENV NLSPATH='/opt/intel/oneapi/mkl/2023.1.0/lib/intel64/locale/%l_%t/%N:/opt/intel/oneapi/compiler/2023.1.0/linux/compiler/lib/intel64_lin/locale/%l_%t/%N' +ENV OCL_ICD_FILENAMES='libintelocl_emu.so:libalteracl.so:/opt/intel/oneapi/compiler/2023.1.0/linux/lib/x64/libintelocl.so' +ENV ONEAPI_ROOT='/opt/intel/oneapi' +ENV PATH='/opt/intel/oneapi/vtune/2023.1.0/bin64:/opt/intel/oneapi/mpi/2021.9.0//libfabric/bin:/opt/intel/oneapi/mpi/2021.9.0//bin:/opt/intel/oneapi/mkl/2023.1.0/bin/intel64:/opt/intel/oneapi/itac/2021.9.0/bin:/opt/intel/oneapi/inspector/2023.1.0/bin64:/opt/intel/oneapi/dev-utilities/2021.9.0/bin:/opt/intel/oneapi/debugger/2023.1.0/gdb/intel64/bin:/opt/intel/oneapi/compiler/2023.1.0/linux/lib/oclfpga/bin:/opt/intel/oneapi/compiler/2023.1.0/linux/bin/intel64:/opt/intel/oneapi/compiler/2023.1.0/linux/bin:/opt/intel/oneapi/clck/2021.7.3/bin/intel64:/opt/intel/oneapi/advisor/2023.1.0/bin64:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin' +ENV PKG_CONFIG_PATH='/opt/intel/oneapi/vtune/2023.1.0/include/pkgconfig/lib64:/opt/intel/oneapi/tbb/2021.9.0/env/../lib/pkgconfig:/opt/intel/oneapi/mpi/2021.9.0/lib/pkgconfig:/opt/intel/oneapi/mkl/2023.1.0/lib/pkgconfig:/opt/intel/oneapi/ippcp/2021.7.0/lib/pkgconfig:/opt/intel/oneapi/inspector/2023.1.0/include/pkgconfig/lib64:/opt/intel/oneapi/dpl/2022.1.0/lib/pkgconfig:/opt/intel/oneapi/dnnl/2023.1.0/cpu_dpcpp_gpu_dpcpp/../lib/pkgconfig:/opt/intel/oneapi/dal/2023.1.0/lib/pkgconfig:/opt/intel/oneapi/compiler/2023.1.0/lib/pkgconfig:/opt/intel/oneapi/ccl/2021.9.0/lib/pkgconfig:/opt/intel/oneapi/advisor/2023.1.0/include/pkgconfig/lib64:' +ENV PYTHONPATH='/opt/intel/oneapi/advisor/2023.1.0/pythonapi' +ENV SETVARS_COMPLETED='1' +ENV TBBROOT='/opt/intel/oneapi/tbb/2021.9.0/env/..' +ENV VTUNE_PROFILER_2023_DIR='/opt/intel/oneapi/vtune/2023.1.0' +ENV VTUNE_PROFILER_DIR='/opt/intel/oneapi/vtune/2023.1.0' +ENV VT_ADD_LIBS='-ldwarf -lelf -lvtunwind -lm -lpthread' +ENV VT_LIB_DIR='/opt/intel/oneapi/itac/2021.9.0/lib' +ENV VT_MPI='impi4' +ENV VT_ROOT='/opt/intel/oneapi/itac/2021.9.0' +ENV VT_SLIB_DIR='/opt/intel/oneapi/itac/2021.9.0/slib' + +RUN cd swiftest && cmake -P distclean.cmake && mkdir build && cd build && cmake .. -DCMAKE_PREFIX_PATH="${INDIR}" -DCMAKE_INSTALL_PREFIX="${INDIR}" -DCMAKE_BUILD_TYPE=release && make && make install #Production container FROM debian:stable-slim @@ -62,6 +115,8 @@ RUN curl -fsSL https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-P RUN deb [trusted=yes] https://apt.repos.intel.com/oneapi all main " > /etc/apt/sources.list.d/oneAPI.list RUN apt-get -y update && apt-get upgrade -y RUN apt-get install -y intel-oneapi-runtime-openmp intel-oneapi-runtime-mkl intel-oneapi-runtime-mpi intel-oneapi-runtime-fortran -RUN . /opt/intel/oneapi/setvars.sh +ENV NETCDF_HOME="/usr/local" +ENV LANG=C.UTF-8 +ENV LD_LIBRARY_PATH=/opt/intel/oneapi/lib ENTRYPOINT ["/usr/bin/swiftest_driver"] \ No newline at end of file From eb1eb50fc9e6d04040a125bae95dc77129288905 Mon Sep 17 00:00:00 2001 From: David Minton Date: Tue, 23 May 2023 08:55:23 -0400 Subject: [PATCH 27/95] Fixed missing packages in final stage --- Dockerfile | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Dockerfile b/Dockerfile index a6572206b..9d4e8580e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -111,6 +111,11 @@ FROM debian:stable-slim COPY --from=build /opt/dist / # Get the Intel runtime libraries +RUN apt-get update && apt-get upgrade -y && \ + DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + ca-certificates curl gpg-agent software-properties-common gnupg pkg-config procps && \ + rm -rf /var/lib/apt/lists/* + RUN curl -fsSL https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS-2023.PUB | apt-key add - RUN deb [trusted=yes] https://apt.repos.intel.com/oneapi all main " > /etc/apt/sources.list.d/oneAPI.list RUN apt-get -y update && apt-get upgrade -y From 3dc18fe66ce2f6589e12179971b02e9d9ccb37b9 Mon Sep 17 00:00:00 2001 From: David Minton Date: Tue, 23 May 2023 10:28:42 -0400 Subject: [PATCH 28/95] Fixed typo --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 9d4e8580e..eaef8474d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -117,7 +117,7 @@ RUN apt-get update && apt-get upgrade -y && \ rm -rf /var/lib/apt/lists/* RUN curl -fsSL https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS-2023.PUB | apt-key add - -RUN deb [trusted=yes] https://apt.repos.intel.com/oneapi all main " > /etc/apt/sources.list.d/oneAPI.list +RUN echo "deb [trusted=yes] https://apt.repos.intel.com/oneapi all main " > /etc/apt/sources.list.d/oneAPI.list RUN apt-get -y update && apt-get upgrade -y RUN apt-get install -y intel-oneapi-runtime-openmp intel-oneapi-runtime-mkl intel-oneapi-runtime-mpi intel-oneapi-runtime-fortran ENV NETCDF_HOME="/usr/local" From 3d8696b6e786b61c02ff54b99a71d51d093cfd5b Mon Sep 17 00:00:00 2001 From: David Minton Date: Tue, 23 May 2023 10:37:41 -0400 Subject: [PATCH 29/95] Added missing dependencies to Dockerfile --- Dockerfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index eaef8474d..ff24e3659 100644 --- a/Dockerfile +++ b/Dockerfile @@ -123,5 +123,7 @@ RUN apt-get install -y intel-oneapi-runtime-openmp intel-oneapi-runtime-mkl inte ENV NETCDF_HOME="/usr/local" ENV LANG=C.UTF-8 ENV LD_LIBRARY_PATH=/opt/intel/oneapi/lib +RUN apt-get -y update && apt-get upgrade -y +RUN apt-get install -y libhdf5-dev libxml2-dev -ENTRYPOINT ["/usr/bin/swiftest_driver"] \ No newline at end of file +ENTRYPOINT ["/usr/local/bin/swiftest_driver"] \ No newline at end of file From 7aa1c81678e7abb76fc781b112b61f70f6ef4be3 Mon Sep 17 00:00:00 2001 From: David Minton Date: Tue, 23 May 2023 11:09:50 -0400 Subject: [PATCH 30/95] Fixed typo in singularity definition file --- swiftest.def | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/swiftest.def b/swiftest.def index 9eeb9d3ef..ce6c10f63 100644 --- a/swiftest.def +++ b/swiftest.def @@ -1,2 +1,2 @@ Bootstrap: docker -From: daminton:swiftest:latest \ No newline at end of file +From: daminton/swiftest:latest \ No newline at end of file From 9ada3e715d62746cd6b2dd21f234142d95d15c36 Mon Sep 17 00:00:00 2001 From: David Minton Date: Tue, 23 May 2023 12:16:39 -0400 Subject: [PATCH 31/95] Adjusted flags to attempt to get cross compiling working with enough vector instructions --- Dockerfile | 2 +- cmake/Modules/SetFortranFlags.cmake | 11 ++--------- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index ff24e3659..f1532b7c3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -122,7 +122,7 @@ RUN apt-get -y update && apt-get upgrade -y RUN apt-get install -y intel-oneapi-runtime-openmp intel-oneapi-runtime-mkl intel-oneapi-runtime-mpi intel-oneapi-runtime-fortran ENV NETCDF_HOME="/usr/local" ENV LANG=C.UTF-8 -ENV LD_LIBRARY_PATH=/opt/intel/oneapi/lib +ENV LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/opt/intel/oneapi/lib" RUN apt-get -y update && apt-get upgrade -y RUN apt-get install -y libhdf5-dev libxml2-dev diff --git a/cmake/Modules/SetFortranFlags.cmake b/cmake/Modules/SetFortranFlags.cmake index ecf9c34e1..5f0c94bf5 100644 --- a/cmake/Modules/SetFortranFlags.cmake +++ b/cmake/Modules/SetFortranFlags.cmake @@ -112,9 +112,9 @@ SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}" # There is some bug where -march=native doesn't work on Mac IF(APPLE) - SET(GNUNATIVE "-mtune=native") + SET(GNUNATIVE "-mtune=CORE-AVX2 -xCORE-AVX2") ELSE() - SET(GNUNATIVE "-march=native") + SET(GNUNATIVE "-march=CORE-AVX2 -axCORE-AVX2") ENDIF() ################### @@ -350,13 +350,6 @@ IF (USE_SIMD) ) ENDIF (NOT USE_OPENMP) - # Optimize for the host's architecture - SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}" - Fortran "-xhost" # Intel - "/QxHost" # Intel Windows - ${GNUNATIVE} # GNU - ) - # Generate an extended set of vector functions SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}" Fortran "-vecabi=cmdtarget" # Intel From ffb8f308f5857d8283386837e4dbf65ecba7b3cf Mon Sep 17 00:00:00 2001 From: David Minton Date: Tue, 23 May 2023 14:20:52 -0400 Subject: [PATCH 32/95] Updated structure of project to better handle containerization, including a new cmake option to build with a lower level of vector support --- .gitignore | 2 + CMakeLists.txt | 1 + cmake/Modules/SetFortranFlags.cmake | 93 ++++++++++++++++-------- docker/.gitignore | 2 + Dockerfile => docker/Dockerfile | 0 docker/bin/.gitignore | 1 + docker/bin/swiftest_driver | 2 + singularity/.gitignore | 2 + singularity/bin/.gitignore | 1 + singularity/bin/swiftest_driver | 2 + swiftest.def => singularity/swiftest.def | 0 11 files changed, 75 insertions(+), 31 deletions(-) create mode 100644 docker/.gitignore rename Dockerfile => docker/Dockerfile (100%) create mode 100644 docker/bin/.gitignore create mode 100755 docker/bin/swiftest_driver create mode 100644 singularity/.gitignore create mode 100644 singularity/bin/.gitignore create mode 100755 singularity/bin/swiftest_driver rename swiftest.def => singularity/swiftest.def (100%) diff --git a/.gitignore b/.gitignore index 81a7fb376..e5c25df47 100644 --- a/.gitignore +++ b/.gitignore @@ -31,6 +31,8 @@ dump* !README_figs/* #Docker and Singularity files +!docker/ +!singularity/ !Dockerfile !swiftest.def diff --git a/CMakeLists.txt b/CMakeLists.txt index a047c0163..37cda5709 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/cmake/Modules/SetFortranFlags.cmake b/cmake/Modules/SetFortranFlags.cmake index 5f0c94bf5..782fdc808 100644 --- a/cmake/Modules/SetFortranFlags.cmake +++ b/cmake/Modules/SetFortranFlags.cmake @@ -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. @@ -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 ### @@ -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) \ No newline at end of file diff --git a/docker/.gitignore b/docker/.gitignore new file mode 100644 index 000000000..a50979646 --- /dev/null +++ b/docker/.gitignore @@ -0,0 +1,2 @@ +!Dockerfile +!bin/ diff --git a/Dockerfile b/docker/Dockerfile similarity index 100% rename from Dockerfile rename to docker/Dockerfile diff --git a/docker/bin/.gitignore b/docker/bin/.gitignore new file mode 100644 index 000000000..c1d7ed39d --- /dev/null +++ b/docker/bin/.gitignore @@ -0,0 +1 @@ +!swiftest_driver diff --git a/docker/bin/swiftest_driver b/docker/bin/swiftest_driver new file mode 100755 index 000000000..0553553a7 --- /dev/null +++ b/docker/bin/swiftest_driver @@ -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} diff --git a/singularity/.gitignore b/singularity/.gitignore new file mode 100644 index 000000000..c15d31235 --- /dev/null +++ b/singularity/.gitignore @@ -0,0 +1,2 @@ +!swiftest.def +!bin/ diff --git a/singularity/bin/.gitignore b/singularity/bin/.gitignore new file mode 100644 index 000000000..c1d7ed39d --- /dev/null +++ b/singularity/bin/.gitignore @@ -0,0 +1 @@ +!swiftest_driver diff --git a/singularity/bin/swiftest_driver b/singularity/bin/swiftest_driver new file mode 100755 index 000000000..45765b4a7 --- /dev/null +++ b/singularity/bin/swiftest_driver @@ -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 \ No newline at end of file diff --git a/swiftest.def b/singularity/swiftest.def similarity index 100% rename from swiftest.def rename to singularity/swiftest.def From 05aa725802cd37b31305c1afae3636b3cdb40277 Mon Sep 17 00:00:00 2001 From: David Minton Date: Tue, 23 May 2023 16:55:43 -0400 Subject: [PATCH 33/95] Added ability to control whether to use the containerized executable or not via the Python code --- cmake/Modules/SetFortranFlags.cmake | 2 +- docker/Dockerfile | 2 +- docker/bin/swiftest_driver | 2 +- python/swiftest/swiftest/simulation_class.py | 38 ++++++++++++++++---- singularity/bin/swiftest_driver | 2 +- singularity/setenv.sh | 3 ++ 6 files changed, 39 insertions(+), 10 deletions(-) create mode 100644 singularity/setenv.sh diff --git a/cmake/Modules/SetFortranFlags.cmake b/cmake/Modules/SetFortranFlags.cmake index 782fdc808..ead3e1433 100644 --- a/cmake/Modules/SetFortranFlags.cmake +++ b/cmake/Modules/SetFortranFlags.cmake @@ -130,7 +130,7 @@ IF (USE_SIMD) "/QxSANDYBRIDGE" # Intel Windows ${GNUNATIVE} # GNU ) - ELSE + ELSE () # Optimize for the host's architecture SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}" Fortran "-xhost" # Intel diff --git a/docker/Dockerfile b/docker/Dockerfile index f1532b7c3..c6d728b2d 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -104,7 +104,7 @@ ENV VT_MPI='impi4' ENV VT_ROOT='/opt/intel/oneapi/itac/2021.9.0' ENV VT_SLIB_DIR='/opt/intel/oneapi/itac/2021.9.0/slib' -RUN cd swiftest && cmake -P distclean.cmake && mkdir build && cd build && cmake .. -DCMAKE_PREFIX_PATH="${INDIR}" -DCMAKE_INSTALL_PREFIX="${INDIR}" -DCMAKE_BUILD_TYPE=release && make && make install +RUN cd swiftest && cmake -P distclean.cmake && mkdir build && cd build && cmake .. -DCMAKE_PREFIX_PATH="${INDIR}" -DCMAKE_INSTALL_PREFIX="${INDIR}" -DCONTAINERIZE=ON -DCMAKE_BUILD_TYPE=release && make && make install #Production container FROM debian:stable-slim diff --git a/docker/bin/swiftest_driver b/docker/bin/swiftest_driver index 0553553a7..d2cb42a90 100755 --- a/docker/bin/swiftest_driver +++ b/docker/bin/swiftest_driver @@ -1,2 +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} +docker run -v $(pwd):$(pwd) -w $(pwd) -t -e OMP_NUM_THREADS -e FOR_COARRAY_NUM_IMAGES swiftest:latest "$@" diff --git a/python/swiftest/swiftest/simulation_class.py b/python/swiftest/swiftest/simulation_class.py index 804eee651..0ae7f540b 100644 --- a/python/swiftest/swiftest/simulation_class.py +++ b/python/swiftest/swiftest/simulation_class.py @@ -91,6 +91,8 @@ def __init__(self,read_param: bool = False, integrator : {"symba","rmvs","whm","helio"}, default "symba" Name of the n-body integrator that will be used when executing a run. Parameter input file equivalent: None + container : {"docker", "singularity"}, default None + Specify whether the driver exectuable is run from a Docker or Singularity container. Setting to `None` read_param : bool, default False Read the parameter file given by `param_file`. param_file : str, path-like, or file-lke, default "param.in" @@ -338,6 +340,7 @@ def __init__(self,read_param: bool = False, self.init_cond = xr.Dataset() self.encounters = xr.Dataset() self.collisions = xr.Dataset() + self.container = None # Set the location of the parameter input file, choosing the default if it isn't specified. self.simdir = Path.cwd() / Path(simdir) @@ -404,9 +407,11 @@ def _run_swiftest_driver(self): """ # Get current environment variables - env = os.environ.copy() + if self.container == "SINGULARITY" and "SWIFTEST_SIF" not in env: + env['SWIFTEST_SIF'] = Path(self.binary_source).parent.parent / "swiftest.sif" cmd = f"{env['SHELL']} -l {self.driver_script}" + def _type_scrub(output_data): int_vars = ["ILOOP","NPL","NTP","NPLM"] @@ -829,7 +834,8 @@ def set_parameter(self, verbose: bool = True, **kwargs): "restart": False, "encounter_save" : "NONE", "coarray" : False, - "simdir" : self.simdir + "simdir" : self.simdir, + "container" : None, } param_file = kwargs.pop("param_file",None) @@ -891,8 +897,9 @@ def get_parameter(self, **kwargs): return param_dict def set_integrator(self, - codename: Literal["Swiftest", "Swifter", "Swift"] | None = None, + codename: None | Literal["Swiftest", "Swifter", "Swift"] = "Swiftest", integrator: Literal["symba","rmvs","whm","helio"] | None = None, + container: Literal["docker", "singularity"] | None = None, mtiny: float | None = None, gmtiny: float | None = None, verbose: bool | None = None, @@ -905,6 +912,10 @@ def set_integrator(self, codename : {"swiftest", "swifter", "swift"}, optional integrator : {"symba","rmvs","whm","helio"}, optional Name of the n-body integrator that will be used when executing a run. + container : {"docker", "singularity"}, default None + Specify whether the driver exectuable is run from a Docker or Singularity container. + Setting to `None` uses the local executable. + *Note*: Only valid for Swiftest. mtiny : float, optional The minimum mass of fully interacting bodies. Bodies below this mass interact with the larger bodies, but not each other (SyMBA only). *Note.* Only mtiny or gmtiny is accepted, not both. @@ -926,7 +937,15 @@ def set_integrator(self, # TODO: Improve how it finds the executable binary update_list = [] - + + if container is not None: + valid_container = ["DOCKER", "SINGULARITY"] + if container.upper() not in valid_container: + warnings.warn(f"{container} is not a valid container type. Valid options are None, ",",".join(valid_container),stacklevel=2) + self.container = None + else: + self.container = container.upper() + if codename is not None: valid_codename = ["Swiftest", "Swifter", "Swift"] if codename.title() not in valid_codename: @@ -941,7 +960,13 @@ def set_integrator(self, self.param['! VERSION'] = f"{self.codename} input file" update_list.append("codename") if self.codename == "Swiftest": - self.binary_source = Path(_pyfile).parent.parent.parent.parent / "bin" / "swiftest_driver" + if self.container is None: + self.binary_source = Path(_pyfile).parent.parent.parent.parent / "bin" / "swiftest_driver" + elif self.container == "DOCKER": + self.binary_source = Path(_pyfile).parent.parent.parent.parent / "docker" / "bin" / "swiftest_driver" + elif self.container == "SINGULARITY": + self.binary_source = Path(_pyfile).parent.parent.parent.parent / "singularity" / "bin" / "swiftest_driver" + self.binary_path = self.simdir.resolve() self.driver_executable = self.binary_path / "swiftest_driver" if not self.binary_source.exists(): @@ -1016,7 +1041,8 @@ def get_integrator(self,arg_list: str | List[str] | None = None, verbose: bool | valid_instance_vars = {"codename": self.codename, "integrator": self.integrator, "param_file": str(self.param_file), - "driver_executable": str(self.driver_executable)} + "driver_executable": str(self.driver_executable), + "container": self.container} try: self.integrator diff --git a/singularity/bin/swiftest_driver b/singularity/bin/swiftest_driver index 45765b4a7..dba0863a9 100755 --- a/singularity/bin/swiftest_driver +++ b/singularity/bin/swiftest_driver @@ -1,2 +1,2 @@ #!/bin/sh -- -docker run -v $(pwd):$(pwd) -w $(pwd) -t -e OMP_NUM_THREADS -e FOR_COARRAY_NUM_IMAGES swiftest:latest \ No newline at end of file +singularity run --bind $(pwd):$(pwd) --env OMP_NUM_THREADS=${OMP_NUM_THREADS},FOR_COARRAY_NUM_IMAGES=${FOR_COARRAY_NUM_IMAGES} ${SWIFTEST_SIF} "$@" \ No newline at end of file diff --git a/singularity/setenv.sh b/singularity/setenv.sh new file mode 100644 index 000000000..769339754 --- /dev/null +++ b/singularity/setenv.sh @@ -0,0 +1,3 @@ +#!/bin/sh +# source this file to set the path to the swiftest.sif file +export SWIFTEST_SIF=${PWD} \ No newline at end of file From f8265e231c8640397359fae5f8770955ab2c116b Mon Sep 17 00:00:00 2001 From: David Minton Date: Tue, 23 May 2023 17:14:22 -0400 Subject: [PATCH 34/95] Adjusted flags to allow the containerized version to work on more CPUs --- cmake/Modules/SetFortranFlags.cmake | 35 ++++++++++++++--------------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/cmake/Modules/SetFortranFlags.cmake b/cmake/Modules/SetFortranFlags.cmake index ead3e1433..ce7f3149b 100644 --- a/cmake/Modules/SetFortranFlags.cmake +++ b/cmake/Modules/SetFortranFlags.cmake @@ -110,7 +110,23 @@ SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}" SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}" Fortran "-pad" # Intel "/Qpad" # Intel Windows + ) +IF (CONTAINERIZE) + # There is some bug where -march=native doesn't work on Mac + IF(APPLE) + SET(GNUNATIVE "-mtune=generic") + ELSE() + SET(GNUNATIVE "-march=generic") + 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) @@ -126,9 +142,7 @@ IF (USE_SIMD) 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 + Fortran ${GNUNATIVE} # GNU ) ELSE () # Optimize for the host's architecture @@ -146,21 +160,6 @@ IF (USE_SIMD) ) 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) From 6ce8e38d0732009ffa2e733928f7f4a40f18648f Mon Sep 17 00:00:00 2001 From: David Minton Date: Tue, 23 May 2023 17:56:35 -0400 Subject: [PATCH 35/95] Created docker pull script --- examples/Basic_Simulation/initial_conditions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/Basic_Simulation/initial_conditions.py b/examples/Basic_Simulation/initial_conditions.py index 1e7cd5cd6..462063a89 100755 --- a/examples/Basic_Simulation/initial_conditions.py +++ b/examples/Basic_Simulation/initial_conditions.py @@ -37,7 +37,7 @@ # Initialize the simulation object as a variable. Arguments may be defined here or through the sim.run() method. #sim = swiftest.Simulation(fragmentation=True, minimum_fragment_mass = 2.5e-11, mtiny=2.5e-8) -sim = swiftest.Simulation() +sim = swiftest.Simulation(container="docker") sim.clean() # Add the modern planets and the Sun using the JPL Horizons Database. From 11cd4b638992850fd2c58fae9b050d96a0f5522c Mon Sep 17 00:00:00 2001 From: David Minton Date: Tue, 23 May 2023 17:57:25 -0400 Subject: [PATCH 36/95] Actually put the pull script up this time. --- docker/.gitignore | 1 + docker/pull | 2 ++ examples/Basic_Simulation/initial_conditions.py | 2 +- 3 files changed, 4 insertions(+), 1 deletion(-) create mode 100755 docker/pull diff --git a/docker/.gitignore b/docker/.gitignore index a50979646..825a38873 100644 --- a/docker/.gitignore +++ b/docker/.gitignore @@ -1,2 +1,3 @@ !Dockerfile !bin/ +!pull diff --git a/docker/pull b/docker/pull new file mode 100755 index 000000000..2367ba639 --- /dev/null +++ b/docker/pull @@ -0,0 +1,2 @@ +#!/bin/sh -- +docker pull daminton/swiftest:latest \ No newline at end of file diff --git a/examples/Basic_Simulation/initial_conditions.py b/examples/Basic_Simulation/initial_conditions.py index 462063a89..1e7cd5cd6 100755 --- a/examples/Basic_Simulation/initial_conditions.py +++ b/examples/Basic_Simulation/initial_conditions.py @@ -37,7 +37,7 @@ # Initialize the simulation object as a variable. Arguments may be defined here or through the sim.run() method. #sim = swiftest.Simulation(fragmentation=True, minimum_fragment_mass = 2.5e-11, mtiny=2.5e-8) -sim = swiftest.Simulation(container="docker") +sim = swiftest.Simulation() sim.clean() # Add the modern planets and the Sun using the JPL Horizons Database. From 76455226084e07bc7f821ecddc213953b2d955ab Mon Sep 17 00:00:00 2001 From: David Minton Date: Tue, 23 May 2023 20:20:28 -0400 Subject: [PATCH 37/95] Added the pull script to the .gitignore --- singularity/.gitignore | 1 + singularity/pull | 3 +++ 2 files changed, 4 insertions(+) create mode 100755 singularity/pull diff --git a/singularity/.gitignore b/singularity/.gitignore index c15d31235..abc0e7f03 100644 --- a/singularity/.gitignore +++ b/singularity/.gitignore @@ -1,2 +1,3 @@ !swiftest.def !bin/ +!pull diff --git a/singularity/pull b/singularity/pull new file mode 100755 index 000000000..8946e4869 --- /dev/null +++ b/singularity/pull @@ -0,0 +1,3 @@ +#!/bin/sh -- +singularity pull swiftest.sif docker://daminton/swiftest:latest +source ./setenv.sh \ No newline at end of file From 571b4a2ffbf531ca88b6028cd8ec629de591c21c Mon Sep 17 00:00:00 2001 From: David Minton Date: Wed, 24 May 2023 13:13:20 -0400 Subject: [PATCH 38/95] Fixed issue in the environment variable setter, as it was only pointing to the directory and not the swiftest.sif file itself --- singularity/pull | 3 +-- singularity/setenv.sh | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) mode change 100644 => 100755 singularity/setenv.sh diff --git a/singularity/pull b/singularity/pull index 8946e4869..a62acaf6e 100755 --- a/singularity/pull +++ b/singularity/pull @@ -1,3 +1,2 @@ #!/bin/sh -- -singularity pull swiftest.sif docker://daminton/swiftest:latest -source ./setenv.sh \ No newline at end of file +singularity pull --force swiftest.sif docker://daminton/swiftest:latest diff --git a/singularity/setenv.sh b/singularity/setenv.sh old mode 100644 new mode 100755 index 769339754..79931a298 --- a/singularity/setenv.sh +++ b/singularity/setenv.sh @@ -1,3 +1,3 @@ #!/bin/sh # source this file to set the path to the swiftest.sif file -export SWIFTEST_SIF=${PWD} \ No newline at end of file +export SWIFTEST_SIF="${PWD}/swiftest.sif" From 0605144509a074209d833721bddfb5b0f5b1d505 Mon Sep 17 00:00:00 2001 From: David Minton Date: Wed, 24 May 2023 16:41:05 -0400 Subject: [PATCH 39/95] Moved swiftest_particle_info further up in the code before it is used in the swiftest_body type definition. --- src/swiftest/swiftest_module.f90 | 38 ++++++++++++++++---------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/swiftest/swiftest_module.f90 b/src/swiftest/swiftest_module.f90 index e3664a9ed..3d35749ee 100644 --- a/src/swiftest/swiftest_module.f90 +++ b/src/swiftest/swiftest_module.f90 @@ -97,6 +97,25 @@ module swiftest end type swiftest_kinship + type, extends(base_particle_info) :: swiftest_particle_info + character(len=NAMELEN) :: name !! Non-unique name + character(len=NAMELEN) :: particle_type !! String containing a description of the particle type (e.g. Central Body, Massive Body, Test Particle) + character(len=NAMELEN) :: origin_type !! String containing a description of the origin of the particle (e.g. Initial Conditions, Supercatastrophic, Disruption, etc.) + real(DP) :: origin_time !! The time of the particle's formation + integer(I4B) :: collision_id !! The ID of the collision that formed the particle + real(DP), dimension(NDIM) :: origin_rh !! The heliocentric distance vector at the time of the particle's formation + real(DP), dimension(NDIM) :: origin_vh !! The heliocentric velocity vector at the time of the particle's formation + real(DP) :: discard_time !! The time of the particle's discard + character(len=NAMELEN) :: status !! Particle status description: Active, Merged, Fragmented, etc. + real(DP), dimension(NDIM) :: discard_rh !! The heliocentric distance vector at the time of the particle's discard + real(DP), dimension(NDIM) :: discard_vh !! The heliocentric velocity vector at the time of the particle's discard + integer(I4B) :: discard_body_id !! The id of the other body involved in the discard (0 if no other body involved) + contains + procedure :: copy => swiftest_util_copy_particle_info !! Copies one set of information object components into another, component-by-component + procedure :: set_value => swiftest_util_set_particle_info !! Sets one or more values of the particle information metadata object + end type swiftest_particle_info + + !> An abstract class for a generic collection of Swiftest bodies type, abstract, extends(base_object) :: swiftest_body !! Superclass that defines the generic elements of a Swiftest particle @@ -167,25 +186,6 @@ module swiftest end type swiftest_body - type, extends(base_particle_info) :: swiftest_particle_info - character(len=NAMELEN) :: name !! Non-unique name - character(len=NAMELEN) :: particle_type !! String containing a description of the particle type (e.g. Central Body, Massive Body, Test Particle) - character(len=NAMELEN) :: origin_type !! String containing a description of the origin of the particle (e.g. Initial Conditions, Supercatastrophic, Disruption, etc.) - real(DP) :: origin_time !! The time of the particle's formation - integer(I4B) :: collision_id !! The ID of the collision that formed the particle - real(DP), dimension(NDIM) :: origin_rh !! The heliocentric distance vector at the time of the particle's formation - real(DP), dimension(NDIM) :: origin_vh !! The heliocentric velocity vector at the time of the particle's formation - real(DP) :: discard_time !! The time of the particle's discard - character(len=NAMELEN) :: status !! Particle status description: Active, Merged, Fragmented, etc. - real(DP), dimension(NDIM) :: discard_rh !! The heliocentric distance vector at the time of the particle's discard - real(DP), dimension(NDIM) :: discard_vh !! The heliocentric velocity vector at the time of the particle's discard - integer(I4B) :: discard_body_id !! The id of the other body involved in the discard (0 if no other body involved) - contains - procedure :: copy => swiftest_util_copy_particle_info !! Copies one set of information object components into another, component-by-component - procedure :: set_value => swiftest_util_set_particle_info !! Sets one or more values of the particle information metadata object - end type swiftest_particle_info - - type, abstract, extends(base_object) :: swiftest_cb !> An abstract class for a generic central body in a Swiftest simulation class(swiftest_particle_info), allocatable :: info !! Particle metadata information From 5245e2ba30ccaf48a1f001a8169bf4ed6356b02f Mon Sep 17 00:00:00 2001 From: David A Minton Date: Wed, 24 May 2023 17:23:59 -0400 Subject: [PATCH 40/95] Use more robust way to check for valid bodies in a NetCDF file with the ieee_arithetic intrinsic module --- src/swiftest/swiftest_io.f90 | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/swiftest/swiftest_io.f90 b/src/swiftest/swiftest_io.f90 index 1e02a7645..c3061858b 100644 --- a/src/swiftest/swiftest_io.f90 +++ b/src/swiftest/swiftest_io.f90 @@ -1035,6 +1035,8 @@ module subroutine swiftest_io_netcdf_get_valid_masks(self, plmask, tpmask) !! !! Given an open NetCDF, returns logical masks indicating which bodies in the body arrays are active pl and tp type at the current time. !! Uses the value of tslot stored in the NetCDF parameter object as the definition of current time + use, intrinsic :: ieee_exceptions + use, intrinsic :: ieee_arithmetic implicit none ! Arguments class(swiftest_netcdf_parameters), intent(inout) :: self !! Parameters used to identify a particular NetCDF dataset @@ -1045,7 +1047,11 @@ module subroutine swiftest_io_netcdf_get_valid_masks(self, plmask, tpmask) real(DP), dimension(:,:), allocatable :: rh integer(I4B), dimension(:), allocatable :: body_status logical, dimension(:), allocatable :: lvalid - integer(I4B) :: idmax, status + integer(I4B) :: idmax, status, i + logical, dimension(size(IEEE_ALL)) :: fpe_halting_modes + + call ieee_get_halting_mode(IEEE_ALL,fpe_halting_modes) ! Save the current halting modes so we can turn them off temporarily + call ieee_set_halting_mode(IEEE_ALL,.false.) call netcdf_io_check( nf90_inquire_dimension(self%id, self%name_dimid, len=idmax), "swiftest_io_netcdf_get_valid_masks nf90_inquire_dimension name_dimid" ) @@ -1067,20 +1073,20 @@ module subroutine swiftest_io_netcdf_get_valid_masks(self, plmask, tpmask) if (status == NF90_NOERR) then allocate(rh(NDIM,idmax)) call netcdf_io_check( nf90_get_var(self%id, self%rh_varid, rh, start=[1, 1, tslot], count=[NDIM,idmax,1]), "swiftest_io_netcdf_get_valid_masks nf90_getvar rh_varid" ) - lvalid(:) = rh(1,:) == rh(1,:) + lvalid(:) = ieee_is_normal(rh(1,:)) else status = nf90_inq_varid(self%id, self%a_varname, self%a_varid) if (status == NF90_NOERR) then allocate(a(idmax)) call netcdf_io_check( nf90_get_var(self%id, self%a_varid, a, start=[1, tslot], count=[idmax,1]), "swiftest_io_netcdf_get_valid_masks nf90_getvar a_varid" ) - lvalid(:) = a(:) == a(:) + lvalid(:) = ieee_is_normal(a(:)) else lvalid(:) = .false. end if end if end if - plmask(:) = (Gmass(:) == Gmass(:)) + plmask(:) = ieee_is_normal(Gmass(:)) where(plmask(:)) plmask(:) = Gmass(:) > 0.0_DP tpmask(:) = .not. plmask(:) plmask(1) = .false. ! This is the central body @@ -1088,6 +1094,7 @@ module subroutine swiftest_io_netcdf_get_valid_masks(self, plmask, tpmask) ! Select only active bodies plmask(:) = plmask(:) .and. lvalid(:) tpmask(:) = tpmask(:) .and. lvalid(:) + call ieee_set_halting_mode(IEEE_ALL,fpe_halting_modes) end associate From e10f09ec03a456eafd6ed2512f0fa227717437e0 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Wed, 24 May 2023 19:50:49 -0400 Subject: [PATCH 41/95] Fixed up the floating point flags for gfortran --- cmake/Modules/SetFortranFlags.cmake | 12 ++++++++++++ src/CMakeLists.txt | 6 +++--- src/swiftest/swiftest_io.f90 | 2 +- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/cmake/Modules/SetFortranFlags.cmake b/cmake/Modules/SetFortranFlags.cmake index ce7f3149b..0d06920de 100644 --- a/cmake/Modules/SetFortranFlags.cmake +++ b/cmake/Modules/SetFortranFlags.cmake @@ -75,6 +75,12 @@ SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}" SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}" Fortran "-fno-underscoring" # GNU ) +# Compile code assuming that IEEE signaling NaNs may generate user-visible traps during floating-point operations. +# Setting this option disables optimizations that may change the number of exceptions visible with signaling NaNs. +SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}" + Fortran "-fsignaling-nans " # GNU + ) + # Determines whether the current Fortran Standard behavior of the compiler is fully implemented. SET_COMPILE_FLAG(CMAKE_Fortran_Flags "${CMAKE_Fortran_FLAGS}" @@ -208,6 +214,7 @@ SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" Fortran "-init=snan,arrays" # Intel "/Qinit:snan,arrays" # Intel Windows + "-finit-real=snan" # GNU ) # Does not generate an interface block for each routine in a source file @@ -342,6 +349,11 @@ SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE}" SET_COMPILE_FLAG(STRICTMATH_FLAGS "${STRICTMATH_FLAGS}" Fortran "-fp-model=precise" # Intel "/fp:precise" # Intel Windows + "-fno-unsafe-math-optimizations" # GNU + ) +# Disable transformations and optimizations that assume default floating-point rounding behavior. +SET_COMPILE_FLAG(STRICTMATH_FLAGS "${STRICTMATH_FLAGS}" + Fortran "-frounding-math" ) SET_COMPILE_FLAG(STRICTMATH_FLAGS "${STRICTMATH_FLAGS}" diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ef23fadc8..e241d3360 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -14,6 +14,8 @@ # Add the source files SET(STRICT_MATH_FILES ${SRC}/collision/collision_generate.f90 + ${SRC}/collision/collision_io.f90 + ${SRC}/collision/collision_util.f90 ${SRC}/fraggle/fraggle_generate.f90 ${SRC}/fraggle/fraggle_util.f90 ${SRC}/fraggle/fraggle_module.f90 @@ -31,6 +33,7 @@ SET(STRICT_MATH_FILES ${SRC}/rmvs/rmvs_step.f90 ${SRC}/swiftest/swiftest_drift.f90 ${SRC}/swiftest/swiftest_gr.f90 + ${SRC}/swiftest/swiftest_io.f90 ${SRC}/swiftest/swiftest_kick.f90 ${SRC}/swiftest/swiftest_user.f90 ${SRC}/swiftest/swiftest_obl.f90 @@ -60,10 +63,8 @@ SET(FAST_MATH_FILES ${SRC}/helio/helio_module.f90 ${SRC}/symba/symba_module.f90 ${SRC}/collision/collision_check.f90 - ${SRC}/collision/collision_io.f90 ${SRC}/collision/collision_regime.f90 ${SRC}/collision/collision_resolve.f90 - ${SRC}/collision/collision_util.f90 ${SRC}/encounter/encounter_check.f90 ${SRC}/encounter/encounter_io.f90 ${SRC}/encounter/encounter_util.f90 @@ -73,7 +74,6 @@ SET(FAST_MATH_FILES ${SRC}/rmvs/rmvs_encounter_check.f90 ${SRC}/rmvs/rmvs_util.f90 ${SRC}/swiftest/swiftest_discard.f90 - ${SRC}/swiftest/swiftest_io.f90 ${SRC}/swiftest/swiftest_util.f90 ${SRC}/symba/symba_discard.f90 ${SRC}/symba/symba_encounter_check.f90 diff --git a/src/swiftest/swiftest_io.f90 b/src/swiftest/swiftest_io.f90 index c3061858b..921ea8308 100644 --- a/src/swiftest/swiftest_io.f90 +++ b/src/swiftest/swiftest_io.f90 @@ -1067,7 +1067,7 @@ module subroutine swiftest_io_netcdf_get_valid_masks(self, plmask, tpmask) if (status == NF90_NOERR) then allocate(body_status(idmax)) call netcdf_io_check( nf90_get_var(self%id, self%status_varid, body_status, start=[1, tslot], count=[idmax,1]), "swiftest_io_netcdf_get_valid_masks nf90_getvar status_varid" ) - lvalid(:) = body_status /= INACTIVE + lvalid(:) = body_status(:) /= INACTIVE else status = nf90_inq_varid(self%id, self%rh_varname, self%rh_varid) if (status == NF90_NOERR) then From 660eb485bbb4baf0d9774ed2ea73e5b11c27070a Mon Sep 17 00:00:00 2001 From: David A Minton Date: Thu, 25 May 2023 11:31:48 -0400 Subject: [PATCH 42/95] Improved the way that semi-interacting bodies are identified from input --- .../Basic_Simulation/initial_conditions.py | 10 +-- src/swiftest/swiftest_io.f90 | 80 ++++++++----------- 2 files changed, 39 insertions(+), 51 deletions(-) diff --git a/examples/Basic_Simulation/initial_conditions.py b/examples/Basic_Simulation/initial_conditions.py index 1e7cd5cd6..813bd8dfb 100755 --- a/examples/Basic_Simulation/initial_conditions.py +++ b/examples/Basic_Simulation/initial_conditions.py @@ -54,13 +54,13 @@ capom_pl = default_rng().uniform(0.0, 360.0, npl) omega_pl = default_rng().uniform(0.0, 360.0, npl) capm_pl = default_rng().uniform(0.0, 360.0, npl) -GM_pl = (np.array([6e23, 8e23, 1e24, 3e24, 5e24]) / sim.param['MU2KG']) * sim.GU -R_pl = np.full(npl, (3 * (GM_pl / sim.GU) / (4 * np.pi * density_pl)) ** (1.0 / 3.0)) -Rh_pl = a_pl * ((GM_pl) / (3 * sim.GU)) ** (1.0 / 3.0) +M_pl = np.array([6e23, 8e23, 1e24, 3e24, 5e24]) * sim.KG2MU +R_pl = np.full(npl, (3 * M_pl/ (4 * np.pi * density_pl)) ** (1.0 / 3.0)) Ip_pl = np.full((npl,3),0.4,) rot_pl = np.zeros((npl,3)) +mtiny = 1.01 * np.max(M_pl) -sim.add_body(name=name_pl, a=a_pl, e=e_pl, inc=inc_pl, capom=capom_pl, omega=omega_pl, capm=capm_pl, Gmass=GM_pl, radius=R_pl, rhill=Rh_pl, Ip=Ip_pl, rot=rot_pl) +sim.add_body(name=name_pl, a=a_pl, e=e_pl, inc=inc_pl, capom=capom_pl, omega=omega_pl, capm=capm_pl, mass=M_pl, radius=R_pl, Ip=Ip_pl, rot=rot_pl) # Add 10 user-defined test particles. ntp = 10 @@ -74,7 +74,7 @@ capm_tp = default_rng().uniform(0.0, 360.0, ntp) sim.add_body(name=name_tp, a=a_tp, e=e_tp, inc=inc_tp, capom=capom_tp, omega=omega_tp, capm=capm_tp) -sim.set_parameter(tstart=0.0, tstop=1.0e3, dt=0.01, istep_out=100, dump_cadence=0) +sim.set_parameter(tstart=0.0, tstop=1.0e3, dt=0.01, istep_out=100, dump_cadence=0, compute_conservation_values=True, mtiny=mtiny) # Display the run configuration parameters. sim.get_parameter() sim.save() diff --git a/src/swiftest/swiftest_io.f90 b/src/swiftest/swiftest_io.f90 index 921ea8308..38b1735d7 100644 --- a/src/swiftest/swiftest_io.f90 +++ b/src/swiftest/swiftest_io.f90 @@ -123,8 +123,6 @@ module subroutine swiftest_io_conservation_report(self, param, lterminal) real(DP), dimension(NDIM) :: L_total_now, L_orbit_now, L_spin_now real(DP) :: ke_orbit_now, ke_spin_now, pe_now, E_orbit_now, be_now, be_cb_now, be_cb_orig, te_now real(DP) :: GMtot_now - character(len=STRMAX) :: errmsg - integer(I4B), parameter :: EGYIU = 72 character(len=*), parameter :: EGYTERMFMT = '(" DL/L0 = ", ES12.5, "; DE_orbit/|E0| = ", ES12.5, "; DE_total/|E0| = ", ES12.5, "; DM/M0 = ", ES12.5)' associate(nbody_system => self, pl => self%pl, cb => self%cb, npl => self%pl%nbody, display_unit => param%display_unit) @@ -204,10 +202,6 @@ module subroutine swiftest_io_conservation_report(self, param, lterminal) end associate return - - 667 continue - write(*,*) "Error writing energy and momentum tracking file: " // trim(adjustl(errmsg)) - call base_util_exit(FAILURE) end subroutine swiftest_io_conservation_report @@ -226,7 +220,6 @@ module subroutine swiftest_io_display_run_information(self, param, integration_t real(DP) :: tfrac !! Fraction of total simulation time completed type(progress_bar), save :: pbar !! Object used to print out a progress bar character(len=64) :: pbarmessage - character(*), parameter :: symbacompactfmt = '(";NPLM",ES22.15,$)' #ifdef COARRAY character(*), parameter :: co_statusfmt = '("Image: ",I4, "; Time = ", ES12.5, "; fraction done = ", F6.3, ' // & '"; Number of active pl, tp = ", I6, ", ", I6)' @@ -465,7 +458,6 @@ module subroutine swiftest_io_get_args(integrator, param_file_name, display_styl character(len=STRMAX), dimension(:), allocatable :: arg integer(I4B), dimension(:), allocatable :: ierr integer :: i,narg - character(len=*),parameter :: linefmt = '(A)' narg = command_argument_count() if (narg > 0) then @@ -653,6 +645,7 @@ module subroutine swiftest_io_netcdf_get_t0_values_system(self, nc, param) ! Internals integer(I4B) :: itmax, idmax, tslot real(DP), dimension(:), allocatable :: vals + logical, dimension(:), allocatable :: plmask, tpmask real(DP), dimension(1) :: rtemp real(DP), dimension(NDIM) :: rot0, Ip0, L real(DP) :: mass0 @@ -689,7 +682,8 @@ module subroutine swiftest_io_netcdf_get_t0_values_system(self, nc, param) self%L_total_orig(:) = self%L_orbit_orig(:) + self%L_spin_orig(:) call netcdf_io_check( nf90_get_var(nc%id, nc%Gmass_varid, vals, start=[1,tslot], count=[idmax,1]), "netcdf_io_get_t0_values_system Gmass_varid" ) - self%GMtot_orig = vals(1) + sum(vals(2:idmax), vals(2:idmax) == vals(2:idmax)) + call nc%get_valid_masks(plmask,tpmask) + self%GMtot_orig = vals(1) + sum(vals(2:idmax), plmask(:)) cb%GM0 = vals(1) cb%dGM = cb%Gmass - cb%GM0 @@ -1030,7 +1024,7 @@ module subroutine swiftest_io_netcdf_open(self, param, readonly) end subroutine swiftest_io_netcdf_open - module subroutine swiftest_io_netcdf_get_valid_masks(self, plmask, tpmask) + module subroutine swiftest_io_netcdf_get_valid_masks(self, plmask, tpmask, plmmask, Gmtiny) !! author: David A. Minton !! !! Given an open NetCDF, returns logical masks indicating which bodies in the body arrays are active pl and tp type at the current time. @@ -1039,15 +1033,17 @@ module subroutine swiftest_io_netcdf_get_valid_masks(self, plmask, tpmask) use, intrinsic :: ieee_arithmetic implicit none ! Arguments - class(swiftest_netcdf_parameters), intent(inout) :: self !! Parameters used to identify a particular NetCDF dataset - logical, dimension(:), allocatable, intent(out) :: plmask !! Logical mask indicating which bodies are massive bodies - logical, dimension(:), allocatable, intent(out) :: tpmask !! Logical mask indicating which bodies are test particles + class(swiftest_netcdf_parameters), intent(inout) :: self !! Parameters used to identify a particular NetCDF dataset + logical, dimension(:), allocatable, intent(out) :: plmask !! Logical mask indicating which bodies are massive bodies + logical, dimension(:), allocatable, intent(out) :: tpmask !! Logical mask indicating which bodies are test particles + logical, dimension(:), allocatable, intent(out), optional :: plmmask !! Logical mask indicating which bodies are fully interacting massive bodies + real(DP), intent(in), optional :: Gmtiny !! The cutoff G*mass between semi-interacting and fully interacting massive bodies ! Internals real(DP), dimension(:), allocatable :: Gmass, a real(DP), dimension(:,:), allocatable :: rh integer(I4B), dimension(:), allocatable :: body_status logical, dimension(:), allocatable :: lvalid - integer(I4B) :: idmax, status, i + integer(I4B) :: idmax, status logical, dimension(size(IEEE_ALL)) :: fpe_halting_modes call ieee_get_halting_mode(IEEE_ALL,fpe_halting_modes) ! Save the current halting modes so we can turn them off temporarily @@ -1094,6 +1090,14 @@ module subroutine swiftest_io_netcdf_get_valid_masks(self, plmask, tpmask) ! Select only active bodies plmask(:) = plmask(:) .and. lvalid(:) tpmask(:) = tpmask(:) .and. lvalid(:) + + if (present(plmmask) .and. present(Gmtiny)) then + allocate(plmmask, source=plmask) + where(plmask(:)) + plmmask = Gmass(:) > Gmtiny + endwhere + end if + call ieee_set_halting_mode(IEEE_ALL,fpe_halting_modes) end associate @@ -1316,10 +1320,6 @@ module function swiftest_io_netcdf_read_frame_system(self, nc, param) result(ier ierr = 0 return - - 667 continue - write(*,*) "Error reading nbody_system frame in netcdf_io_read_frame_system" - end function swiftest_io_netcdf_read_frame_system @@ -1335,21 +1335,15 @@ module subroutine swiftest_io_netcdf_read_hdr_system(self, nc, param) class(swiftest_netcdf_parameters), intent(inout) :: nc !! Parameters used to for reading a NetCDF dataset to file class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters ! Internals - integer(I4B) :: status, idmax + integer(I4B) :: status logical, dimension(:), allocatable :: plmask, tpmask, plmmask - real(DP), dimension(:), allocatable :: Gmtemp associate(tslot => nc%tslot) call netcdf_io_check( nf90_get_var(nc%id, nc%time_varid, self%t, start=[tslot]), "netcdf_io_read_hdr_system nf90_getvar time_varid" ) - call nc%get_valid_masks(plmask, tpmask) - if (param%lmtiny_pl) then - idmax = size(plmask) - allocate(plmmask(idmax)) - allocate(Gmtemp(idmax)) - call netcdf_io_check( nf90_get_var(nc%id, nc%Gmass_varid, Gmtemp, start=[1,tslot], count=[idmax,1]), "netcdf_io_read_hdr_system nf90_getvar Gmass_varid" ) - where(Gmtemp(:) /= Gmtemp(:)) Gmtemp(:) = 0.0_DP - plmmask(:) = plmask(:) .and. Gmtemp(:) > param%GMTINY + call nc%get_valid_masks(plmask, tpmask, plmmask, param%GMTINY) + else + call nc%get_valid_masks(plmask, tpmask) end if status = nf90_inq_varid(nc%id, nc%npl_varname, nc%npl_varid) @@ -1624,7 +1618,7 @@ module subroutine swiftest_io_netcdf_write_frame_body(self, nc, param) class(swiftest_netcdf_parameters), intent(inout) :: nc !! Parameters used to for writing a NetCDF dataset to file class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters ! Internals - integer(I4B) :: i, j, idslot, old_mode + integer(I4B) :: i, j, idslot, old_mode, tmp integer(I4B), dimension(:), allocatable :: ind real(DP), dimension(NDIM) :: vh !! Temporary variable to store heliocentric velocity values when converting from pseudovelocity in GR-enabled runs real(DP) :: a, e, inc, omega, capom, capm, varpi, lam, f, cape, capf @@ -1729,7 +1723,7 @@ module subroutine swiftest_io_netcdf_write_frame_body(self, nc, param) end select #endif - call netcdf_io_check( nf90_set_fill(nc%id, old_mode, old_mode), "netcdf_io_write_frame_body nf90_set_fill old_mode" ) + call netcdf_io_check( nf90_set_fill(nc%id, old_mode, tmp), "netcdf_io_write_frame_body nf90_set_fill old_mode" ) return end subroutine swiftest_io_netcdf_write_frame_body @@ -1745,7 +1739,7 @@ module subroutine swiftest_io_netcdf_write_frame_cb(self, nc, param) class(swiftest_netcdf_parameters), intent(inout) :: nc !! Parameters used to for writing a NetCDF dataset to file class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters ! Internals - integer(I4B) :: idslot, old_mode + integer(I4B) :: idslot, old_mode, tmp associate(tslot => nc%tslot) call self%write_info(nc, param) @@ -1766,7 +1760,7 @@ module subroutine swiftest_io_netcdf_write_frame_cb(self, nc, param) call netcdf_io_check( nf90_put_var(nc%id, nc%rot_varid, self%rot(:) * RAD2DEG, start=[1, idslot, tslot], count=[NDIM,1,1]), "swiftest_io_netcdf_write_frame_cby nf90_put_var cb rot_varid" ) end if - call netcdf_io_check( nf90_set_fill(nc%id, old_mode, old_mode), "swiftest_io_netcdf_write_frame_cb nf90_set_fill old_mode" ) + call netcdf_io_check( nf90_set_fill(nc%id, old_mode, tmp), "swiftest_io_netcdf_write_frame_cb nf90_set_fill old_mode" ) end associate return @@ -1848,7 +1842,7 @@ module subroutine swiftest_io_netcdf_write_info_body(self, nc, param) class(swiftest_netcdf_parameters), intent(inout) :: nc !! Parameters used to identify a particular NetCDF dataset class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters ! Internals - integer(I4B) :: i, j, idslot, old_mode + integer(I4B) :: i, j, idslot, old_mode, tmp integer(I4B), dimension(:), allocatable :: ind character(len=NAMELEN) :: charstring character(len=NAMELEN), dimension(self%nbody) :: origin_type @@ -1892,7 +1886,7 @@ module subroutine swiftest_io_netcdf_write_info_body(self, nc, param) end associate end select - call netcdf_io_check( nf90_set_fill(nc%id, old_mode, old_mode) ) + call netcdf_io_check( nf90_set_fill(nc%id, old_mode, tmp) ) return end subroutine swiftest_io_netcdf_write_info_body @@ -1906,7 +1900,7 @@ module subroutine swiftest_io_netcdf_write_info_cb(self, nc, param) class(swiftest_netcdf_parameters), intent(inout) :: nc !! Parameters used to identify a particular NetCDF dataset class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters ! Internals - integer(I4B) :: idslot, old_mode + integer(I4B) :: idslot, old_mode, tmp character(len=NAMELEN) :: charstring ! This string of spaces of length NAMELEN is used to clear out any old data left behind inside the string variables @@ -1935,7 +1929,7 @@ module subroutine swiftest_io_netcdf_write_info_cb(self, nc, param) call netcdf_io_check( nf90_put_var(nc%id, nc%discard_rh_varid, self%info%discard_rh(:), start=[1, idslot], count=[NDIM,1]), "netcdf_io_write_info_body nf90_put_var cb discard_rh_varid" ) call netcdf_io_check( nf90_put_var(nc%id, nc%discard_vh_varid, self%info%discard_vh(:), start=[1, idslot], count=[NDIM,1]), "netcdf_io_write_info_body nf90_put_var cb discard_vh_varid" ) end if - call netcdf_io_check( nf90_set_fill(nc%id, old_mode, old_mode) ) + call netcdf_io_check( nf90_set_fill(nc%id, old_mode, tmp) ) return end subroutine swiftest_io_netcdf_write_info_cb @@ -1989,7 +1983,6 @@ module subroutine swiftest_io_param_reader(self, unit, iotype, v_list, iostat, i character(*),parameter :: linefmt = '(A)' !! Format code for simple text string integer(I4B) :: nseeds, nseeds_from_file logical :: seed_set = .false. !! Is the random seed set in the input file? - character(len=:), allocatable :: integrator real(DP) :: tratio, y #ifdef COARRAY type(swiftest_parameters), codimension[*], save :: coparam @@ -2517,9 +2510,6 @@ module subroutine swiftest_io_param_writer(self, unit, iotype, v_list, iostat, i integer, intent(out) :: iostat !! IO status code character(len=*), intent(inout) :: iomsg !! Message to pass if iostat /= 0 ! Internals - character(*),parameter :: Ifmt = '(I0)' !! Format label for integer values - character(*),parameter :: Rfmt = '(ES25.17)' !! Format label for real values - character(*),parameter :: Lfmt = '(L1)' !! Format label for logical values integer(I4B) :: nseeds associate(param => self) @@ -2588,7 +2578,6 @@ module subroutine swiftest_io_param_writer(self, unit, iotype, v_list, iostat, i iomsg = "UDIO not implemented" end associate - 667 continue return end subroutine swiftest_io_param_writer @@ -2935,7 +2924,7 @@ module subroutine swiftest_io_read_in_system(self, nc, param) if (ierr /=0) call base_util_exit(FAILURE) end if - param%loblatecb = ((self%cb%j2rp2 /= 0.0_DP) .or. (self%cb%j4rp4 /= 0.0_DP)) + param%loblatecb = ((abs(self%cb%j2rp2) > 0.0_DP) .or. (abs(self%cb%j4rp4) > 0.0_DP)) if (.not.param%loblatecb) then if (allocated(self%pl%aobl)) deallocate(self%pl%aobl) if (allocated(self%tp%aobl)) deallocate(self%tp%aobl) @@ -3083,7 +3072,6 @@ module subroutine swiftest_io_read_in_param(self, param_file_name) call self%reader(LUN, iotype= "none", v_list=[""], iostat = ierr, iomsg = errmsg) if (ierr == 0) return - 667 continue write(self%display_unit,*) "Error reading parameter file: " // trim(adjustl(errmsg)) call base_util_exit(FAILURE) end subroutine swiftest_io_read_in_param @@ -3177,7 +3165,7 @@ module subroutine swiftest_io_initialize_output_file_system(self, nc, param) class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters ! Internals logical, save :: lfirst = .true. !! Flag to determine if this is the first call of this method - character(len=STRMAX) :: errmsg + character(len=2*STRMAX) :: errmsg logical :: fileExists associate (pl => self%pl, tp => self%tp, npl => self%pl%nbody, ntp => self%tp%nbody) @@ -3191,13 +3179,13 @@ module subroutine swiftest_io_initialize_output_file_system(self, nc, param) select case(param%out_stat) case('APPEND') if (.not.fileExists) then - errmsg = param%outfile // " not found! You must specify OUT_STAT = NEW, REPLACE, or UNKNOWN" + errmsg = trim(adjustl(param%outfile)) // " not found! You must specify OUT_STAT = NEW, REPLACE, or UNKNOWN" goto 667 end if call nc%open(param) case('NEW') if (fileExists) then - errmsg = param%outfile // " Alread Exists! You must specify OUT_STAT = APPEND, REPLACE, or UNKNOWN" + errmsg = trim(adjustl(param%outfile)) // " Alread Exists! You must specify OUT_STAT = APPEND, REPLACE, or UNKNOWN" goto 667 end if call nc%initialize(param) From 8c9e0520d12ca5cb61cd58c1725c79f994172189 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Thu, 25 May 2023 11:32:33 -0400 Subject: [PATCH 43/95] Removed the line in the executable that calls the shell default shell configuration file temporarily until I determine if it is necessary --- python/swiftest/swiftest/simulation_class.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/swiftest/swiftest/simulation_class.py b/python/swiftest/swiftest/simulation_class.py index 0ae7f540b..10a869ec1 100644 --- a/python/swiftest/swiftest/simulation_class.py +++ b/python/swiftest/swiftest/simulation_class.py @@ -2779,7 +2779,7 @@ def write_param(self, self.driver_script = os.path.join(self.simdir, "swiftest_driver.sh") with open(self.driver_script, 'w') as f: f.write(f"#{self._shell_full}\n") - f.write(f"source ~/.{self._shell}rc\n") + #f.write(f"source ~/.{self._shell}rc\n") f.write(f"cd {self.simdir}\n") f.write(f"{str(self.driver_executable)} {self.integrator} {str(self.param_file)} compact\n") From 54869bed837c9340fc6f6346904f44f1c66e1009 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Thu, 25 May 2023 11:32:47 -0400 Subject: [PATCH 44/95] Improved GNU warning flags in debug mode --- cmake/Modules/SetFortranFlags.cmake | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/cmake/Modules/SetFortranFlags.cmake b/cmake/Modules/SetFortranFlags.cmake index 0d06920de..7b7752747 100644 --- a/cmake/Modules/SetFortranFlags.cmake +++ b/cmake/Modules/SetFortranFlags.cmake @@ -186,6 +186,20 @@ SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" "/warn:all" # Intel Windows "-Wall" # GNU ) +# This enables some extra warning flags that are not enabled by -Wall +SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" + Fortran "-Wextra" # GNU + ) + +# Disable the warning that arrays may be uninitialized, which comes up due to a known bug in gfortran +SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" + Fortran "-Wno-maybe-uninitialized" # GNU + ) +# Disable the warning about unused dummy arguments. These primarily occur due to interface rules for type-bound procedures used in extendable types. +SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" + Fortran "-Wno-unused-dummy-argument" # GNU + ) + # Traceback SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" @@ -241,6 +255,11 @@ SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" "-ffpe-trap=zero,overflow,underflow" # GNU ) +# List of floating-point exceptions, whose flag status is printed to ERROR_UNIT when invoking STOP and ERROR STOP +SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" + Fortran "-ffpe-summary=all" # GNU + ) + # Enables floating-point invalid, divide-by-zero, and overflow exceptions SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" Fortran "-fpe0" # Intel From 511e425c3a3a24445eccba9714cbaf9c82058e45 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Thu, 25 May 2023 11:49:56 -0400 Subject: [PATCH 45/95] Fixed inconsistent types in index flattener routines --- src/swiftest/swiftest_util.f90 | 60 +++++++++++++--------------------- 1 file changed, 22 insertions(+), 38 deletions(-) diff --git a/src/swiftest/swiftest_util.f90 b/src/swiftest/swiftest_util.f90 index b063cb418..641fcc170 100644 --- a/src/swiftest/swiftest_util.f90 +++ b/src/swiftest/swiftest_util.f90 @@ -1101,12 +1101,12 @@ module subroutine swiftest_util_flatten_eucl_plpl(self, param) class(swiftest_pl), intent(inout) :: self !! Swiftest massive body object class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters ! Internals - integer(I4B) :: i, j, err - integer(I8B) :: k, npl + integer(I4B) :: err, i, j + integer(I8B) :: k, npl8 - npl = int(self%nbody, kind=I8B) - associate(nplpl => self%nplpl) - nplpl = npl * (npl - 1_I8B) / 2_I8B ! number of entries in a strict lower triangle, npl x npl + associate(npl => self%nbody, nplpl => self%nplpl) + npl8 = int(npl, kind=I8B) + nplpl = npl8 * (npl8 - 1_I8B) / 2_I8B ! number of entries in a strict lower triangle, npl x npl if (param%lflatten_interactions) then if (allocated(self%k_plpl)) deallocate(self%k_plpl) ! Reset the index array if it's been set previously allocate(self%k_plpl(2, nplpl), stat=err) @@ -1118,7 +1118,7 @@ module subroutine swiftest_util_flatten_eucl_plpl(self, param) #else do concurrent (i=1:npl, j=1:npl, j>i) #endif - call swiftest_util_flatten_eucl_ij_to_k(self%nbody, i, j, k) + call swiftest_util_flatten_eucl_ij_to_k(npl, i, j, k) self%k_plpl(1, k) = i self%k_plpl(2, k) = j end do @@ -1145,17 +1145,18 @@ module subroutine swiftest_util_flatten_eucl_pltp(self, pl, param) class(swiftest_pl), intent(in) :: pl !! Swiftest massive body object class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters ! Internals - integer(I8B) :: i, j, counter, npl, ntp + integer(I4B) :: i, j + integer(I8B) :: counter, npl8, ntp8 - ntp = int(self%nbody, kind=I8B) - npl = int(pl%nbody, kind=I8B) - associate(npltp => self%npltp) - npltp = npl * ntp + associate(ntp => self%nbody, npl => pl%nbody, npltp => self%npltp) + npl8 = int(npl, kind=I8B) + ntp8 = int(ntp, kind=I8B) + npltp = npl8 * ntp8 if (allocated(self%k_pltp)) deallocate(self%k_pltp) ! Reset the index array if it's been set previously allocate(self%k_pltp(2, npltp)) - do i = 1_I8B, npl - counter = (i - 1_I8B) * npl + 1_I8B - do j = 1_I8B, ntp + counter = 1_I8B + do i = 1, npl + do j = 1, ntp self%k_pltp(1, counter) = i self%k_pltp(2, counter) = j counter = counter + 1_I8B @@ -1643,7 +1644,8 @@ module subroutine swiftest_util_rearray_pl(self, nbody_system, param) class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters ! Internals class(swiftest_pl), allocatable :: tmp !! The discarded body list. - integer(I4B) :: i, k, npl, nadd, nencmin, nenc_old, idnew1, idnew2, idold1, idold2 + integer(I4B) :: i, npl, nadd, idnew1, idnew2, idold1, idold2 + integer(I8B) :: k, nenc_old, nencmin logical, dimension(:), allocatable :: lmask class(encounter_list), allocatable :: plplenc_old logical :: lencounter @@ -1708,7 +1710,7 @@ module subroutine swiftest_util_rearray_pl(self, nbody_system, param) if (allocated(nbody_system%plpl_encounter)) then ! Store the original plplenc list so we don't remove any of the original encounters nenc_old = nbody_system%plpl_encounter%nenc - if (nenc_old > 0) then + if (nenc_old > 0_I8B) then allocate(plplenc_old, source=nbody_system%plpl_encounter) call plplenc_old%copy(nbody_system%plpl_encounter) end if @@ -1730,10 +1732,10 @@ module subroutine swiftest_util_rearray_pl(self, nbody_system, param) end select ! Re-index the encounter list as the index values may have changed - if (nenc_old > 0) then + if (nenc_old > 0_I8B) then nencmin = min(nbody_system%plpl_encounter%nenc, plplenc_old%nenc) nbody_system%plpl_encounter%nenc = nencmin - do k = 1, nencmin + do k = 1_I8B, nencmin idnew1 = nbody_system%plpl_encounter%id1(k) idnew2 = nbody_system%plpl_encounter%id2(k) idold1 = plplenc_old%id1(k) @@ -1774,7 +1776,7 @@ module subroutine swiftest_util_rearray_pl(self, nbody_system, param) end if nencmin = count(lmask(:)) nbody_system%plpl_encounter%nenc = nencmin - if (nencmin > 0) then + if (nencmin > 0_I8B) then nbody_system%plpl_encounter%index1(1:nencmin) = pack(nbody_system%plpl_encounter%index1(1:nenc_old), lmask(1:nenc_old)) nbody_system%plpl_encounter%index2(1:nencmin) = pack(nbody_system%plpl_encounter%index2(1:nenc_old), lmask(1:nenc_old)) nbody_system%plpl_encounter%id1(1:nencmin) = pack(nbody_system%plpl_encounter%id1(1:nenc_old), lmask(1:nenc_old)) @@ -3325,9 +3327,7 @@ module subroutine swiftest_util_version() "Authors:", //, & " The Purdue University Swiftest Development team ", /, & " Lead by David A. Minton ", /, & - " Single loop blocking by Jacob R. Elliott", /, & - " Fragmentation by Carlisle A. Wishard and", //, & - " Jennifer L. L. Poutplin ", //, & + " Carlisle Wishard, Jennifer Pouplin, Jacob Elliott, Dana Singh." & "Please address comments and questions to:", //, & " David A. Minton", /, & " Department Earth, Atmospheric, & Planetary Sciences ",/, & @@ -3341,22 +3341,6 @@ module subroutine swiftest_util_version() "************************************************", /) - 100 FORMAT(/, "************* SWIFTER: Version ", F3.1, " *************", //, & - "Authors:", //, & - " Martin Duncan: Queen's University", /, & - " Hal Levison : Southwest Research Institute", //, & - "Please address comments and questions to:", //, & - " Hal Levison or David Kaufmann", /, & - " Department of Space Studies", /, & - " Southwest Research Institute", /, & - " 1050 Walnut Street, Suite 400", /, & - " Boulder, Colorado 80302", /, & - " 303-546-0290 (HFL), 720-240-0119 (DEK)", /, & - " 303-546-9687 (fax)", /, & - " hal@gort.boulder.swri.edu (HFL)", /, & - " kaufmann@boulder.swri.edu (DEK)", //, & - "************************************************", /) - return end subroutine swiftest_util_version From d854c21a1444866e7ee6b4a56582fc709fcf5be7 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Thu, 25 May 2023 11:55:21 -0400 Subject: [PATCH 46/95] Improved the tslot finder using proper ieee arithmetic routine --- src/CMakeLists.txt | 2 +- src/netcdf_io/netcdf_io_implementations.f90 | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e241d3360..0e3decf3c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -25,6 +25,7 @@ SET(STRICT_MATH_FILES ${SRC}/helio/helio_step.f90 ${SRC}/misc/lambda_function_module.f90 ${SRC}/misc/solver_module.f90 + ${SRC}/netcdf_io/netcdf_io_implementations.f90 ${SRC}/operator/operator_module.f90 ${SRC}/operator/operator_cross.f90 ${SRC}/operator/operator_mag.f90 @@ -69,7 +70,6 @@ SET(FAST_MATH_FILES ${SRC}/encounter/encounter_io.f90 ${SRC}/encounter/encounter_util.f90 ${SRC}/helio/helio_util.f90 - ${SRC}/netcdf_io/netcdf_io_implementations.f90 ${SRC}/rmvs/rmvs_discard.f90 ${SRC}/rmvs/rmvs_encounter_check.f90 ${SRC}/rmvs/rmvs_util.f90 diff --git a/src/netcdf_io/netcdf_io_implementations.f90 b/src/netcdf_io/netcdf_io_implementations.f90 index 831b17902..b4e7f0b12 100644 --- a/src/netcdf_io/netcdf_io_implementations.f90 +++ b/src/netcdf_io/netcdf_io_implementations.f90 @@ -59,6 +59,8 @@ module subroutine netcdf_io_find_tslot(self, t, tslot) !! !! Given an open NetCDF file and a value of time t, finds the index of the time value (aka the time slot) to place a new set of data. !! The returned value of tslot will correspond to the first index value where the value of t is greater than or equal to the saved time value. + use, intrinsic :: ieee_exceptions + use, intrinsic :: ieee_arithmetic implicit none ! Arguments class(netcdf_parameters), intent(inout) :: self !! Parameters used to identify a particular NetCDF dataset @@ -67,7 +69,10 @@ module subroutine netcdf_io_find_tslot(self, t, tslot) ! Internals real(DP), dimension(:), allocatable :: tvals integer(I4B) :: i + logical, dimension(size(IEEE_ALL)) :: fpe_halting_modes + call ieee_get_halting_mode(IEEE_ALL,fpe_halting_modes) ! Save the current halting modes so we can turn them off temporarily + call ieee_set_halting_mode(IEEE_ALL,.false.) if (.not.self%lfile_is_open) return tslot = 0 @@ -76,7 +81,7 @@ module subroutine netcdf_io_find_tslot(self, t, tslot) if (self%max_tslot > 0) then allocate(tvals(self%max_tslot)) call netcdf_io_check( nf90_get_var(self%id, self%time_varid, tvals(:), start=[1]), "netcdf_io_find_tslot get_var" ) - where(tvals(:) /= tvals(:)) tvals(:) = huge(1.0_DP) + where(.not.ieee_is_normal(tvals(:))) tvals(:) = huge(1.0_DP) else allocate(tvals(1)) tvals(1) = huge(1.0_DP) @@ -91,6 +96,8 @@ module subroutine netcdf_io_find_tslot(self, t, tslot) self%max_tslot = max(self%max_tslot, tslot) self%tslot = tslot + call ieee_set_halting_mode(IEEE_ALL,fpe_halting_modes) + return end subroutine netcdf_io_find_tslot From 7b923bd97a30a32351468ac151e8db024abfbb00 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Thu, 25 May 2023 12:00:56 -0400 Subject: [PATCH 47/95] Cleaned up unused variables, type conversion inconsistencies (except for unit conversions using quad precision) and other things flagged by gfortran warnings --- src/base/base_module.f90 | 2 +- src/collision/collision_check.f90 | 26 +++++++++++++----------- src/collision/collision_generate.f90 | 5 +++-- src/collision/collision_io.f90 | 4 ++-- src/collision/collision_module.f90 | 2 +- src/collision/collision_resolve.f90 | 20 ++++++++++--------- src/encounter/encounter_check.f90 | 8 ++++---- src/encounter/encounter_io.f90 | 4 ++-- src/fraggle/fraggle_generate.f90 | 2 -- src/fraggle/fraggle_util.f90 | 7 +++---- src/rmvs/rmvs_step.f90 | 5 ++--- src/swiftest/swiftest_module.f90 | 10 ++++++---- src/swiftest/swiftest_orbel.f90 | 5 ++--- src/symba/symba_encounter_check.f90 | 30 +++++++++++++++------------- src/symba/symba_kick.f90 | 15 +++++++------- src/symba/symba_step.f90 | 1 - src/symba/symba_util.f90 | 4 ---- 17 files changed, 75 insertions(+), 75 deletions(-) diff --git a/src/base/base_module.f90 b/src/base/base_module.f90 index 01c111661..0f91e3473 100644 --- a/src/base/base_module.f90 +++ b/src/base/base_module.f90 @@ -2078,7 +2078,7 @@ subroutine base_util_unique_DP(input_array, output_array, index_map) n = n + 1 lo = minval(input_array(:), mask=input_array(:) > lo) unique_array(n) = lo - where(input_array(:) == lo) index_map(:) = n + where(abs(input_array(:) - lo) < epsilon(1.0_DP) * lo) index_map(:) = n if (lo >= hi) exit enddo allocate(output_array(n), source=unique_array(1:n)) diff --git a/src/collision/collision_check.f90 b/src/collision/collision_check.f90 index 0e69032bc..ebb4a3671 100644 --- a/src/collision/collision_check.f90 +++ b/src/collision/collision_check.f90 @@ -77,7 +77,8 @@ module subroutine collision_check_plpl(self, nbody_system, param, t, dt, irec, l ! Internals logical, dimension(:), allocatable :: lcollision, lmask real(DP), dimension(NDIM) :: xr, vr - integer(I4B) :: i, j, k, nenc + integer(I4B) :: i, j + integer(I8B) :: k, nenc real(DP) :: rlim, Gmtot logical :: lany_closest @@ -102,9 +103,9 @@ module subroutine collision_check_plpl(self, nbody_system, param, t, dt, irec, l self%lclosest(:) = .false. #ifdef DOCONLOC - do concurrent(k = 1:nenc, lmask(k)) shared(self,pl,lmask, dt, lcollision) local(i,j,xr,vr,rlim,Gmtot) + do concurrent(k = 1_I8B:nenc, lmask(k)) shared(self,pl,lmask, dt, lcollision) local(i,j,xr,vr,rlim,Gmtot) #else - do concurrent(k = 1:nenc, lmask(k)) + do concurrent(k = 1_I8B:nenc, lmask(k)) #endif i = self%index1(k) j = self%index2(k) @@ -120,7 +121,7 @@ module subroutine collision_check_plpl(self, nbody_system, param, t, dt, irec, l if (lany_collision .or. lany_closest) then call pl%rh2rb(nbody_system%cb) ! Update the central body barycenteric position vector to get us out of DH and into bary - do k = 1, nenc + do k = 1_I8B, nenc if (.not.lcollision(k) .and. .not. self%lclosest(k)) cycle i = self%index1(k) j = self%index2(k) @@ -178,7 +179,8 @@ module subroutine collision_check_pltp(self, nbody_system, param, t, dt, irec, l ! Internals logical, dimension(:), allocatable :: lcollision, lmask real(DP), dimension(NDIM) :: xr, vr - integer(I4B) :: i, j, k, nenc + integer(I4B) :: i, j + integer(I8B) :: k, nenc logical :: lany_closest character(len=STRMAX) :: timestr, idstri, idstrj, message class(collision_list_pltp), allocatable :: tmp @@ -194,13 +196,13 @@ module subroutine collision_check_pltp(self, nbody_system, param, t, dt, irec, l nenc = self%nenc allocate(lmask(nenc)) - lmask(:) = (self%status(1:nenc) == ACTIVE) + lmask(:) = (self%status(1:nenc) == ACTIVE) select type(pl) class is (symba_pl) - select type(tp) - class is (symba_tp) - lmask(:) = lmask(:) .and. (tp%levelg(self%index2(1:nenc)) >= irec) - end select + select type(tp) + class is (symba_tp) + lmask(:) = lmask(:) .and. (tp%levelg(self%index2(1:nenc)) >= irec) + end select end select if (.not.any(lmask(:))) return @@ -209,9 +211,9 @@ module subroutine collision_check_pltp(self, nbody_system, param, t, dt, irec, l self%lclosest(:) = .false. #ifdef DOCONLOC - do concurrent(k = 1:nenc, lmask(k)) shared(self,pl,tp,lmask, dt, lcollision) local(i,j,xr,vr) + do concurrent(k = 1_I8B:nenc, lmask(k)) shared(self,pl,tp,lmask, dt, lcollision) local(i,j,xr,vr) #else - do concurrent(k = 1:nenc, lmask(k)) + do concurrent(k = 1_I8B:nenc, lmask(k)) #endif i = self%index1(k) j = self%index2(k) diff --git a/src/collision/collision_generate.f90 b/src/collision/collision_generate.f90 index 6162122cf..7f529ba02 100644 --- a/src/collision/collision_generate.f90 +++ b/src/collision/collision_generate.f90 @@ -170,7 +170,8 @@ module subroutine collision_generate_merge(self, nbody_system, param, t) class(base_parameters), intent(inout) :: param !! Current run configuration parameters real(DP), intent(in) :: t !! The time of the collision ! Internals - integer(I4B) :: i, j, k, ibiggest + integer(I4B) :: i, j, ibiggest + integer(I8B) :: k real(DP), dimension(NDIM) :: L_spin_new, L_residual real(DP) :: volume character(len=STRMAX) :: message @@ -231,7 +232,7 @@ module subroutine collision_generate_merge(self, nbody_system, param, t) call collision_util_velocity_torque(-L_residual(:), fragments%mass(1), fragments%rb(:,1), fragments%vb(:,1)) ! Update any encounter lists that have the removed bodies in them so that they instead point to the new body - do k = 1, nbody_system%plpl_encounter%nenc + do k = 1_I8B, nbody_system%plpl_encounter%nenc do j = 1, impactors%ncoll i = impactors%id(j) if (i == ibiggest) cycle diff --git a/src/collision/collision_io.f90 b/src/collision/collision_io.f90 index d0e8f30ae..cb4a544a0 100644 --- a/src/collision/collision_io.f90 +++ b/src/collision/collision_io.f90 @@ -365,7 +365,7 @@ module subroutine collision_io_netcdf_write_frame_snapshot(self, history, param) class(encounter_storage), intent(inout) :: history !! Collision history object class(base_parameters), intent(inout) :: param !! Current run configuration parameters ! Internals - integer(I4B) :: i, idslot, old_mode, npl, stage + integer(I4B) :: i, idslot, old_mode, npl, stage, tmp character(len=NAMELEN) :: charstring class(swiftest_pl), allocatable :: pl @@ -427,7 +427,7 @@ module subroutine collision_io_netcdf_write_frame_snapshot(self, history, param) call netcdf_io_check( nf90_put_var(nc%id, nc%L_spin_varid, collider%L_spin(:,:), start=[1, 1, eslot], count=[NDIM, 2, 1]), "collision_io_netcdf_write_frame_snapshot nf90_put_var L_spin_varid before" ) end if - call netcdf_io_check( nf90_set_fill(nc%id, old_mode, old_mode) ) + call netcdf_io_check( nf90_set_fill(nc%id, old_mode, tmp) ) end associate end select return diff --git a/src/collision/collision_module.f90 b/src/collision/collision_module.f90 index 82bec250b..a06d6d2c1 100644 --- a/src/collision/collision_module.f90 +++ b/src/collision/collision_module.f90 @@ -126,7 +126,7 @@ module collision real(DP), dimension(:), allocatable :: rmag !! Array of radial distance magnitudes of individual fragments in the collisional coordinate frame real(DP), dimension(:), allocatable :: vmag !! Array of radial distance magnitudes of individual fragments in the collisional coordinate frame real(DP), dimension(:), allocatable :: rotmag !! Array of rotation magnitudes of individual fragments - integer(I1B), dimension(:), allocatable :: origin_body !! Array of indices indicating which impactor body (1 or 2) the fragment originates from + integer(I4B), dimension(:), allocatable :: origin_body !! Array of indices indicating which impactor body (1 or 2) the fragment originates from real(DP), dimension(NDIM) :: L_orbit_tot !! Orbital angular momentum vector of all fragments real(DP), dimension(NDIM) :: L_spin_tot !! Spin angular momentum vector of all fragments real(DP), dimension(:,:), allocatable :: L_orbit !! Orbital angular momentum vector of each individual fragment diff --git a/src/collision/collision_resolve.f90 b/src/collision/collision_resolve.f90 index 7aa76166c..3fbbbee84 100644 --- a/src/collision/collision_resolve.f90 +++ b/src/collision/collision_resolve.f90 @@ -191,8 +191,9 @@ module subroutine collision_resolve_extract_plpl(self, nbody_system, param) logical, dimension(:), allocatable :: lplpl_collision logical, dimension(:), allocatable :: lplpl_unique_parent integer(I4B), dimension(:), pointer :: plparent - integer(I4B), dimension(:), allocatable :: collision_idx, unique_parent_idx - integer(I4B) :: i, index_coll, ncollisions, nunique_parent, nplplenc + integer(I4B) :: nunique_parent + integer(I8B) :: ncollisions, index_coll, k, nplplenc + integer(I8B), dimension(:), allocatable :: unique_parent_idx, collision_idx select type(nbody_system) class is (swiftest_nbody_system) @@ -201,14 +202,14 @@ module subroutine collision_resolve_extract_plpl(self, nbody_system, param) associate(idx1 => self%index1, idx2 => self%index2, plparent => pl%kin%parent) nplplenc = self%nenc allocate(lplpl_collision(nplplenc)) - lplpl_collision(:) = self%status(1:nplplenc) == COLLIDED + lplpl_collision(:) = self%status(1_I8B:nplplenc) == COLLIDED if (.not.any(lplpl_collision)) return ! Collisions have been detected in this step. So we need to determine which of them are between unique bodies. ! Get the subset of pl-pl encounters that lead to a collision ncollisions = count(lplpl_collision(:)) allocate(collision_idx(ncollisions)) - collision_idx = pack([(i, i=1, nplplenc)], lplpl_collision) + collision_idx = pack([(k, k=1_I8B, nplplenc)], lplpl_collision) ! Get the subset of collisions that involve a unique pair of parents allocate(lplpl_unique_parent(ncollisions)) @@ -223,7 +224,7 @@ module subroutine collision_resolve_extract_plpl(self, nbody_system, param) ! due to restructuring of parent/child relationships when there are large numbers of multi-body collisions in a single ! step lplpl_unique_parent(:) = .true. - do index_coll = 1, ncollisions + do index_coll = 1_I8B, ncollisions associate(ip1 => plparent(idx1(collision_idx(index_coll))), ip2 => plparent(idx2(collision_idx(index_coll)))) lplpl_unique_parent(:) = .not. ( any(plparent(idx1(unique_parent_idx(:))) == ip1) .or. & any(plparent(idx2(unique_parent_idx(:))) == ip1) .or. & @@ -537,7 +538,8 @@ module subroutine collision_resolve_plpl(self, nbody_system, param, t, dt, irec) character(len=STRMAX) :: timestr, idstr integer(I4B), dimension(2) :: idx_parent !! Index of the two bodies considered the "parents" of the collision logical :: lgoodcollision - integer(I4B) :: i, j, nnew, loop, ncollisions + integer(I4B) :: i, j, nnew, loop + integer(I8B) :: k, ncollisions integer(I4B), dimension(:), allocatable :: idnew integer(I4B), parameter :: MAXCASCADE = 1000 @@ -576,9 +578,9 @@ module subroutine collision_resolve_plpl(self, nbody_system, param, t, dt, irec) call swiftest_io_log_one_message(COLLISION_LOG_OUT, "***********************************************************" // & "***********************************************************") - do i = 1, ncollisions - idx_parent(1) = pl%kin(idx1(i))%parent - idx_parent(2) = pl%kin(idx2(i))%parent + do k = 1_I8B, ncollisions + idx_parent(1) = pl%kin(idx1(k))%parent + idx_parent(2) = pl%kin(idx2(k))%parent call impactors%consolidate(nbody_system, param, idx_parent, lgoodcollision) if ((.not. lgoodcollision) .or. any(pl%status(idx_parent(:)) /= COLLIDED)) cycle diff --git a/src/encounter/encounter_check.f90 b/src/encounter/encounter_check.f90 index b987f8799..2d934e7d8 100644 --- a/src/encounter/encounter_check.f90 +++ b/src/encounter/encounter_check.f90 @@ -636,7 +636,7 @@ module subroutine encounter_check_collapse_ragged_list(ragged_list, n1, nenc, in ! Internals integer(I4B) :: i integer(I8B) :: j1, j0, nenci - integer(I4B), dimension(n1) :: ibeg + integer(I8B), dimension(n1) :: ibeg associate(nenc_arr => ragged_list(:)%nenc) nenc = sum(nenc_arr(:)) @@ -865,7 +865,7 @@ module subroutine encounter_check_sweep_aabb_double_list(self, n1, n2, r1, v1, r if (loverlap(i)) then ibeg = self%aabb%ibeg(i) + 1_I8B iend = self%aabb%iend(i) - 1_I8B - nbox = iend - ibeg + 1 + nbox = int(iend - ibeg, kind=I4B) + 1 call encounter_check_all_sweep_one(i, nbox, r1(1,i), r1(2,i), r1(3,i), v1(1,i), v1(2,i), v1(3,i), & xind(ibeg:iend), yind(ibeg:iend), zind(ibeg:iend),& vxind(ibeg:iend), vyind(ibeg:iend), vzind(ibeg:iend), & @@ -881,7 +881,7 @@ module subroutine encounter_check_sweep_aabb_double_list(self, n1, n2, r1, v1, r if (loverlap(i)) then ibeg = self%aabb%ibeg(i) + 1_I8B iend = self%aabb%iend(i) - 1_I8B - nbox = iend - ibeg + 1 + nbox = int(iend - ibeg, kind=I4B) + 1 ii = i - n1 call encounter_check_all_sweep_one(ii, nbox, r2(1,ii), r2(2,ii), r2(3,ii), v2(1,ii), v2(2,ii), v2(3,ii), & xind(ibeg:iend), yind(ibeg:iend), zind(ibeg:iend),& @@ -958,7 +958,7 @@ module subroutine encounter_check_sweep_aabb_single_list(self, n, r, v, renc, dt if (loverlap(i)) then ibeg = self%aabb%ibeg(i) + 1_I8B iend = self%aabb%iend(i) - 1_I8B - nbox = int(iend - ibeg + 1, kind=I4B) + nbox = int(iend - ibeg, kind=I4B) + 1 lencounteri(ibeg:iend) = .true. call encounter_check_all_sweep_one(i, nbox, r(1,i), r(2,i), r(3,i), v(1,i), v(2,i), v(3,i), & xind(ibeg:iend), yind(ibeg:iend), zind(ibeg:iend),& diff --git a/src/encounter/encounter_io.f90 b/src/encounter/encounter_io.f90 index ceb3194fe..fb5de048f 100644 --- a/src/encounter/encounter_io.f90 +++ b/src/encounter/encounter_io.f90 @@ -231,7 +231,7 @@ module subroutine encounter_io_netcdf_write_frame_snapshot(self, history, param) class(base_parameters), intent(inout) :: param !! Current run configuration parameters ! Internals - integer(I4B) :: i, idslot, old_mode, npl, ntp + integer(I4B) :: i, idslot, old_mode, npl, ntp, tmp character(len=STRMAX) :: charstring select type(param) @@ -284,7 +284,7 @@ module subroutine encounter_io_netcdf_write_frame_snapshot(self, history, param) call netcdf_io_check( nf90_put_var(nc%id, nc%ptype_varid, charstring, start=[1, idslot], count=[NAMELEN, 1]), "encounter_io_netcdf_write_frame_snapshot nf90_put_var tp particle_type_varid" ) end do - call netcdf_io_check( nf90_set_fill(nc%id, old_mode, old_mode) ) + call netcdf_io_check( nf90_set_fill(nc%id, old_mode, tmp) ) end associate end select end select diff --git a/src/fraggle/fraggle_generate.f90 b/src/fraggle/fraggle_generate.f90 index 0dec13fde..5ec993fba 100644 --- a/src/fraggle/fraggle_generate.f90 +++ b/src/fraggle/fraggle_generate.f90 @@ -361,8 +361,6 @@ module subroutine fraggle_generate_pos_vec(collider, nbody_system, param, lfailu integer(I4B) :: i, j, loop, istart, nfrag, npl, ntp logical :: lsupercat, lhitandrun integer(I4B), parameter :: MAXLOOP = 10000 - real(DP), parameter :: cloud_size_scale_factor = 3.0_DP ! Scale factor to apply to the size of the cloud relative to the distance from the impact point. - ! A larger value puts more space between fragments initially real(DP), parameter :: rbuffer = 1.01_DP ! Body radii are inflated by this scale factor to prevent secondary collisions real(DP), parameter :: pack_density = 0.5236_DP ! packing density of loose spheres diff --git a/src/fraggle/fraggle_util.f90 b/src/fraggle/fraggle_util.f90 index 351bd05fa..19752442c 100644 --- a/src/fraggle/fraggle_util.f90 +++ b/src/fraggle/fraggle_util.f90 @@ -108,7 +108,6 @@ module subroutine fraggle_util_set_mass_dist(self, param) integer(I4B), parameter :: iMrem = 3 integer(I4B), parameter :: NFRAGMIN = iMrem + 2 !! Minimum number of fragments that can be generated integer(I4B), dimension(:), allocatable :: ind - integer(I4B), parameter :: MAXLOOP = 20 logical :: flipper logical, dimension(size(IEEE_ALL)) :: fpe_halting_modes @@ -174,7 +173,7 @@ module subroutine fraggle_util_set_mass_dist(self, param) mass(2) = impactors%mass_dist(iMslr) ! Recompute the slope parameter beta so that we span the complete size range - if (Mslr == min_mfrag) Mslr = Mslr + impactors%mass_dist(iMrem) / nfrag + if (abs(Mslr - min_mfrag) < epsilon(min_mfrag) * min_mfrag) Mslr = Mslr + impactors%mass_dist(iMrem) / nfrag mremaining = impactors%mass_dist(iMrem) ! The mass will be distributed in a power law where N>M=(M/Mslr)**(-beta/3) @@ -225,8 +224,8 @@ module subroutine fraggle_util_set_mass_dist(self, param) ! For catastrophic impacts, we will assign each of the n>2 fragments to one of the two original bodies so that the fragment cloud occupies ! roughly the same space as both original bodies. For all other disruption cases, we use body 2 as the center of the cloud. - fragments%origin_body(1) = 1 - fragments%origin_body(2) = 2 + fragments%origin_body(1) = 1_I1B + fragments%origin_body(2) = 2_I1B if (impactors%regime == COLLRESOLVE_REGIME_SUPERCATASTROPHIC) then mcumul = fragments%mass(1) flipper = .true. diff --git a/src/rmvs/rmvs_step.f90 b/src/rmvs/rmvs_step.f90 index 11f7d2756..4a5dcf3af 100644 --- a/src/rmvs/rmvs_step.f90 +++ b/src/rmvs/rmvs_step.f90 @@ -541,9 +541,8 @@ subroutine rmvs_peri_tp(tp, pl, t, dt, lfirst, inner_index, ipleP, param) integer(I4B), intent(in) :: ipleP !! index of RMVS planet being closely encountered class(swiftest_parameters), intent(in) :: param !! Current run configuration parameters ! Internals - integer(I4B) :: i, id1, id2 - real(DP) :: r2, mu, rhill2, vdotr, a, peri, capm, tperi, rpl - real(DP), dimension(NDIM) :: rh1, rh2, vh1, vh2 + integer(I4B) :: i + real(DP) :: r2, mu, rhill2, vdotr, a, peri, capm, tperi rhill2 = pl%rhill(ipleP)**2 mu = pl%Gmass(ipleP) diff --git a/src/swiftest/swiftest_module.f90 b/src/swiftest/swiftest_module.f90 index 3d35749ee..8349c12c1 100644 --- a/src/swiftest/swiftest_module.f90 +++ b/src/swiftest/swiftest_module.f90 @@ -671,11 +671,13 @@ module subroutine swiftest_io_netcdf_get_t0_values_system(self, nc, param) class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters end subroutine swiftest_io_netcdf_get_t0_values_system - module subroutine swiftest_io_netcdf_get_valid_masks(self, plmask, tpmask) + module subroutine swiftest_io_netcdf_get_valid_masks(self, plmask, tpmask, plmmask, Gmtiny) implicit none - class(swiftest_netcdf_parameters), intent(inout) :: self !! Parameters used to identify a particular NetCDF dataset - logical, dimension(:), allocatable, intent(out) :: plmask !! Logical mask indicating which bodies are massive bodies - logical, dimension(:), allocatable, intent(out) :: tpmask !! Logical mask indicating which bodies are test particles + class(swiftest_netcdf_parameters), intent(inout) :: self !! Parameters used to identify a particular NetCDF dataset + logical, dimension(:), allocatable, intent(out) :: plmask !! Logical mask indicating which bodies are massive bodies + logical, dimension(:), allocatable, intent(out) :: tpmask !! Logical mask indicating which bodies are test particles + logical, dimension(:), allocatable, intent(out), optional :: plmmask !! Logical mask indicating which bodies are fully interacting massive bodies + real(DP), intent(in), optional :: Gmtiny !! The cutoff G*mass between semi-interacting and fully interacting massive bodies end subroutine swiftest_io_netcdf_get_valid_masks module subroutine swiftest_io_netcdf_initialize_output(self, param) diff --git a/src/swiftest/swiftest_orbel.f90 b/src/swiftest/swiftest_orbel.f90 index dafb3e293..3827c1b59 100644 --- a/src/swiftest/swiftest_orbel.f90 +++ b/src/swiftest/swiftest_orbel.f90 @@ -236,7 +236,6 @@ real(DP) pure function swiftest_orbel_flon(e,icapn) real(DP), parameter :: a5 = 51891840._DP, a3 = 1037836800._DP real(DP), parameter :: b11 = 11 * a11, b9 = 9 * a9, b7 = 7 * a7 real(DP), parameter :: b5 = 5 * a5, b3 = 3 * a3 - real(DP), parameter :: THIRD = 1._DP / 3._DP ! Function to solve "Kepler's eqn" for F (here called ! x) for given e and CAPN. Only good for smallish CAPN @@ -725,7 +724,7 @@ pure elemental module subroutine swiftest_orbel_xv2aeq(mu, rx, ry, rz, vx, vy, v hz = rx*vy - ry*vx h2 = hx*hx + hy*hy + hz*hz - if (h2 == 0.0_DP) return + if (h2 < tiny(h2)) return energy = 0.5_DP * v2 - mu / r if (abs(energy * r / mu) < sqrt(TINYVALUE)) then iorbit_type = PARABOLA @@ -791,7 +790,7 @@ pure module subroutine swiftest_orbel_xv2aqt(mu, rx, ry, rz, vx, vy, vz, a, q, c hy = rz*vx - rx*vz hz = rx*vy - ry*vx h2 = hx*hx + hy*hy + hz*hz - if (h2 == 0.0_DP) return + if (h2 < tiny(h2)) return r = sqrt(rx*rx + ry*ry + rz*rz) v2 = vx*vx + vy*vy + vz*vz diff --git a/src/symba/symba_encounter_check.f90 b/src/symba/symba_encounter_check.f90 index 4bc92b79d..e66791409 100644 --- a/src/symba/symba_encounter_check.f90 +++ b/src/symba/symba_encounter_check.f90 @@ -96,11 +96,12 @@ module function symba_encounter_check_list_plpl(self, param, nbody_system, dt, i integer(I4B), intent(in) :: irec !! Current recursion level logical :: lany_encounter !! Returns true if there is at least one close encounter ! Internals - integer(I4B) :: i, j, k, lidx, nenc_enc + integer(I4B) :: i, j, nenc_enc + integer(I8B) :: k, lidx real(DP), dimension(NDIM) :: xr, vr real(DP) :: rlim2, rji2, rcrit12 logical, dimension(:), allocatable :: lencmask, lencounter - integer(I4B), dimension(:), allocatable :: eidx + integer(I8B), dimension(:), allocatable :: eidx lany_encounter = .false. if (self%nenc == 0) return @@ -116,13 +117,13 @@ module function symba_encounter_check_list_plpl(self, param, nbody_system, dt, i allocate(eidx(nenc_enc)) allocate(lencounter(nenc_enc)) - eidx(:) = pack([(k, k = 1, self%nenc)], lencmask(:)) + eidx(:) = pack([(k, k = 1_I8B, self%nenc)], lencmask(:)) lencounter(:) = .false. #ifdef DOCONLOC - do concurrent(lidx = 1:nenc_enc) shared(self,pl,eidx,lencounter,dt) local(i,j,k,xr,vr,rcrit12,rlim2,rji2) + do concurrent(lidx = 1_I8B:nenc_enc) shared(self,pl,eidx,lencounter,dt) local(i,j,k,xr,vr,rcrit12,rlim2,rji2) #else - do concurrent(lidx = 1:nenc_enc) + do concurrent(lidx = 1_I8B:nenc_enc) #endif k = eidx(lidx) i = self%index1(k) @@ -141,8 +142,8 @@ module function symba_encounter_check_list_plpl(self, param, nbody_system, dt, i lany_encounter = any(lencounter(:)) if (lany_encounter) then nenc_enc = count(lencounter(:)) - eidx(1:nenc_enc) = pack(eidx(:), lencounter(:)) - do lidx = 1, nenc_enc + eidx(1_I8B:nenc_enc) = pack(eidx(:), lencounter(:)) + do lidx = 1_I8B, nenc_enc k = eidx(lidx) i = self%index1(k) j = self%index2(k) @@ -168,11 +169,12 @@ module function symba_encounter_check_list_pltp(self, param, nbody_system, dt, i integer(I4B), intent(in) :: irec !! Current recursion level logical :: lany_encounter !! Returns true if there is at least one close encounter ! Internals - integer(I4B) :: i, j, k, lidx, nenc_enc + integer(I4B) :: i, j, nenc_enc + integer(I8B) :: k, lidx real(DP), dimension(NDIM) :: xr, vr real(DP) :: rlim2, rji2 logical, dimension(:), allocatable :: lencmask, lencounter - integer(I4B), dimension(:), allocatable :: eidx + integer(I8B), dimension(:), allocatable :: eidx lany_encounter = .false. if (self%nenc == 0) return @@ -190,12 +192,12 @@ module function symba_encounter_check_list_pltp(self, param, nbody_system, dt, i allocate(eidx(nenc_enc)) allocate(lencounter(nenc_enc)) - eidx(:) = pack([(k, k = 1, self%nenc)], lencmask(:)) + eidx(:) = pack([(k, k = 1_I8B, self%nenc)], lencmask(:)) lencounter(:) = .false. #ifdef DOCONLOC - do concurrent(lidx = 1:nenc_enc) shared(self,pl,tp,eidx,lencounter,dt) local(i,j,k,xr,vr,rlim2,rji2) + do concurrent(lidx = 1_I8B:nenc_enc) shared(self,pl,tp,eidx,lencounter,dt) local(i,j,k,xr,vr,rlim2,rji2) #else - do concurrent(lidx = 1:nenc_enc) + do concurrent(lidx = 1_I8B:nenc_enc) #endif k = eidx(lidx) i = self%index1(k) @@ -214,8 +216,8 @@ module function symba_encounter_check_list_pltp(self, param, nbody_system, dt, i lany_encounter = any(lencounter(:)) if (lany_encounter) then nenc_enc = count(lencounter(:)) - eidx(1:nenc_enc) = pack(eidx(:), lencounter(:)) - do lidx = 1, nenc_enc + eidx(1_I8B:nenc_enc) = pack(eidx(:), lencounter(:)) + do lidx = 1_I8B, nenc_enc k = eidx(lidx) i = self%index1(k) j = self%index2(k) diff --git a/src/symba/symba_kick.f90 b/src/symba/symba_kick.f90 index dc280ef1c..2db14456c 100644 --- a/src/symba/symba_kick.f90 +++ b/src/symba/symba_kick.f90 @@ -91,7 +91,8 @@ module subroutine symba_kick_getacch_tp(self, nbody_system, param, t, lbeg) real(DP), intent(in) :: t !! Current time logical, intent(in) :: lbeg !! Logical flag that determines whether or not this is the beginning or end of the step ! Internals - integer(I4B) :: i, j, k + integer(I4B) :: i, j + integer(I8B) :: k real(DP) :: rjj, fac real(DP), dimension(NDIM) :: dx @@ -142,7 +143,7 @@ module subroutine symba_kick_list_plpl(self, nbody_system, dt, irec, sgn) real(DP) :: r, rr, ri, ris, rim1, r2, ir3, fac, faci, facj real(DP), dimension(NDIM) :: dx logical, dimension(:), allocatable :: lgoodlevel - integer(I4B), dimension(:), allocatable :: good_idx + integer(I8B), dimension(:), allocatable :: good_idx if (self%nenc == 0) return @@ -170,7 +171,7 @@ module subroutine symba_kick_list_plpl(self, nbody_system, dt, irec, sgn) ngood = count(lgoodlevel(:)) if (ngood > 0_I8B) then allocate(good_idx(ngood)) - good_idx(:) = pack([(i, i = 1, nenc)], lgoodlevel(:)) + good_idx(:) = pack([(k, k = 1_I8B, nenc)], lgoodlevel(:)) #ifdef DOCONLOC do concurrent (k = 1:ngood) shared(self,pl,good_idx) local(i,j) @@ -212,7 +213,7 @@ module subroutine symba_kick_list_plpl(self, nbody_system, dt, irec, sgn) end do ngood = count(lgoodlevel(:)) if (ngood == 0_I8B) return - good_idx(1:ngood) = pack([(i, i = 1, nenc)], lgoodlevel(:)) + good_idx(1:ngood) = pack([(k, k = 1_I8B, nenc)], lgoodlevel(:)) do k = 1, ngood i = self%index1(good_idx(k)) @@ -251,7 +252,7 @@ module subroutine symba_kick_list_pltp(self, nbody_system, dt, irec, sgn) real(DP) :: r, rr, ri, ris, rim1, r2, ir3, fac, faci real(DP), dimension(NDIM) :: dx logical, dimension(:), allocatable :: lgoodlevel - integer(I4B), dimension(:), allocatable :: good_idx + integer(I8B), dimension(:), allocatable :: good_idx if (self%nenc == 0) return @@ -284,7 +285,7 @@ module subroutine symba_kick_list_pltp(self, nbody_system, dt, irec, sgn) if (ngood > 0_I8B) then allocate(good_idx(ngood)) - good_idx(:) = pack([(i, i = 1, nenc)], lgoodlevel(:)) + good_idx(:) = pack([(k, k = 1_I8B, nenc)], lgoodlevel(:)) #ifdef DOCONLOC do concurrent (k = 1_I8B:ngood) shared(self,tp,good_idx) local(j) @@ -323,7 +324,7 @@ module subroutine symba_kick_list_pltp(self, nbody_system, dt, irec, sgn) end do ngood = count(lgoodlevel(:)) if (ngood == 0_I8B) return - good_idx(1:ngood) = pack([(i, i = 1, nenc)], lgoodlevel(:)) + good_idx(1:ngood) = pack([(k, k = 1_I8B, nenc)], lgoodlevel(:)) do k = 1, ngood j = self%index2(good_idx(k)) diff --git a/src/symba/symba_step.f90 b/src/symba/symba_step.f90 index 6e72c3e95..22cdddeb6 100644 --- a/src/symba/symba_step.f90 +++ b/src/symba/symba_step.f90 @@ -27,7 +27,6 @@ module subroutine symba_step_system(self, param, t, dt) real(DP), intent(in) :: dt !! Current stepsize ! Internals logical :: lencounter - type(walltimer) :: timer1,timer2,timer3 !! Object used for computing elapsed wall time select type(pl => self%pl) class is (symba_pl) diff --git a/src/symba/symba_util.f90 b/src/symba/symba_util.f90 index 94b6aa9f5..c7abd79f3 100644 --- a/src/symba/symba_util.f90 +++ b/src/symba/symba_util.f90 @@ -71,8 +71,6 @@ module subroutine symba_util_dealloc_pl(self) implicit none ! Arguments class(symba_pl), intent(inout) :: self !! SyMBA massive body object - ! Internals - integer(I4B) :: i if (allocated(self%levelg)) deallocate(self%levelg) if (allocated(self%levelm)) deallocate(self%levelm) @@ -352,8 +350,6 @@ module subroutine symba_util_setup_pl(self, n, param) class(symba_pl), intent(inout) :: self !! SyMBA massive body object integer(I4B), intent(in) :: n !! Number of particles to allocate space for class(swiftest_parameters), intent(in) :: param !! Current run configuration parameter - ! Internals - integer(I4B) :: i !> Call allocation method for parent class. call self%helio_pl%setup(n, param) From 2ad3c7d84111128ea3aedc82611800946010f7fd Mon Sep 17 00:00:00 2001 From: David A Minton Date: Thu, 25 May 2023 12:02:39 -0400 Subject: [PATCH 48/95] Fixed bad index resulting from refactor --- src/collision/collision_resolve.f90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/collision/collision_resolve.f90 b/src/collision/collision_resolve.f90 index 3fbbbee84..0166711ab 100644 --- a/src/collision/collision_resolve.f90 +++ b/src/collision/collision_resolve.f90 @@ -601,7 +601,7 @@ module subroutine collision_resolve_plpl(self, nbody_system, param, t, dt, irec) call collision_history%take_snapshot(param,nbody_system, t, "after") - plpl_collision%status(i) = collider%status + plpl_collision%status(k) = collider%status call impactors%dealloc() end do From 7472c5cd63baccf6e583ba203de57767b5a9adb8 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Thu, 25 May 2023 14:03:11 -0400 Subject: [PATCH 49/95] Fixed problem in SyMBA where nplm was not being updated properly after massive body discards --- src/swiftest/swiftest_util.f90 | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/swiftest/swiftest_util.f90 b/src/swiftest/swiftest_util.f90 index 641fcc170..2c7b803bc 100644 --- a/src/swiftest/swiftest_util.f90 +++ b/src/swiftest/swiftest_util.f90 @@ -1678,7 +1678,10 @@ module subroutine swiftest_util_rearray_pl(self, nbody_system, param) npl = pl%nbody end if - if (npl == 0) return + if (npl == 0) then + if (param%lmtiny_pl) pl%nplm = 0 + return + end if ! Reset all of the status flags for this body pl%status(1:npl) = ACTIVE @@ -1696,6 +1699,7 @@ module subroutine swiftest_util_rearray_pl(self, nbody_system, param) elsewhere pl%info(1:npl)%particle_type = PL_TYPE_NAME end where + pl%nplm = count(.not.pl%lmtiny(1:npl)) end if ! Reindex the new list of bodies From d46bec6186f90b241b1a71e991c83a73c1bade86 Mon Sep 17 00:00:00 2001 From: David Minton Date: Fri, 26 May 2023 12:41:37 -0400 Subject: [PATCH 50/95] Restructured Docker and Singularity scripts. Added new GNU version of the Docker container that is smaller than the Intel one (but also slower). --- docker/.gitignore | 13 ++++++-- docker/bin/.gitignore | 1 - docker/gnu/Dockerfile | 44 ++++++++++++++++++++++++++++ docker/gnu/bin/.gitignore | 0 docker/{ => gnu}/bin/swiftest_driver | 2 +- docker/install.sh | 5 ++++ docker/{ => intel}/Dockerfile | 0 docker/pull | 2 -- singularity/.gitignore | 5 ++-- singularity/bin/.gitignore | 1 - singularity/install.sh | 9 ++++++ singularity/pull | 2 -- singularity/setenv.sh | 7 +++-- singularity/swiftest.def | 2 -- 14 files changed, 76 insertions(+), 17 deletions(-) delete mode 100644 docker/bin/.gitignore create mode 100644 docker/gnu/Dockerfile create mode 100644 docker/gnu/bin/.gitignore rename docker/{ => gnu}/bin/swiftest_driver (62%) create mode 100755 docker/install.sh rename docker/{ => intel}/Dockerfile (100%) delete mode 100755 docker/pull delete mode 100644 singularity/bin/.gitignore create mode 100755 singularity/install.sh delete mode 100755 singularity/pull delete mode 100644 singularity/swiftest.def diff --git a/docker/.gitignore b/docker/.gitignore index 825a38873..215dd3f04 100644 --- a/docker/.gitignore +++ b/docker/.gitignore @@ -1,3 +1,10 @@ -!Dockerfile -!bin/ -!pull +* +!.gitignore +!install.sh +!gnu/ +!gnu/Dockerfile +!/gnu/bin/ +!/gnu/bin/swiftest_driver +!intel/ +!intel/Dockerfile +!/intel/bin/swiftest_driver diff --git a/docker/bin/.gitignore b/docker/bin/.gitignore deleted file mode 100644 index c1d7ed39d..000000000 --- a/docker/bin/.gitignore +++ /dev/null @@ -1 +0,0 @@ -!swiftest_driver diff --git a/docker/gnu/Dockerfile b/docker/gnu/Dockerfile new file mode 100644 index 000000000..ec64211bd --- /dev/null +++ b/docker/gnu/Dockerfile @@ -0,0 +1,44 @@ +FROM debian:stable-slim as build + +# kick everything off +RUN apt-get update && apt-get upgrade -y && \ + DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + ca-certificates curl git build-essential gfortran && \ + apt-get update && apt-get upgrade -y && \ + rm -rf /var/lib/apt/lists/* + +# Get CMAKE and install it +RUN mkdir -p /opt/cmake/build && \ + cd /opt/cmake/build && \ + curl -LO https://github.com/Kitware/CMake/releases/download/v3.26.2/cmake-3.26.2-linux-x86_64.sh && \ + /bin/bash cmake-3.26.2-linux-x86_64.sh --prefix=/usr/local --skip-license + +# Get dependencies +RUN apt-get update && apt-get upgrade -y && \ + DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + libnetcdf-dev libnetcdff-dev libcoarrays-dev libcoarrays-mpich-dev&& \ + rm -rf /var/lib/apt/lists/* + +ENV NETCDF_HOME="/usr" +ENV NETCDF_FORTRAN_HOME="/usr" +ENV INDIR="/opt/dist//usr/local" + +# Get Swiftest source code +RUN cd /opt/ && \ + git clone -b debug https://github.com/carlislewishard/swiftest.git && \ + cd swiftest && \ + mkdir build && \ + cd build && \ + cmake .. -DCMAKE_PREFIX_PATH="${INDIR}" -DCMAKE_INSTALL_PREFIX="${INDIR}" -DCONTAINERIZE=ON -DCMAKE_BUILD_TYPE=release && \ + make && \ + make install + +#Production container +FROM debian:stable-slim +COPY --from=build /opt/dist / +RUN apt-get update && apt-get upgrade -y && \ + DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + ca-certificates gfortran libnetcdf-dev libnetcdff-dev && \ + rm -rf /var/lib/apt/lists/* + +ENTRYPOINT ["/usr/local/bin/swiftest_driver"] \ No newline at end of file diff --git a/docker/gnu/bin/.gitignore b/docker/gnu/bin/.gitignore new file mode 100644 index 000000000..e69de29bb diff --git a/docker/bin/swiftest_driver b/docker/gnu/bin/swiftest_driver similarity index 62% rename from docker/bin/swiftest_driver rename to docker/gnu/bin/swiftest_driver index d2cb42a90..f0a3638dd 100755 --- a/docker/bin/swiftest_driver +++ b/docker/gnu/bin/swiftest_driver @@ -1,2 +1,2 @@ #!/bin/sh -- -docker run -v $(pwd):$(pwd) -w $(pwd) -t -e OMP_NUM_THREADS -e FOR_COARRAY_NUM_IMAGES swiftest:latest "$@" +docker run -v $(pwd):$(pwd) -w $(pwd) -t -e OMP_NUM_THREADS -e FOR_COARRAY_NUM_IMAGES swiftest_driver:gnu "$@" diff --git a/docker/install.sh b/docker/install.sh new file mode 100755 index 000000000..82e97d58f --- /dev/null +++ b/docker/install.sh @@ -0,0 +1,5 @@ +#!/bin/sh -- +tag=${1:-intel} +echo "Installing swiftest_driver:${tag} container and executable script" +docker pull daminton/swiftest_driver:${tag} +cp -rf ${tag}/bin/swiftest_driver ../bin/ \ No newline at end of file diff --git a/docker/Dockerfile b/docker/intel/Dockerfile similarity index 100% rename from docker/Dockerfile rename to docker/intel/Dockerfile diff --git a/docker/pull b/docker/pull deleted file mode 100755 index 2367ba639..000000000 --- a/docker/pull +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -- -docker pull daminton/swiftest:latest \ No newline at end of file diff --git a/singularity/.gitignore b/singularity/.gitignore index abc0e7f03..2a259d270 100644 --- a/singularity/.gitignore +++ b/singularity/.gitignore @@ -1,3 +1,4 @@ -!swiftest.def !bin/ -!pull +!bin/swiftest_driver +!install.sh +!setenv.sh diff --git a/singularity/bin/.gitignore b/singularity/bin/.gitignore deleted file mode 100644 index c1d7ed39d..000000000 --- a/singularity/bin/.gitignore +++ /dev/null @@ -1 +0,0 @@ -!swiftest_driver diff --git a/singularity/install.sh b/singularity/install.sh new file mode 100755 index 000000000..ef3eb1b9e --- /dev/null +++ b/singularity/install.sh @@ -0,0 +1,9 @@ +#!/bin/sh -- +# This will install the Singularity container version of the swiftest_driver in place of the native compiled version into ../bin. +# In order to use the executable script, the SWIFTEST_SIF environment variable must be set to point to the location of swiftest_driver.sif, which requires this script to be called via source: +# $ . ./install.sh +# +tag=${1:-intel} +singularity pull --force swiftest_driver.sif docker://daminton/swiftest_driver:${tag} +cp -rf bin/swiftest_driver ../bin/ +source ./setenv.sh \ No newline at end of file diff --git a/singularity/pull b/singularity/pull deleted file mode 100755 index a62acaf6e..000000000 --- a/singularity/pull +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -- -singularity pull --force swiftest.sif docker://daminton/swiftest:latest diff --git a/singularity/setenv.sh b/singularity/setenv.sh index 79931a298..308d49151 100755 --- a/singularity/setenv.sh +++ b/singularity/setenv.sh @@ -1,3 +1,4 @@ -#!/bin/sh -# source this file to set the path to the swiftest.sif file -export SWIFTEST_SIF="${PWD}/swiftest.sif" +#!/bin/sh -- +# This will set the SWIFTEST_SIF environment variable as long as it is executed by source. +# $ . ./setenvl.sh +export SWIFTEST_SIF="${PWD}/swiftest_driver.sif" \ No newline at end of file diff --git a/singularity/swiftest.def b/singularity/swiftest.def deleted file mode 100644 index ce6c10f63..000000000 --- a/singularity/swiftest.def +++ /dev/null @@ -1,2 +0,0 @@ -Bootstrap: docker -From: daminton/swiftest:latest \ No newline at end of file From 64d6a304a481dde06a4281c5c76019811a902023 Mon Sep 17 00:00:00 2001 From: David Minton Date: Fri, 26 May 2023 13:13:36 -0400 Subject: [PATCH 51/95] Fixed typos and added some output --- docker/install.sh | 2 +- singularity/install.sh | 1 + singularity/setenv.sh | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/docker/install.sh b/docker/install.sh index 82e97d58f..f81e95e57 100755 --- a/docker/install.sh +++ b/docker/install.sh @@ -1,5 +1,5 @@ #!/bin/sh -- tag=${1:-intel} -echo "Installing swiftest_driver:${tag} container and executable script" +echo "Installing swiftest_driver:${tag} Docker container and executable script" docker pull daminton/swiftest_driver:${tag} cp -rf ${tag}/bin/swiftest_driver ../bin/ \ No newline at end of file diff --git a/singularity/install.sh b/singularity/install.sh index ef3eb1b9e..50d6d56df 100755 --- a/singularity/install.sh +++ b/singularity/install.sh @@ -4,6 +4,7 @@ # $ . ./install.sh # tag=${1:-intel} +echo "Installing swiftest_driver.sif Singularity container and executable script from swiftest_driver:${tag} Docker container" singularity pull --force swiftest_driver.sif docker://daminton/swiftest_driver:${tag} cp -rf bin/swiftest_driver ../bin/ source ./setenv.sh \ No newline at end of file diff --git a/singularity/setenv.sh b/singularity/setenv.sh index 308d49151..cc8905033 100755 --- a/singularity/setenv.sh +++ b/singularity/setenv.sh @@ -1,4 +1,4 @@ #!/bin/sh -- # This will set the SWIFTEST_SIF environment variable as long as it is executed by source. -# $ . ./setenvl.sh +# $ . ./setenv.sh export SWIFTEST_SIF="${PWD}/swiftest_driver.sif" \ No newline at end of file From 6cce4f023b86f795370b149c8f8d0c0b2427bf94 Mon Sep 17 00:00:00 2001 From: David Minton Date: Fri, 26 May 2023 13:17:17 -0400 Subject: [PATCH 52/95] Removed unneeeded "container" argument because now the install.sh scripts will replace the executable with a script that calls the container --- python/swiftest/swiftest/simulation_class.py | 31 ++------------------ 1 file changed, 3 insertions(+), 28 deletions(-) diff --git a/python/swiftest/swiftest/simulation_class.py b/python/swiftest/swiftest/simulation_class.py index 10a869ec1..8971b897a 100644 --- a/python/swiftest/swiftest/simulation_class.py +++ b/python/swiftest/swiftest/simulation_class.py @@ -91,8 +91,6 @@ def __init__(self,read_param: bool = False, integrator : {"symba","rmvs","whm","helio"}, default "symba" Name of the n-body integrator that will be used when executing a run. Parameter input file equivalent: None - container : {"docker", "singularity"}, default None - Specify whether the driver exectuable is run from a Docker or Singularity container. Setting to `None` read_param : bool, default False Read the parameter file given by `param_file`. param_file : str, path-like, or file-lke, default "param.in" @@ -340,7 +338,6 @@ def __init__(self,read_param: bool = False, self.init_cond = xr.Dataset() self.encounters = xr.Dataset() self.collisions = xr.Dataset() - self.container = None # Set the location of the parameter input file, choosing the default if it isn't specified. self.simdir = Path.cwd() / Path(simdir) @@ -408,8 +405,6 @@ def _run_swiftest_driver(self): # Get current environment variables env = os.environ.copy() - if self.container == "SINGULARITY" and "SWIFTEST_SIF" not in env: - env['SWIFTEST_SIF'] = Path(self.binary_source).parent.parent / "swiftest.sif" cmd = f"{env['SHELL']} -l {self.driver_script}" @@ -835,7 +830,6 @@ def set_parameter(self, verbose: bool = True, **kwargs): "encounter_save" : "NONE", "coarray" : False, "simdir" : self.simdir, - "container" : None, } param_file = kwargs.pop("param_file",None) @@ -899,7 +893,6 @@ def get_parameter(self, **kwargs): def set_integrator(self, codename: None | Literal["Swiftest", "Swifter", "Swift"] = "Swiftest", integrator: Literal["symba","rmvs","whm","helio"] | None = None, - container: Literal["docker", "singularity"] | None = None, mtiny: float | None = None, gmtiny: float | None = None, verbose: bool | None = None, @@ -912,10 +905,6 @@ def set_integrator(self, codename : {"swiftest", "swifter", "swift"}, optional integrator : {"symba","rmvs","whm","helio"}, optional Name of the n-body integrator that will be used when executing a run. - container : {"docker", "singularity"}, default None - Specify whether the driver exectuable is run from a Docker or Singularity container. - Setting to `None` uses the local executable. - *Note*: Only valid for Swiftest. mtiny : float, optional The minimum mass of fully interacting bodies. Bodies below this mass interact with the larger bodies, but not each other (SyMBA only). *Note.* Only mtiny or gmtiny is accepted, not both. @@ -938,14 +927,6 @@ def set_integrator(self, update_list = [] - if container is not None: - valid_container = ["DOCKER", "SINGULARITY"] - if container.upper() not in valid_container: - warnings.warn(f"{container} is not a valid container type. Valid options are None, ",",".join(valid_container),stacklevel=2) - self.container = None - else: - self.container = container.upper() - if codename is not None: valid_codename = ["Swiftest", "Swifter", "Swift"] if codename.title() not in valid_codename: @@ -960,13 +941,7 @@ def set_integrator(self, self.param['! VERSION'] = f"{self.codename} input file" update_list.append("codename") if self.codename == "Swiftest": - if self.container is None: - self.binary_source = Path(_pyfile).parent.parent.parent.parent / "bin" / "swiftest_driver" - elif self.container == "DOCKER": - self.binary_source = Path(_pyfile).parent.parent.parent.parent / "docker" / "bin" / "swiftest_driver" - elif self.container == "SINGULARITY": - self.binary_source = Path(_pyfile).parent.parent.parent.parent / "singularity" / "bin" / "swiftest_driver" - + self.binary_source = Path(_pyfile).parent.parent.parent.parent / "bin" / "swiftest_driver" self.binary_path = self.simdir.resolve() self.driver_executable = self.binary_path / "swiftest_driver" if not self.binary_source.exists(): @@ -1041,8 +1016,8 @@ def get_integrator(self,arg_list: str | List[str] | None = None, verbose: bool | valid_instance_vars = {"codename": self.codename, "integrator": self.integrator, "param_file": str(self.param_file), - "driver_executable": str(self.driver_executable), - "container": self.container} + "driver_executable": str(self.driver_executable) + } try: self.integrator From 0e130018452e8703e8f9c33b1efcf4a133c2c175 Mon Sep 17 00:00:00 2001 From: David Minton Date: Fri, 26 May 2023 13:46:52 -0400 Subject: [PATCH 53/95] Added documentation for container versions --- README.md | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 033d86834..60893055f 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,9 @@ Swiftest also includes the collisional fragmentation algorithm **Fraggle**, an a #### Installation -**System Requirements** +In order to use Swiftest, you need to have a working `swiftest_driver` executable. Currently, this can be obtained by either compiling the source code on the system you plan to run simulations on (fastest), or by running it from a Docker/Singularity container compiled for an x86_64 CPU using the Intel Fortran compiler (slower) or compiled using the GNU/gfortran compiler (slowest). + +**Building the `swiftest_driver` executable** Swiftest is designed to be downloaded, compiled, and run on a Linux based system. It is untested on Windows systems. @@ -103,6 +105,29 @@ $ make The Swiftest executable, called ```swiftest_driver```, should now be created in the ```/swiftest/bin/``` directory. +**Download the `swiftest_driver` as a Docker or Singularity container. + +The Swiftest driver is available as a Docker container on DockerHub in two versions: Intel and GNU. The Intel version was compiled for the x86_64 CPU using the Intel classic Fortran compiler. The GNU version was compliled for the x86_64 CPU using gfortran. The Intel version is faster than the GNU version (though not as fast as a native compile to the target CPU that you wish to run it on due to vectorization optimizations that Swiftest takes advantage of), however it is much larger: The Intel version is ~2.7GB while the GNU version is ~300MB. The Singularity container pulls from the same DockerHub container. + +To facilitate installation of the container, we provide a set of shell scripts to help automate the process of installing container versions of the executable. To install the default Intel version of the docker container from within the `swiftest\` project directory + +``` +$ cd docker +$ . ./install.sh +``` + +To install the GNU version: + +``` +$ cd docker +$ . ./install.sh gnu +``` + +The Singularity versions are installed the same way, just replace `cd docker` with `cd singularity` above. + +Whether installing either the Docker or Singularity containers, the install script will copy an executable shell script `swiftest_driver` into `swiftest/bin/`. Not that when installing the Singularity container, the install script will set an environment variable called `SWIFTEST_SIF` that must point to the aboslute path of the container file called `swiftest_driver.sif`. To use the driver script in a future shell, rather than running the install script again, we suggest adding the environment variable definition to your shell startup script (e.g. add `export SWIFTEST_SIF="/path/to/swiftest/singularity/swiftest.sif"` to your `.zshrc`) + + **Swiftest Python Package** Included with Swiftest, in the ```/swiftest/python/swiftest/``` directory, is a Python package designed to facilitate seamless data processing and analysis. The Python package, also called Swiftest, can be used to generate input files, run Swiftest simulations, and process output files in the NetCDF file format. From b17b360c008246d393ea298a2b92115e56c6030b Mon Sep 17 00:00:00 2001 From: David Minton Date: Fri, 26 May 2023 13:49:00 -0400 Subject: [PATCH 54/95] Fixed typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 60893055f..3671832cb 100644 --- a/README.md +++ b/README.md @@ -105,7 +105,7 @@ $ make The Swiftest executable, called ```swiftest_driver```, should now be created in the ```/swiftest/bin/``` directory. -**Download the `swiftest_driver` as a Docker or Singularity container. +**Download the `swiftest_driver` as a Docker or Singularity container.** The Swiftest driver is available as a Docker container on DockerHub in two versions: Intel and GNU. The Intel version was compiled for the x86_64 CPU using the Intel classic Fortran compiler. The GNU version was compliled for the x86_64 CPU using gfortran. The Intel version is faster than the GNU version (though not as fast as a native compile to the target CPU that you wish to run it on due to vectorization optimizations that Swiftest takes advantage of), however it is much larger: The Intel version is ~2.7GB while the GNU version is ~300MB. The Singularity container pulls from the same DockerHub container. From acf1bb8d5a58ee5e0d9d5b676cafc41e077d3d83 Mon Sep 17 00:00:00 2001 From: David Minton Date: Sun, 4 Jun 2023 16:20:50 -0400 Subject: [PATCH 55/95] Set up new Docker container to run the driver and Python packages. Still needs testing. --- CMakeLists.txt | 7 +- Dockerfile | 191 ++++++++++++++++++++++++++++ cmake/Modules/FindNETCDF.cmake | 11 +- cmake/Modules/SetFortranFlags.cmake | 21 ++- src/CMakeLists.txt | 15 +-- swiftest.sh | 3 + 6 files changed, 230 insertions(+), 18 deletions(-) create mode 100644 Dockerfile create mode 100755 swiftest.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index 37cda5709..08ec7c9e2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,10 +32,15 @@ OPTION(USE_COARRAY "Use Coarray Fortran for parallelization of test particles" O 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) +OPTION(BUILD_SHARED_LIBS "Build using shared libraries" ON) -# Locate and set parallelization libraries. There are some CMake peculiarities +# Locate and set external libraries. There are some CMake peculiarities # taken care of here, such as the fact that the FindOpenMP routine doesn't know # about Fortran. +IF (NOT BUILD_SHARED_LIBS) + set(CMAKE_FIND_LIBRARY_SUFFIXES ".a" ".so") +ENDIF () + INCLUDE(${CMAKE_MODULE_PATH}/SetParallelizationLibrary.cmake) INCLUDE(${CMAKE_MODULE_PATH}/SetUpNetCDF.cmake) INCLUDE(${CMAKE_MODULE_PATH}/SetMKL.cmake) diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..53a5ce831 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,191 @@ +FROM ubuntu:20.04 as build + +# kick everything off +RUN apt-get update && apt-get upgrade -y && \ + DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + ca-certificates curl git wget gpg-agent software-properties-common build-essential gnupg pkg-config && \ + rm -rf /var/lib/apt/lists/* + +# Get CMAKE and install it +RUN mkdir -p cmake/build && \ + cd cmake/build && \ + curl -LO https://github.com/Kitware/CMake/releases/download/v3.26.2/cmake-3.26.2-linux-x86_64.sh && \ + /bin/bash cmake-3.26.2-linux-x86_64.sh --prefix=/usr/local --skip-license + +# Get the Intel compilers +# download the key to system keyring +RUN wget -O- https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB \ +| gpg --dearmor | tee /usr/share/keyrings/oneapi-archive-keyring.gpg > /dev/null +# add signed entry to apt sources and configure the APT client to use Intel repository: +RUN echo "deb [signed-by=/usr/share/keyrings/oneapi-archive-keyring.gpg] https://apt.repos.intel.com/oneapi all main" | tee /etc/apt/sources.list.d/oneAPI.list +RUN apt-get -y update && apt-get upgrade -y +RUN apt-get install -y intel-hpckit + +# Set Intel compiler environment variables +ENV INTEL_DIR="/opt/intel/oneapi" +ENV LANG=C.UTF-8 +ENV ACL_BOARD_VENDOR_PATH='/opt/Intel/OpenCLFPGA/oneAPI/Boards' +ENV ADVISOR_2023_DIR='/opt/intel/oneapi/advisor/2023.1.0' +ENV APM='/opt/intel/oneapi/advisor/2023.1.0/perfmodels' +ENV CCL_CONFIGURATION='cpu_gpu_dpcpp' +ENV CCL_ROOT='/opt/intel/oneapi/ccl/2021.9.0' +ENV CLASSPATH='/opt/intel/oneapi/mpi/2021.9.0//lib/mpi.jar:/opt/intel/oneapi/dal/2023.1.0/lib/onedal.jar' +ENV CLCK_ROOT='/opt/intel/oneapi/clck/2021.7.3' +ENV CMAKE_PREFIX_PATH='/opt/intel/oneapi/tbb/2021.9.0/env/..:/opt/intel/oneapi/dnnl/2023.1.0/cpu_dpcpp_gpu_dpcpp/../lib/cmake:/opt/intel/oneapi/dal/2023.1.0:/opt/intel/oneapi/compiler/2023.1.0/linux/IntelDPCPP:/opt/intel/oneapi/ccl/2021.9.0/lib/cmake/oneCCL' +ENV CMPLR_ROOT='/opt/intel/oneapi/compiler/2023.1.0' +ENV CPATH='/opt/intel/oneapi/tbb/2021.9.0/env/../include:/opt/intel/oneapi/mpi/2021.9.0//include:/opt/intel/oneapi/mkl/2023.1.0/include:/opt/intel/oneapi/ippcp/2021.7.0/include:/opt/intel/oneapi/ipp/2021.8.0/include:/opt/intel/oneapi/dpl/2022.1.0/linux/include:/opt/intel/oneapi/dnnl/2023.1.0/cpu_dpcpp_gpu_dpcpp/include:/opt/intel/oneapi/dev-utilities/2021.9.0/include:/opt/intel/oneapi/dal/2023.1.0/include:/opt/intel/oneapi/ccl/2021.9.0/include/cpu_gpu_dpcpp' +ENV CPLUS_INCLUDE_PATH='/opt/intel/oneapi/clck/2021.7.3/include' +ENV DAALROOT='/opt/intel/oneapi/dal/2023.1.0' +ENV DALROOT='/opt/intel/oneapi/dal/2023.1.0' +ENV DAL_MAJOR_BINARY='1' +ENV DAL_MINOR_BINARY='1' +ENV DIAGUTIL_PATH='/opt/intel/oneapi/vtune/2023.1.0/sys_check/vtune_sys_check.py:/opt/intel/oneapi/debugger/2023.1.0/sys_check/debugger_sys_check.py:/opt/intel/oneapi/compiler/2023.1.0/sys_check/sys_check.sh:/opt/intel/oneapi/advisor/2023.1.0/sys_check/advisor_sys_check.py:' +ENV DNNLROOT='/opt/intel/oneapi/dnnl/2023.1.0/cpu_dpcpp_gpu_dpcpp' +ENV DPL_ROOT='/opt/intel/oneapi/dpl/2022.1.0' +ENV FI_PROVIDER_PATH='/opt/intel/oneapi/mpi/2021.9.0//libfabric/lib/prov:/usr/lib64/libfabric' +ENV FPGA_VARS_ARGS='' +ENV FPGA_VARS_DIR='/opt/intel/oneapi/compiler/2023.1.0/linux/lib/oclfpga' +ENV GDB_INFO='/opt/intel/oneapi/debugger/2023.1.0/documentation/info/' +ENV INFOPATH='/opt/intel/oneapi/debugger/2023.1.0/gdb/intel64/lib' +ENV INSPECTOR_2023_DIR='/opt/intel/oneapi/inspector/2023.1.0' +ENV INTELFPGAOCLSDKROOT='/opt/intel/oneapi/compiler/2023.1.0/linux/lib/oclfpga' +ENV INTEL_LICENSE_FILE='/opt/intel/licenses:/root/intel/licenses:/opt/intel/oneapi/clck/2021.7.3/licensing:/opt/intel/licenses:/root/intel/licenses:/Users/Shared/Library/Application Support/Intel/Licenses' +ENV INTEL_PYTHONHOME='/opt/intel/oneapi/debugger/2023.1.0/dep' +ENV IPPCP_TARGET_ARCH='intel64' +ENV IPPCRYPTOROOT='/opt/intel/oneapi/ippcp/2021.7.0' +ENV IPPROOT='/opt/intel/oneapi/ipp/2021.8.0' +ENV IPP_TARGET_ARCH='intel64' +ENV I_MPI_ROOT='/opt/intel/oneapi/mpi/2021.9.0' +ENV LD_LIBRARY_PATH='/opt/intel/oneapi/tbb/2021.9.0/env/../lib/intel64/gcc4.8:/opt/intel/oneapi/mpi/2021.9.0//libfabric/lib:/opt/intel/oneapi/mpi/2021.9.0//lib/release:/opt/intel/oneapi/mpi/2021.9.0//lib:/opt/intel/oneapi/mkl/2023.1.0/lib/intel64:/opt/intel/oneapi/itac/2021.9.0/slib:/opt/intel/oneapi/ippcp/2021.7.0/lib/intel64:/opt/intel/oneapi/ipp/2021.8.0/lib/intel64:/opt/intel/oneapi/dnnl/2023.1.0/cpu_dpcpp_gpu_dpcpp/lib:/opt/intel/oneapi/debugger/2023.1.0/gdb/intel64/lib:/opt/intel/oneapi/debugger/2023.1.0/libipt/intel64/lib:/opt/intel/oneapi/debugger/2023.1.0/dep/lib:/opt/intel/oneapi/dal/2023.1.0/lib/intel64:/opt/intel/oneapi/compiler/2023.1.0/linux/lib:/opt/intel/oneapi/compiler/2023.1.0/linux/lib/x64:/opt/intel/oneapi/compiler/2023.1.0/linux/lib/oclfpga/host/linux64/lib:/opt/intel/oneapi/compiler/2023.1.0/linux/compiler/lib/intel64_lin:/opt/intel/oneapi/ccl/2021.9.0/lib/cpu_gpu_dpcpp' +ENV LIBRARY_PATH='/opt/intel/oneapi/tbb/2021.9.0/env/../lib/intel64/gcc4.8:/opt/intel/oneapi/mpi/2021.9.0//libfabric/lib:/opt/intel/oneapi/mpi/2021.9.0//lib/release:/opt/intel/oneapi/mpi/2021.9.0//lib:/opt/intel/oneapi/mkl/2023.1.0/lib/intel64:/opt/intel/oneapi/ippcp/2021.7.0/lib/intel64:/opt/intel/oneapi/ipp/2021.8.0/lib/intel64:/opt/intel/oneapi/dnnl/2023.1.0/cpu_dpcpp_gpu_dpcpp/lib:/opt/intel/oneapi/dal/2023.1.0/lib/intel64:/opt/intel/oneapi/compiler/2023.1.0/linux/compiler/lib/intel64_lin:/opt/intel/oneapi/compiler/2023.1.0/linux/lib:/opt/intel/oneapi/clck/2021.7.3/lib/intel64:/opt/intel/oneapi/ccl/2021.9.0/lib/cpu_gpu_dpcpp' +ENV MANPATH='/opt/intel/oneapi/mpi/2021.9.0/man:/opt/intel/oneapi/itac/2021.9.0/man:/opt/intel/oneapi/debugger/2023.1.0/documentation/man:/opt/intel/oneapi/compiler/2023.1.0/documentation/en/man/common:/opt/intel/oneapi/clck/2021.7.3/man::' +ENV MKLROOT='/opt/intel/oneapi/mkl/2023.1.0' +ENV NLSPATH='/opt/intel/oneapi/mkl/2023.1.0/lib/intel64/locale/%l_%t/%N:/opt/intel/oneapi/compiler/2023.1.0/linux/compiler/lib/intel64_lin/locale/%l_%t/%N' +ENV OCL_ICD_FILENAMES='libintelocl_emu.so:libalteracl.so:/opt/intel/oneapi/compiler/2023.1.0/linux/lib/x64/libintelocl.so' +ENV ONEAPI_ROOT='/opt/intel/oneapi' +ENV PATH='/opt/intel/oneapi/vtune/2023.1.0/bin64:/opt/intel/oneapi/mpi/2021.9.0//libfabric/bin:/opt/intel/oneapi/mpi/2021.9.0//bin:/opt/intel/oneapi/mkl/2023.1.0/bin/intel64:/opt/intel/oneapi/itac/2021.9.0/bin:/opt/intel/oneapi/inspector/2023.1.0/bin64:/opt/intel/oneapi/dev-utilities/2021.9.0/bin:/opt/intel/oneapi/debugger/2023.1.0/gdb/intel64/bin:/opt/intel/oneapi/compiler/2023.1.0/linux/lib/oclfpga/bin:/opt/intel/oneapi/compiler/2023.1.0/linux/bin/intel64:/opt/intel/oneapi/compiler/2023.1.0/linux/bin:/opt/intel/oneapi/clck/2021.7.3/bin/intel64:/opt/intel/oneapi/advisor/2023.1.0/bin64:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin' +ENV PKG_CONFIG_PATH='/opt/intel/oneapi/vtune/2023.1.0/include/pkgconfig/lib64:/opt/intel/oneapi/tbb/2021.9.0/env/../lib/pkgconfig:/opt/intel/oneapi/mpi/2021.9.0/lib/pkgconfig:/opt/intel/oneapi/mkl/2023.1.0/lib/pkgconfig:/opt/intel/oneapi/ippcp/2021.7.0/lib/pkgconfig:/opt/intel/oneapi/inspector/2023.1.0/include/pkgconfig/lib64:/opt/intel/oneapi/dpl/2022.1.0/lib/pkgconfig:/opt/intel/oneapi/dnnl/2023.1.0/cpu_dpcpp_gpu_dpcpp/../lib/pkgconfig:/opt/intel/oneapi/dal/2023.1.0/lib/pkgconfig:/opt/intel/oneapi/compiler/2023.1.0/lib/pkgconfig:/opt/intel/oneapi/ccl/2021.9.0/lib/pkgconfig:/opt/intel/oneapi/advisor/2023.1.0/include/pkgconfig/lib64:' +ENV PYTHONPATH='/opt/intel/oneapi/advisor/2023.1.0/pythonapi' +ENV SETVARS_COMPLETED='1' +ENV TBBROOT='/opt/intel/oneapi/tbb/2021.9.0/env/..' +ENV VTUNE_PROFILER_2023_DIR='/opt/intel/oneapi/vtune/2023.1.0' +ENV VTUNE_PROFILER_DIR='/opt/intel/oneapi/vtune/2023.1.0' +ENV VT_ADD_LIBS='-ldwarf -lelf -lvtunwind -lm -lpthread' +ENV VT_LIB_DIR='/opt/intel/oneapi/itac/2021.9.0/lib' +ENV VT_MPI='impi4' +ENV VT_ROOT='/opt/intel/oneapi/itac/2021.9.0' +ENV VT_SLIB_DIR='/opt/intel/oneapi/itac/2021.9.0/slib' + +# Set HDF5 and NetCDF-specific Environment variables +ENV INSTALL_DIR="/usr/local" +ENV LIB_DIR="${INSTALL_DIR}/lib" +ENV LD_LIBRARY_PATH=${LIB_DIR}:${LD_LIBRARY_PATH} +RUN mkdir -p ${LIB_DIR} + +ENV CC="${INTEL_DIR}/compiler/latest/linux/bin/icx-cc" +ENV FC="${INTEL_DIR}/compiler/latest/linux/bin/ifx" +ENV CXX="${INTEL_DIR}/compiler/latest/linux/bin/icpx" +ENV LDFLAGS="-L${LIB_DIR}" +ENV NCDIR="${INSTALL_DIR}" +ENV NFDIR="${INSTALL_DIR}" +ENV HDF5_ROOT="${INSTALL_DIR}" +ENV HDF5_LIBDIR="${HDF5_ROOT}/lib" +ENV HDF5_INCLUDE_DIR="${HDF5_ROOT}/include" +ENV HDF5_PLUGIN_PATH="${HDF5_LIBDIR}/plugin" + +# Get the HDF5, NetCDF-C and NetCDF-Fortran libraries +RUN wget -qO- https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.14/hdf5-1.14.1/bin/unix/hdf5-1.14.1-2-Std-ubuntu2004_64-Intel.tar.gz | tar xvz +RUN wget -qO- https://github.com/Unidata/netcdf-c/archive/refs/tags/v4.9.2.tar.gz | tar xvz +RUN wget -qO- https://github.com/Unidata/netcdf-fortran/archive/refs/tags/v4.6.1.tar.gz | tar xvz +RUN wget -qO- https://www.zlib.net/zlib-1.2.13.tar.gz | tar xvz + +# Install dependencies +RUN apt-get update && apt-get upgrade -y && \ + DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + libxml2-dev libcurl4-gnutls-dev libzstd-dev libbz2-dev libaec-dev m4 && \ + rm -rf /var/lib/apt/lists/* + +# Install HDF5 +RUN cd hdf && \ + ./HDF5-1.14.1-Linux.sh --skip-license && \ + cp -R HDF_Group/HDF5/1.14.1/lib/*.a ${HDF5_ROOT}/lib/ && \ + cp -R HDF_Group/HDF5/1.14.1/include/* ${HDF5_ROOT}/include/ + +RUN cp zlib-1.2.13/zlib.h ${HDF5_INCLUDE_DIR}/ + +ENV LD_LIBRARY_PATH="/lib/x86_64-linux-gnu:${LD_LIBRARY_PATH}" +ENV LDFLAGS="-static-intel -lhdf5_hl -lhdf5 -lsz -lm -lz -lzstd -lbz2 -lcurl -lxml2" +RUN cd netcdf-c-4.9.2 && \ + cmake -S . -B build -DCMAKE_PREFIX_PATH="${INSTALL_DIR}" \ + -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} \ + -DCMAKE_POSITION_INDEPENDENT_CODE=ON \ + -DBUILD_SHARED_LIBS=OFF && \ + cmake --build build && \ + cmake --install build + +# NetCDF-Fortran library +ENV F77=${FC} +ENV CFLAGS="-fPIC" +ENV FCFLAGS=${CFLAGS} +ENV FFLAGS=${CFLAGS} +ENV CPPFLAGS="-I${INSTALL_DIR}/include -I/usr/include -I/usr/include/x86_64-linux-gnu/curl" +ENV LDFLAGS="-static-intel" +ENV LIBS="-L/usr/local/lib -L/usr/lib/x86_64-linux-gnu -lnetcdf -lhdf5_hl -lhdf5 -lsz -lm -lz -lzstd -lbz2 -lcurl -lxml2" +RUN cd netcdf-fortran-4.6.1 && \ + ./configure --disable-shared --prefix=${NFDIR} && \ + make && \ + make install + +# # Swiftest +ENV NETCDF_HOME=${INSTALL_DIR} +ENV NETCDF_FORTRAN_HOME=${NETCDF_HOME} +ENV NETCDF_LIBRARY=${NETCDF_HOME} +ENV FC="${INTEL_DIR}/mpi/latest/bin/mpiifort" +ENV LDFLAGS="-L/usr/local/lib -L/usr/lib/x86_64-linux-gnu -lnetcdff -lnetcdf -lhdf5_hl -lhdf5 -lsz -lz -lzstd -lbz2 -lcurl -lxml2" +COPY ./cmake/ /swiftest/cmake/ +COPY ./src/ /swiftest/src/ +COPY ./CMakeLists.txt /swiftest/ +RUN echo 'find_path(NETCDF_INCLUDE_DIR NAMES netcdf.mod HINTS ENV NETCDF_FORTRAN_HOME)\n' \ + 'find_library(NETCDF_FORTRAN_LIBRARY NAMES netcdff HINTS ENV LD_LIBRARY_PATH)\n' \ + 'find_library(NETCDF_LIBRARY NAMES netcdf HINTS ENV LD_LIBRARY_PATH)\n' \ + 'find_library(HDF5_HL_LIBRARY NAMES libhdf5_hl.a HINTS ENV LD_LIBRARY_PATH)\n' \ + 'find_library(HDF5_LIBRARY NAMES libhdf5.a HINTS ENV LD_LIBRARY_PATH)\n' \ + 'find_library(Z_LIBRARY NAMES libz.a HINTS ENV LD_LIBRARY_PATH)\n' \ + 'find_library(ZSTD_LIBRARY NAMES libzstd.a HINTS ENV LD_LIBRARY_PATH)\n' \ + 'find_library(SZ_LIBRARY NAMES libsz.a HINTS ENV LD_LIBRARY_PATH)\n' \ + 'find_library(BZ2_LIBRARY NAMES libbz2.a HINTS ENV LD_LIBRARY_PATH)\n' \ + 'find_library(CURL_LIBRARY NAMES libcurl.a HINTS ENV LD_LIBRARY_PATH)\n' \ + 'find_library(XML2_LIBRARY NAMES libxml2.a HINTS ENV LD_LIBRARY_PATH)\n' \ + 'set(NETCDF_FOUND TRUE)\n' \ + 'set(NETCDF_INCLUDE_DIRS ${NETCDF_INCLUDE_DIR})\n' \ + 'set(NETCDF_LIBRARIES ${NETCDF_FORTRAN_LIBRARY} ${NETCDF_LIBRARY} ${HDF5_HL_LIBRARY} ${HDF5_LIBRARY} ${SZ_LIBRARY} ${Z_LIBRARY} ${ZSTD_LIBRARY} ${BZ2_LIBRARY} ${CURL_LIBRARY} ${XML2_LIBRARY} )\n' \ + 'mark_as_advanced(NETCDF_LIBRARY NETCDF_FORTRAN_LIBRARY NETCDF_INCLUDE_DIR)\n' > /swiftest/cmake/Modules/FindNETCDF.cmake + +RUN cd swiftest && \ + cmake -S . -B build -DCMAKE_INSTALL_PREFIX="${INSTALL_DIR}" -DCONTAINERIZE=ON -DCMAKE_BUILD_TYPE=release -DBUILD_SHARED_LIBS=OFF &&\ + cmake --build build --verbose && \ + cmake --install build + +# Production container +FROM continuumio/miniconda3 + +RUN apt-get update && apt-get upgrade -y && \ + DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + libxml2-dev libcurl4-gnutls-dev libzstd-dev libbz2-dev libaec-dev && \ + rm -rf /var/lib/apt/lists/* + +ENV LD_LIBRARY_PATH="/usr/local/lib" +COPY --from=build /opt/intel/oneapi/mpi/latest/lib/libmpifort.so.12 /usr/local/lib/ +COPY --from=build /opt/intel/oneapi/mpi/latest/lib/release/libmpi.so.12 /usr/local/lib/ + +RUN conda update --all -y +RUN conda install conda-libmamba-solver -y +RUN conda config --set solver libmamba +RUN conda install -c conda-forge conda-build numpy scipy matplotlib pandas xarray astropy astroquery tqdm x264 bottleneck ffmpeg h5netcdf netcdf4 -y +RUN conda update --all -y + +COPY ./python/ . +COPY --from=build /usr/local/bin/swiftest_driver /bin/ +RUN cd swiftest && conda develop . +ENV SHELL="/bin/bash" +ENTRYPOINT ["/opt/conda/bin/python"] \ No newline at end of file diff --git a/cmake/Modules/FindNETCDF.cmake b/cmake/Modules/FindNETCDF.cmake index 2355ad900..003d5b195 100644 --- a/cmake/Modules/FindNETCDF.cmake +++ b/cmake/Modules/FindNETCDF.cmake @@ -8,11 +8,14 @@ # If not, see: https://www.gnu.org/licenses. # - Finds the NetCDF libraries -find_path(NETCDF_INCLUDE_DIR NAMES netcdf.mod HINTS ENV NETCDF_FORTRAN_HOME) -find_library(NETCDF_LIBRARY NAMES netcdf HINTS ENV NETCDF_FORTRAN_HOME) -find_library(NETCDF_FORTRAN_LIBRARY NAMES netcdff HINTS ENV NETCDF_FORTRAN_HOME) + +find_path(NETCDF_INCLUDE_DIR NAMES netcdf.mod HINTS ENV NETCDF_FORTRAN_HOME ENV CPATH) +find_library(NETCDF_FORTRAN_LIBRARY NAMES netcdff HINTS ENV NETCDF_FORTRAN_HOME ENV LD_LIBRARY_PATH) +find_library(NETCDF_LIBRARY NAMES netcdf HINTS ENV NETCDF_FORTRAN_HOME ENV LD_LIBRARY_PATH) set(NETCDF_FOUND TRUE) set(NETCDF_INCLUDE_DIRS ${NETCDF_INCLUDE_DIR}) -set(NETCDF_LIBRARIES ${NETCDF_LIBRARY} ${NETCDF_FORTRAN_LIBRARY}) +# Note for posterity: When building static libraries, NETCDF_FORTRAN_LIBRARY must come *before* NETCDF_LIBRARY. Otherwise you get a bunch of "undefined reference to" errors +set(NETCDF_LIBRARIES ${NETCDF_FORTRAN_LIBRARY} ${NETCDF_LIBRARY}) + mark_as_advanced(NETCDF_LIBRARY NETCDF_FORTRAN_LIBRARY NETCDF_INCLUDE_DIR) \ No newline at end of file diff --git a/cmake/Modules/SetFortranFlags.cmake b/cmake/Modules/SetFortranFlags.cmake index 7b7752747..cb5a40768 100644 --- a/cmake/Modules/SetFortranFlags.cmake +++ b/cmake/Modules/SetFortranFlags.cmake @@ -50,9 +50,9 @@ 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 AND CMAKE_Fortran_FLAGS_CONTAINER) +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 AND CMAKE_Fortran_FLAGS_PROFILE AND CMAKE_Fortran_FLAGS_CONTAINER) +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. @@ -118,6 +118,7 @@ SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}" "/Qpad" # Intel Windows ) + IF (CONTAINERIZE) # There is some bug where -march=native doesn't work on Mac IF(APPLE) @@ -125,6 +126,18 @@ IF (CONTAINERIZE) ELSE() SET(GNUNATIVE "-march=generic") ENDIF() + + # Use static Intel libraries + SET_COMPILE_FLAG(CMAKE_Fortran_LINK_FLAGS "${CMAKE_Fortran_LINK_FLAGS}" + Fortran "-static-intel" # Intel + ) + + IF (USE_OPENMP) + SET_COMPILE_FLAG(CMAKE_Fortran_LINK_FLAGS "${CMAKE_Fortran_LINK_FLAGS}" + Fortran "-qopenmp-link=static" # Intel + ) + ENDIF (USE_OPENMP) + ELSE () # There is some bug where -march=native doesn't work on Mac IF(APPLE) @@ -148,7 +161,9 @@ IF (USE_SIMD) 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 ${GNUNATIVE} # GNU + Fortran "-xSSE2" # Intel + "/QxSSE2" # Intel Windows + ${GNUNATIVE} # GNU ) ELSE () # Optimize for the host's architecture diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0e3decf3c..cd7567afc 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -108,22 +108,17 @@ SET_SOURCE_FILES_PROPERTIES(${SWIFTEST_src} PROPERTIES Fortran_PREPROCESS ON) # Add the needed libraries and special compiler flags ##################################################### -# # Uncomment if you need to link to BLAS and LAPACK -TARGET_LINK_LIBRARIES(${SWIFTEST_DRIVER} ${NETCDF_LIBRARIES} ${NETCDF_FORTRAN_LIBRARIES}) - - +TARGET_LINK_LIBRARIES(${SWIFTEST_DRIVER} PRIVATE ${NETCDF_FORTRAN_LIBRARIES} ${NETCDF_LIBRARIES}) IF(USE_OPENMP) - SET_TARGET_PROPERTIES(${SWIFTEST_DRIVER} PROPERTIES - COMPILE_FLAGS "${OpenMP_Fortran_FLAGS}" - LINK_FLAGS "${OpenMP_Fortran_FLAGS}") + SET_PROPERTY(TARGET ${SWIFTEST_DRIVER} APPEND_STRING PROPERTY COMPILE_FLAGS "${OpenMP_Fortran_FLAGS} ") + SET_PROPERTY(TARGET ${SWIFTEST_DRIVER} APPEND_STRING PROPERTY LINK_FLAGS "${OpenMP_Fortran_FLAGS} ") ENDIF(USE_OPENMP) IF(USE_COARRAY) TARGET_COMPILE_DEFINITIONS(${SWIFTEST_DRIVER} PRIVATE -DCOARRAY) - SET_TARGET_PROPERTIES(${SWIFTEST_DRIVER} PROPERTIES - COMPILE_FLAGS "${Coarray_Fortran_FLAGS}" - LINK_FLAGS "${Coarray_Fortran_FLAGS}") + SET_PROPERTY(TARGET ${SWIFTEST_DRIVER} APPEND_STRING PROPERTY COMPILE_FLAGS "${Coarray_Fortran_FLAGS} ") + SET_PROPERTY(TARGET ${SWIFTEST_DRIVER} APPEND_STRING PROPERTY LINK_FLAGS "${Coarray_Fortran_FLAGS} ") ENDIF(USE_COARRAY) diff --git a/swiftest.sh b/swiftest.sh new file mode 100755 index 000000000..91d53ff92 --- /dev/null +++ b/swiftest.sh @@ -0,0 +1,3 @@ +#!/bin/sh -- +#docker run -v $(pwd):$(pwd) -w $(pwd) --user "$(id -u):$(id -g)" -t -e OMP_NUM_THREADS -e FOR_COARRAY_NUM_IMAGES swiftest:1.0.0 "$@" +docker run -v $(pwd):$(pwd) -w $(pwd) -t -e OMP_NUM_THREADS -e FOR_COARRAY_NUM_IMAGES swiftest:1.0.0 "$@" \ No newline at end of file From ae98dd89dc8ffd3226156690705d1ef56c620157 Mon Sep 17 00:00:00 2001 From: David Minton Date: Sun, 4 Jun 2023 19:38:22 -0400 Subject: [PATCH 56/95] Added a universal writable .astropy directory to be able to call the docker image as a regular user to that simdir will have the correct ownership --- Dockerfile | 2 + docker/.gitignore | 9 +-- docker/bin/swiftest | 2 + docker/gnu/Dockerfile | 44 ----------- docker/gnu/bin/.gitignore | 0 docker/gnu/bin/swiftest_driver | 2 - docker/install.sh | 8 +- docker/intel/Dockerfile | 129 --------------------------------- swiftest.sh | 3 - 9 files changed, 10 insertions(+), 189 deletions(-) create mode 100755 docker/bin/swiftest delete mode 100644 docker/gnu/Dockerfile delete mode 100644 docker/gnu/bin/.gitignore delete mode 100755 docker/gnu/bin/swiftest_driver delete mode 100644 docker/intel/Dockerfile delete mode 100755 swiftest.sh diff --git a/Dockerfile b/Dockerfile index 53a5ce831..99b0e97a3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -187,5 +187,7 @@ RUN conda update --all -y COPY ./python/ . COPY --from=build /usr/local/bin/swiftest_driver /bin/ RUN cd swiftest && conda develop . +RUN mkdir -p /.astropy && \ + chmod -R 777 /.astropy ENV SHELL="/bin/bash" ENTRYPOINT ["/opt/conda/bin/python"] \ No newline at end of file diff --git a/docker/.gitignore b/docker/.gitignore index 215dd3f04..09c5585d1 100644 --- a/docker/.gitignore +++ b/docker/.gitignore @@ -1,10 +1,5 @@ * !.gitignore !install.sh -!gnu/ -!gnu/Dockerfile -!/gnu/bin/ -!/gnu/bin/swiftest_driver -!intel/ -!intel/Dockerfile -!/intel/bin/swiftest_driver +!bin +!bin/swiftest diff --git a/docker/bin/swiftest b/docker/bin/swiftest new file mode 100755 index 000000000..bc94b2cb0 --- /dev/null +++ b/docker/bin/swiftest @@ -0,0 +1,2 @@ +#!/bin/sh -- +docker run -v $(pwd):$(pwd) -w $(pwd) --user "$(id -u):$(id -g)" -t -e OMP_NUM_THREADS -e FOR_COARRAY_NUM_IMAGES swiftest:1.0.0 "$@" \ No newline at end of file diff --git a/docker/gnu/Dockerfile b/docker/gnu/Dockerfile deleted file mode 100644 index ec64211bd..000000000 --- a/docker/gnu/Dockerfile +++ /dev/null @@ -1,44 +0,0 @@ -FROM debian:stable-slim as build - -# kick everything off -RUN apt-get update && apt-get upgrade -y && \ - DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ - ca-certificates curl git build-essential gfortran && \ - apt-get update && apt-get upgrade -y && \ - rm -rf /var/lib/apt/lists/* - -# Get CMAKE and install it -RUN mkdir -p /opt/cmake/build && \ - cd /opt/cmake/build && \ - curl -LO https://github.com/Kitware/CMake/releases/download/v3.26.2/cmake-3.26.2-linux-x86_64.sh && \ - /bin/bash cmake-3.26.2-linux-x86_64.sh --prefix=/usr/local --skip-license - -# Get dependencies -RUN apt-get update && apt-get upgrade -y && \ - DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ - libnetcdf-dev libnetcdff-dev libcoarrays-dev libcoarrays-mpich-dev&& \ - rm -rf /var/lib/apt/lists/* - -ENV NETCDF_HOME="/usr" -ENV NETCDF_FORTRAN_HOME="/usr" -ENV INDIR="/opt/dist//usr/local" - -# Get Swiftest source code -RUN cd /opt/ && \ - git clone -b debug https://github.com/carlislewishard/swiftest.git && \ - cd swiftest && \ - mkdir build && \ - cd build && \ - cmake .. -DCMAKE_PREFIX_PATH="${INDIR}" -DCMAKE_INSTALL_PREFIX="${INDIR}" -DCONTAINERIZE=ON -DCMAKE_BUILD_TYPE=release && \ - make && \ - make install - -#Production container -FROM debian:stable-slim -COPY --from=build /opt/dist / -RUN apt-get update && apt-get upgrade -y && \ - DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ - ca-certificates gfortran libnetcdf-dev libnetcdff-dev && \ - rm -rf /var/lib/apt/lists/* - -ENTRYPOINT ["/usr/local/bin/swiftest_driver"] \ No newline at end of file diff --git a/docker/gnu/bin/.gitignore b/docker/gnu/bin/.gitignore deleted file mode 100644 index e69de29bb..000000000 diff --git a/docker/gnu/bin/swiftest_driver b/docker/gnu/bin/swiftest_driver deleted file mode 100755 index f0a3638dd..000000000 --- a/docker/gnu/bin/swiftest_driver +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -- -docker run -v $(pwd):$(pwd) -w $(pwd) -t -e OMP_NUM_THREADS -e FOR_COARRAY_NUM_IMAGES swiftest_driver:gnu "$@" diff --git a/docker/install.sh b/docker/install.sh index f81e95e57..1a0b2b20c 100755 --- a/docker/install.sh +++ b/docker/install.sh @@ -1,5 +1,5 @@ #!/bin/sh -- -tag=${1:-intel} -echo "Installing swiftest_driver:${tag} Docker container and executable script" -docker pull daminton/swiftest_driver:${tag} -cp -rf ${tag}/bin/swiftest_driver ../bin/ \ No newline at end of file +tag=${1:-latest} +echo "Installing swiftest:${tag} Docker container and executable script" +docker pull daminton/swiftest:${tag} +cp -rf bin/swiftest ../bin/ \ No newline at end of file diff --git a/docker/intel/Dockerfile b/docker/intel/Dockerfile deleted file mode 100644 index c6d728b2d..000000000 --- a/docker/intel/Dockerfile +++ /dev/null @@ -1,129 +0,0 @@ -FROM debian:stable-slim as build - -# kick everything off -RUN apt-get update && apt-get upgrade -y && \ - DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ - ca-certificates curl git wget gpg-agent software-properties-common build-essential gnupg pkg-config libaec-dev procps && \ - rm -rf /var/lib/apt/lists/* - -# Get CMAKE and install it -RUN mkdir -p cmake/build && \ - cd cmake/build && \ - curl -LO https://github.com/Kitware/CMake/releases/download/v3.26.2/cmake-3.26.2-linux-x86_64.sh && \ - /bin/bash cmake-3.26.2-linux-x86_64.sh --prefix=/usr/local --skip-license - -# Get the Intel compilers -# download the key to system keyring -RUN wget -O- https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB \ -| gpg --dearmor | tee /usr/share/keyrings/oneapi-archive-keyring.gpg > /dev/null -# add signed entry to apt sources and configure the APT client to use Intel repository: -RUN echo "deb [signed-by=/usr/share/keyrings/oneapi-archive-keyring.gpg] https://apt.repos.intel.com/oneapi all main" | tee /etc/apt/sources.list.d/oneAPI.list -RUN apt-get -y update && apt-get upgrade -y -RUN apt-get install -y intel-hpckit - -# Build the NetCDF libraries -RUN mkdir -p /opt/build && mkdir -p /opt/dist -ENV INDIR="/opt/dist//usr/local" -ENV INTEL_DIR="/opt/intel/oneapi" -ENV CC="${INTEL_DIR}/compiler/latest/linux/bin/icx-cc" -ENV FC="${INTEL_DIR}/compiler/latest/linux/bin/ifx" - -RUN apt-get update && apt-get upgrade -y && \ - DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ - libhdf5-dev hdf5-tools zlib1g zlib1g-dev libxml2-dev libcurl4-gnutls-dev m4 && \ - rm -rf /var/lib/apt/lists/* - - -#NetCDF-c library -RUN git clone https://github.com/Unidata/netcdf-c.git -RUN cd netcdf-c && mkdir build && cd build && \ - cmake .. -DCMAKE_PREFIX_PATH="${LD_LIBRARY_PATH}" -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_INSTALL_PREFIX="${INDIR}" && \ - make && make install - -#NetCDF-Fortran library -RUN git clone https://github.com/Unidata/netcdf-fortran.git -RUN cd netcdf-fortran && mkdir build && cd build && \ - cmake .. -DCMAKE_INSTALL_PREFIX="${INDIR}" && \ - make && make install - -# #Swiftest -RUN git clone -b debug https://github.com/carlislewishard/swiftest.git -ENV FC="${INTEL_DIR}/mpi/latest/bin/mpiifort" -ENV NETCDF_HOME="${INDIR}" -ENV NETCDF_FORTRAN_HOME="${INDIR}" -ENV LANG=C.UTF-8 -ENV ACL_BOARD_VENDOR_PATH='/opt/Intel/OpenCLFPGA/oneAPI/Boards' -ENV ADVISOR_2023_DIR='/opt/intel/oneapi/advisor/2023.1.0' -ENV APM='/opt/intel/oneapi/advisor/2023.1.0/perfmodels' -ENV CCL_CONFIGURATION='cpu_gpu_dpcpp' -ENV CCL_ROOT='/opt/intel/oneapi/ccl/2021.9.0' -ENV CLASSPATH='/opt/intel/oneapi/mpi/2021.9.0//lib/mpi.jar:/opt/intel/oneapi/dal/2023.1.0/lib/onedal.jar' -ENV CLCK_ROOT='/opt/intel/oneapi/clck/2021.7.3' -ENV CMAKE_PREFIX_PATH='/opt/intel/oneapi/tbb/2021.9.0/env/..:/opt/intel/oneapi/dnnl/2023.1.0/cpu_dpcpp_gpu_dpcpp/../lib/cmake:/opt/intel/oneapi/dal/2023.1.0:/opt/intel/oneapi/compiler/2023.1.0/linux/IntelDPCPP:/opt/intel/oneapi/ccl/2021.9.0/lib/cmake/oneCCL' -ENV CMPLR_ROOT='/opt/intel/oneapi/compiler/2023.1.0' -ENV CPATH='/opt/intel/oneapi/tbb/2021.9.0/env/../include:/opt/intel/oneapi/mpi/2021.9.0//include:/opt/intel/oneapi/mkl/2023.1.0/include:/opt/intel/oneapi/ippcp/2021.7.0/include:/opt/intel/oneapi/ipp/2021.8.0/include:/opt/intel/oneapi/dpl/2022.1.0/linux/include:/opt/intel/oneapi/dnnl/2023.1.0/cpu_dpcpp_gpu_dpcpp/include:/opt/intel/oneapi/dev-utilities/2021.9.0/include:/opt/intel/oneapi/dal/2023.1.0/include:/opt/intel/oneapi/ccl/2021.9.0/include/cpu_gpu_dpcpp' -ENV CPLUS_INCLUDE_PATH='/opt/intel/oneapi/clck/2021.7.3/include' -ENV DAALROOT='/opt/intel/oneapi/dal/2023.1.0' -ENV DALROOT='/opt/intel/oneapi/dal/2023.1.0' -ENV DAL_MAJOR_BINARY='1' -ENV DAL_MINOR_BINARY='1' -ENV DIAGUTIL_PATH='/opt/intel/oneapi/vtune/2023.1.0/sys_check/vtune_sys_check.py:/opt/intel/oneapi/debugger/2023.1.0/sys_check/debugger_sys_check.py:/opt/intel/oneapi/compiler/2023.1.0/sys_check/sys_check.sh:/opt/intel/oneapi/advisor/2023.1.0/sys_check/advisor_sys_check.py:' -ENV DNNLROOT='/opt/intel/oneapi/dnnl/2023.1.0/cpu_dpcpp_gpu_dpcpp' -ENV DPL_ROOT='/opt/intel/oneapi/dpl/2022.1.0' -ENV FI_PROVIDER_PATH='/opt/intel/oneapi/mpi/2021.9.0//libfabric/lib/prov:/usr/lib64/libfabric' -ENV FPGA_VARS_ARGS='' -ENV FPGA_VARS_DIR='/opt/intel/oneapi/compiler/2023.1.0/linux/lib/oclfpga' -ENV GDB_INFO='/opt/intel/oneapi/debugger/2023.1.0/documentation/info/' -ENV INFOPATH='/opt/intel/oneapi/debugger/2023.1.0/gdb/intel64/lib' -ENV INSPECTOR_2023_DIR='/opt/intel/oneapi/inspector/2023.1.0' -ENV INTELFPGAOCLSDKROOT='/opt/intel/oneapi/compiler/2023.1.0/linux/lib/oclfpga' -ENV INTEL_LICENSE_FILE='/opt/intel/licenses:/root/intel/licenses:/opt/intel/oneapi/clck/2021.7.3/licensing:/opt/intel/licenses:/root/intel/licenses:/Users/Shared/Library/Application Support/Intel/Licenses' -ENV INTEL_PYTHONHOME='/opt/intel/oneapi/debugger/2023.1.0/dep' -ENV IPPCP_TARGET_ARCH='intel64' -ENV IPPCRYPTOROOT='/opt/intel/oneapi/ippcp/2021.7.0' -ENV IPPROOT='/opt/intel/oneapi/ipp/2021.8.0' -ENV IPP_TARGET_ARCH='intel64' -ENV I_MPI_ROOT='/opt/intel/oneapi/mpi/2021.9.0' -ENV LD_LIBRARY_PATH='/opt/intel/oneapi/tbb/2021.9.0/env/../lib/intel64/gcc4.8:/opt/intel/oneapi/mpi/2021.9.0//libfabric/lib:/opt/intel/oneapi/mpi/2021.9.0//lib/release:/opt/intel/oneapi/mpi/2021.9.0//lib:/opt/intel/oneapi/mkl/2023.1.0/lib/intel64:/opt/intel/oneapi/itac/2021.9.0/slib:/opt/intel/oneapi/ippcp/2021.7.0/lib/intel64:/opt/intel/oneapi/ipp/2021.8.0/lib/intel64:/opt/intel/oneapi/dnnl/2023.1.0/cpu_dpcpp_gpu_dpcpp/lib:/opt/intel/oneapi/debugger/2023.1.0/gdb/intel64/lib:/opt/intel/oneapi/debugger/2023.1.0/libipt/intel64/lib:/opt/intel/oneapi/debugger/2023.1.0/dep/lib:/opt/intel/oneapi/dal/2023.1.0/lib/intel64:/opt/intel/oneapi/compiler/2023.1.0/linux/lib:/opt/intel/oneapi/compiler/2023.1.0/linux/lib/x64:/opt/intel/oneapi/compiler/2023.1.0/linux/lib/oclfpga/host/linux64/lib:/opt/intel/oneapi/compiler/2023.1.0/linux/compiler/lib/intel64_lin:/opt/intel/oneapi/ccl/2021.9.0/lib/cpu_gpu_dpcpp' -ENV LIBRARY_PATH='/opt/intel/oneapi/tbb/2021.9.0/env/../lib/intel64/gcc4.8:/opt/intel/oneapi/mpi/2021.9.0//libfabric/lib:/opt/intel/oneapi/mpi/2021.9.0//lib/release:/opt/intel/oneapi/mpi/2021.9.0//lib:/opt/intel/oneapi/mkl/2023.1.0/lib/intel64:/opt/intel/oneapi/ippcp/2021.7.0/lib/intel64:/opt/intel/oneapi/ipp/2021.8.0/lib/intel64:/opt/intel/oneapi/dnnl/2023.1.0/cpu_dpcpp_gpu_dpcpp/lib:/opt/intel/oneapi/dal/2023.1.0/lib/intel64:/opt/intel/oneapi/compiler/2023.1.0/linux/compiler/lib/intel64_lin:/opt/intel/oneapi/compiler/2023.1.0/linux/lib:/opt/intel/oneapi/clck/2021.7.3/lib/intel64:/opt/intel/oneapi/ccl/2021.9.0/lib/cpu_gpu_dpcpp' -ENV MANPATH='/opt/intel/oneapi/mpi/2021.9.0/man:/opt/intel/oneapi/itac/2021.9.0/man:/opt/intel/oneapi/debugger/2023.1.0/documentation/man:/opt/intel/oneapi/compiler/2023.1.0/documentation/en/man/common:/opt/intel/oneapi/clck/2021.7.3/man::' -ENV MKLROOT='/opt/intel/oneapi/mkl/2023.1.0' -ENV NLSPATH='/opt/intel/oneapi/mkl/2023.1.0/lib/intel64/locale/%l_%t/%N:/opt/intel/oneapi/compiler/2023.1.0/linux/compiler/lib/intel64_lin/locale/%l_%t/%N' -ENV OCL_ICD_FILENAMES='libintelocl_emu.so:libalteracl.so:/opt/intel/oneapi/compiler/2023.1.0/linux/lib/x64/libintelocl.so' -ENV ONEAPI_ROOT='/opt/intel/oneapi' -ENV PATH='/opt/intel/oneapi/vtune/2023.1.0/bin64:/opt/intel/oneapi/mpi/2021.9.0//libfabric/bin:/opt/intel/oneapi/mpi/2021.9.0//bin:/opt/intel/oneapi/mkl/2023.1.0/bin/intel64:/opt/intel/oneapi/itac/2021.9.0/bin:/opt/intel/oneapi/inspector/2023.1.0/bin64:/opt/intel/oneapi/dev-utilities/2021.9.0/bin:/opt/intel/oneapi/debugger/2023.1.0/gdb/intel64/bin:/opt/intel/oneapi/compiler/2023.1.0/linux/lib/oclfpga/bin:/opt/intel/oneapi/compiler/2023.1.0/linux/bin/intel64:/opt/intel/oneapi/compiler/2023.1.0/linux/bin:/opt/intel/oneapi/clck/2021.7.3/bin/intel64:/opt/intel/oneapi/advisor/2023.1.0/bin64:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin' -ENV PKG_CONFIG_PATH='/opt/intel/oneapi/vtune/2023.1.0/include/pkgconfig/lib64:/opt/intel/oneapi/tbb/2021.9.0/env/../lib/pkgconfig:/opt/intel/oneapi/mpi/2021.9.0/lib/pkgconfig:/opt/intel/oneapi/mkl/2023.1.0/lib/pkgconfig:/opt/intel/oneapi/ippcp/2021.7.0/lib/pkgconfig:/opt/intel/oneapi/inspector/2023.1.0/include/pkgconfig/lib64:/opt/intel/oneapi/dpl/2022.1.0/lib/pkgconfig:/opt/intel/oneapi/dnnl/2023.1.0/cpu_dpcpp_gpu_dpcpp/../lib/pkgconfig:/opt/intel/oneapi/dal/2023.1.0/lib/pkgconfig:/opt/intel/oneapi/compiler/2023.1.0/lib/pkgconfig:/opt/intel/oneapi/ccl/2021.9.0/lib/pkgconfig:/opt/intel/oneapi/advisor/2023.1.0/include/pkgconfig/lib64:' -ENV PYTHONPATH='/opt/intel/oneapi/advisor/2023.1.0/pythonapi' -ENV SETVARS_COMPLETED='1' -ENV TBBROOT='/opt/intel/oneapi/tbb/2021.9.0/env/..' -ENV VTUNE_PROFILER_2023_DIR='/opt/intel/oneapi/vtune/2023.1.0' -ENV VTUNE_PROFILER_DIR='/opt/intel/oneapi/vtune/2023.1.0' -ENV VT_ADD_LIBS='-ldwarf -lelf -lvtunwind -lm -lpthread' -ENV VT_LIB_DIR='/opt/intel/oneapi/itac/2021.9.0/lib' -ENV VT_MPI='impi4' -ENV VT_ROOT='/opt/intel/oneapi/itac/2021.9.0' -ENV VT_SLIB_DIR='/opt/intel/oneapi/itac/2021.9.0/slib' - -RUN cd swiftest && cmake -P distclean.cmake && mkdir build && cd build && cmake .. -DCMAKE_PREFIX_PATH="${INDIR}" -DCMAKE_INSTALL_PREFIX="${INDIR}" -DCONTAINERIZE=ON -DCMAKE_BUILD_TYPE=release && make && make install - -#Production container -FROM debian:stable-slim -COPY --from=build /opt/dist / - -# Get the Intel runtime libraries -RUN apt-get update && apt-get upgrade -y && \ - DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ - ca-certificates curl gpg-agent software-properties-common gnupg pkg-config procps && \ - rm -rf /var/lib/apt/lists/* - -RUN curl -fsSL https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS-2023.PUB | apt-key add - -RUN echo "deb [trusted=yes] https://apt.repos.intel.com/oneapi all main " > /etc/apt/sources.list.d/oneAPI.list -RUN apt-get -y update && apt-get upgrade -y -RUN apt-get install -y intel-oneapi-runtime-openmp intel-oneapi-runtime-mkl intel-oneapi-runtime-mpi intel-oneapi-runtime-fortran -ENV NETCDF_HOME="/usr/local" -ENV LANG=C.UTF-8 -ENV LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/opt/intel/oneapi/lib" -RUN apt-get -y update && apt-get upgrade -y -RUN apt-get install -y libhdf5-dev libxml2-dev - -ENTRYPOINT ["/usr/local/bin/swiftest_driver"] \ No newline at end of file diff --git a/swiftest.sh b/swiftest.sh deleted file mode 100755 index 91d53ff92..000000000 --- a/swiftest.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -- -#docker run -v $(pwd):$(pwd) -w $(pwd) --user "$(id -u):$(id -g)" -t -e OMP_NUM_THREADS -e FOR_COARRAY_NUM_IMAGES swiftest:1.0.0 "$@" -docker run -v $(pwd):$(pwd) -w $(pwd) -t -e OMP_NUM_THREADS -e FOR_COARRAY_NUM_IMAGES swiftest:1.0.0 "$@" \ No newline at end of file From da21136b8c8e72389553f9b6857fcc58d5989ba3 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Sun, 4 Jun 2023 19:39:46 -0400 Subject: [PATCH 57/95] Improved coarray outpt handling and preventing runs getting stuck on sync --- src/swiftest/swiftest_coarray.f90 | 19 +++++++++++++++---- src/swiftest/swiftest_io.f90 | 6 +++--- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/swiftest/swiftest_coarray.f90 b/src/swiftest/swiftest_coarray.f90 index e97488a0f..7dbd1a816 100644 --- a/src/swiftest/swiftest_coarray.f90 +++ b/src/swiftest/swiftest_coarray.f90 @@ -24,20 +24,33 @@ module subroutine swiftest_coarray_balance_system(nbody_system, param) ! Internals integer(I4B), codimension[*], save :: ntp integer(I4B) :: img,ntp_min, ntp_max + character(len=NAMELEN) :: min_str, max_str, diff_str, ni_str ntp = nbody_system%tp%nbody sync all + write(param%display_unit,*) "Checking whether test particles need to be reblanced." ntp_min = huge(1) ntp_max = 0 do img = 1, num_images() if (ntp[img] < ntp_min) ntp_min = ntp[img] if (ntp[img] > ntp_max) ntp_max = ntp[img] end do + write(min_str,*) ntp_min + write(max_str,*) ntp_max + write(diff_str,*) ntp_max - ntp_min + write(ni_str,*) num_images() + write(param%display_unit,*) "ntp_min : " // trim(adjustl(min_str)) + write(param%display_unit,*) "ntp_max : " // trim(adjustl(max_str)) + write(param%display_unit,*) "difference: " // trim(adjustl(diff_str)) if (ntp_max - ntp_min >= num_images()) then + write(param%display_unit,*) trim(adjustl(diff_str)) // ">=" // trim(adjustl(ni_str)) // ": Rebalancing" call nbody_system%coarray_collect(param) call nbody_system%coarray_distribute(param) + write(param%display_unit,*) "Rebalancing complete" + else + write(param%display_unit,*) trim(adjustl(diff_str)) // "<" // trim(adjustl(ni_str)) // ": No rebalancing needed" end if - + call flush(param%display_unit) return end subroutine swiftest_coarray_balance_system @@ -700,10 +713,8 @@ module subroutine swiftest_coarray_distribute_system(nbody_system, param) write(image_num_char,*) this_image() write(ntp_num_char,*) nbody_system%tp%nbody - if (this_image() /= 1) sync images(this_image() - 1) write(param%display_unit,*) "Image " // trim(adjustl(image_num_char)) // " ntp: " // trim(adjustl(ntp_num_char)) if (param%log_output) flush(param%display_unit) - if (this_image() < num_images()) sync images(this_image() + 1) deallocate(ntp, lspill_list, tmp, cotp) @@ -711,4 +722,4 @@ module subroutine swiftest_coarray_distribute_system(nbody_system, param) end subroutine swiftest_coarray_distribute_system -end submodule s_swiftest_coarray \ No newline at end of file +end submodule s_swiftest_coarray diff --git a/src/swiftest/swiftest_io.f90 b/src/swiftest/swiftest_io.f90 index 38b1735d7..eea186c48 100644 --- a/src/swiftest/swiftest_io.f90 +++ b/src/swiftest/swiftest_io.f90 @@ -416,9 +416,9 @@ module subroutine swiftest_io_dump_storage(self, param) associate(nc => self%nc) #ifdef COARRAY sync all - if (param%lcoarray .and. (this_image() /= 1)) sync images(this_image() - 1) write(param%display_unit,*) "File output started" call iotimer%start() + critical #endif call nc%open(param) do i = 1, self%iframe @@ -433,10 +433,10 @@ module subroutine swiftest_io_dump_storage(self, param) end do call nc%close() #ifdef COARRAY - if (param%lcoarray .and. (this_image() < num_images())) sync images(this_image() + 1) + end critical call iotimer%stop() - call iotimer%report(message="File output :", unit=param%display_unit) sync all + call iotimer%report(message="File output :", unit=param%display_unit) #endif end associate From 0d4935bd21e963fba635c53f50c831dba0ce698c Mon Sep 17 00:00:00 2001 From: David Minton Date: Mon, 5 Jun 2023 14:05:32 -0400 Subject: [PATCH 58/95] Minor changes to troubleshoot energy calc NaN in new container. --- Dockerfile | 43 +++++++++++++++++++++------------- singularity/install.sh | 2 +- src/swiftest/swiftest_util.f90 | 5 ++-- 3 files changed, 31 insertions(+), 19 deletions(-) diff --git a/Dockerfile b/Dockerfile index 99b0e97a3..5b0e942a1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -136,10 +136,12 @@ RUN cd netcdf-fortran-4.6.1 && \ make && \ make install -# # Swiftest +# Swiftest ENV NETCDF_HOME=${INSTALL_DIR} ENV NETCDF_FORTRAN_HOME=${NETCDF_HOME} ENV NETCDF_LIBRARY=${NETCDF_HOME} +ENV FOR_COARRAY_NUM_IMAGES=1 +ENV OMP_NUM_THREADS=1 ENV FC="${INTEL_DIR}/mpi/latest/bin/mpiifort" ENV LDFLAGS="-L/usr/local/lib -L/usr/lib/x86_64-linux-gnu -lnetcdff -lnetcdf -lhdf5_hl -lhdf5 -lsz -lz -lzstd -lbz2 -lcurl -lxml2" COPY ./cmake/ /swiftest/cmake/ @@ -162,32 +164,41 @@ RUN echo 'find_path(NETCDF_INCLUDE_DIR NAMES netcdf.mod HINTS ENV NETCDF_FORTRAN 'mark_as_advanced(NETCDF_LIBRARY NETCDF_FORTRAN_LIBRARY NETCDF_INCLUDE_DIR)\n' > /swiftest/cmake/Modules/FindNETCDF.cmake RUN cd swiftest && \ - cmake -S . -B build -DCMAKE_INSTALL_PREFIX="${INSTALL_DIR}" -DCONTAINERIZE=ON -DCMAKE_BUILD_TYPE=release -DBUILD_SHARED_LIBS=OFF &&\ + cmake -S . -B build -DCMAKE_INSTALL_PREFIX="${INSTALL_DIR}" -DCONTAINERIZE=ON -DUSE_COARRAY=OFF -DCMAKE_BUILD_TYPE=DEBUG -DBUILD_SHARED_LIBS=OFF &&\ cmake --build build --verbose && \ cmake --install build -# Production container -FROM continuumio/miniconda3 - +# Driver container +FROM ubuntu:20.04 as Driver +COPY --from=build /opt/intel/oneapi/mpi/latest/lib/libmpifort.so.12 /usr/local/lib/ +COPY --from=build /opt/intel/oneapi/mpi/latest/lib/release/libmpi.so.12 /usr/local/lib/ +COPY --from=build /usr/local/bin/swiftest_driver /usr/local/bin RUN apt-get update && apt-get upgrade -y && \ DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ - libxml2-dev libcurl4-gnutls-dev libzstd-dev libbz2-dev libaec-dev && \ + libsz2 libcurl3-gnutls libxml2 && \ rm -rf /var/lib/apt/lists/* +# Production container +FROM continuumio/miniconda3 + ENV LD_LIBRARY_PATH="/usr/local/lib" +ENV SHELL="/bin/bash" COPY --from=build /opt/intel/oneapi/mpi/latest/lib/libmpifort.so.12 /usr/local/lib/ COPY --from=build /opt/intel/oneapi/mpi/latest/lib/release/libmpi.so.12 /usr/local/lib/ - -RUN conda update --all -y -RUN conda install conda-libmamba-solver -y -RUN conda config --set solver libmamba -RUN conda install -c conda-forge conda-build numpy scipy matplotlib pandas xarray astropy astroquery tqdm x264 bottleneck ffmpeg h5netcdf netcdf4 -y -RUN conda update --all -y - COPY ./python/ . COPY --from=build /usr/local/bin/swiftest_driver /bin/ -RUN cd swiftest && conda develop . -RUN mkdir -p /.astropy && \ + +RUN apt-get update && apt-get upgrade -y && \ + DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + libsz2 libcurl3-gnutls libxml2 && \ + rm -rf /var/lib/apt/lists/* && \ + conda update --all -y && \ + conda install conda-libmamba-solver -y && \ + conda config --set solver libmamba && \ + conda install -c conda-forge conda-build numpy scipy matplotlib pandas xarray astropy astroquery tqdm x264 bottleneck ffmpeg h5netcdf netcdf4 dask -y && \ + conda update --all -y && \ + cd swiftest && conda develop . && \ + mkdir -p /.astropy && \ chmod -R 777 /.astropy -ENV SHELL="/bin/bash" + ENTRYPOINT ["/opt/conda/bin/python"] \ No newline at end of file diff --git a/singularity/install.sh b/singularity/install.sh index 50d6d56df..ff2be8596 100755 --- a/singularity/install.sh +++ b/singularity/install.sh @@ -3,7 +3,7 @@ # In order to use the executable script, the SWIFTEST_SIF environment variable must be set to point to the location of swiftest_driver.sif, which requires this script to be called via source: # $ . ./install.sh # -tag=${1:-intel} +tag=${1:-latest} echo "Installing swiftest_driver.sif Singularity container and executable script from swiftest_driver:${tag} Docker container" singularity pull --force swiftest_driver.sif docker://daminton/swiftest_driver:${tag} cp -rf bin/swiftest_driver ../bin/ diff --git a/src/swiftest/swiftest_util.f90 b/src/swiftest/swiftest_util.f90 index 2c7b803bc..c164a365a 100644 --- a/src/swiftest/swiftest_util.f90 +++ b/src/swiftest/swiftest_util.f90 @@ -1101,10 +1101,11 @@ module subroutine swiftest_util_flatten_eucl_plpl(self, param) class(swiftest_pl), intent(inout) :: self !! Swiftest massive body object class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters ! Internals - integer(I4B) :: err, i, j + integer(I4B) :: err, i, j, npl integer(I8B) :: k, npl8 - associate(npl => self%nbody, nplpl => self%nplpl) + associate(nplpl => self%nplpl) + npl = self%nbody npl8 = int(npl, kind=I8B) nplpl = npl8 * (npl8 - 1_I8B) / 2_I8B ! number of entries in a strict lower triangle, npl x npl if (param%lflatten_interactions) then From 9bf02d01741a64aa7848138af2a629c54b972c3f Mon Sep 17 00:00:00 2001 From: David Minton Date: Tue, 6 Jun 2023 12:51:42 -0400 Subject: [PATCH 59/95] Fixed compiler flag typos that prevented the -standard-semantics flag from being set. Also moved the standards compliance warnings to the DEBUG build --- Dockerfile | 68 ++++++++++++----------------- cmake/Modules/SetFortranFlags.cmake | 14 +++--- 2 files changed, 35 insertions(+), 47 deletions(-) diff --git a/Dockerfile b/Dockerfile index 5b0e942a1..cb81fb7f6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,24 +2,18 @@ FROM ubuntu:20.04 as build # kick everything off RUN apt-get update && apt-get upgrade -y && \ - DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ - ca-certificates curl git wget gpg-agent software-properties-common build-essential gnupg pkg-config && \ - rm -rf /var/lib/apt/lists/* - -# Get CMAKE and install it -RUN mkdir -p cmake/build && \ - cd cmake/build && \ - curl -LO https://github.com/Kitware/CMake/releases/download/v3.26.2/cmake-3.26.2-linux-x86_64.sh && \ - /bin/bash cmake-3.26.2-linux-x86_64.sh --prefix=/usr/local --skip-license - -# Get the Intel compilers -# download the key to system keyring -RUN wget -O- https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB \ -| gpg --dearmor | tee /usr/share/keyrings/oneapi-archive-keyring.gpg > /dev/null -# add signed entry to apt sources and configure the APT client to use Intel repository: -RUN echo "deb [signed-by=/usr/share/keyrings/oneapi-archive-keyring.gpg] https://apt.repos.intel.com/oneapi all main" | tee /etc/apt/sources.list.d/oneAPI.list -RUN apt-get -y update && apt-get upgrade -y -RUN apt-get install -y intel-hpckit + DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + ca-certificates curl git wget gpg-agent software-properties-common build-essential gnupg pkg-config && \ + rm -rf /var/lib/apt/lists/* && \ + mkdir -p cmake/build && \ + cd cmake/build && \ + curl -LO https://github.com/Kitware/CMake/releases/download/v3.26.2/cmake-3.26.2-linux-x86_64.sh && \ + /bin/bash cmake-3.26.2-linux-x86_64.sh --prefix=/usr/local --skip-license && \ + wget -O- https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB \ + | gpg --dearmor | tee /usr/share/keyrings/oneapi-archive-keyring.gpg > /dev/null && \ + echo "deb [signed-by=/usr/share/keyrings/oneapi-archive-keyring.gpg] https://apt.repos.intel.com/oneapi all main" | tee /etc/apt/sources.list.d/oneAPI.list && \ + apt-get -y update && apt-get upgrade -y && \ + apt-get install -y intel-hpckit && \ # Set Intel compiler environment variables ENV INTEL_DIR="/opt/intel/oneapi" @@ -94,24 +88,19 @@ ENV HDF5_INCLUDE_DIR="${HDF5_ROOT}/include" ENV HDF5_PLUGIN_PATH="${HDF5_LIBDIR}/plugin" # Get the HDF5, NetCDF-C and NetCDF-Fortran libraries -RUN wget -qO- https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.14/hdf5-1.14.1/bin/unix/hdf5-1.14.1-2-Std-ubuntu2004_64-Intel.tar.gz | tar xvz -RUN wget -qO- https://github.com/Unidata/netcdf-c/archive/refs/tags/v4.9.2.tar.gz | tar xvz -RUN wget -qO- https://github.com/Unidata/netcdf-fortran/archive/refs/tags/v4.6.1.tar.gz | tar xvz -RUN wget -qO- https://www.zlib.net/zlib-1.2.13.tar.gz | tar xvz - -# Install dependencies -RUN apt-get update && apt-get upgrade -y && \ - DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ - libxml2-dev libcurl4-gnutls-dev libzstd-dev libbz2-dev libaec-dev m4 && \ - rm -rf /var/lib/apt/lists/* - -# Install HDF5 -RUN cd hdf && \ - ./HDF5-1.14.1-Linux.sh --skip-license && \ - cp -R HDF_Group/HDF5/1.14.1/lib/*.a ${HDF5_ROOT}/lib/ && \ - cp -R HDF_Group/HDF5/1.14.1/include/* ${HDF5_ROOT}/include/ - -RUN cp zlib-1.2.13/zlib.h ${HDF5_INCLUDE_DIR}/ +RUN wget -qO- https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.14/hdf5-1.14.1/bin/unix/hdf5-1.14.1-2-Std-ubuntu2004_64-Intel.tar.gz | tar xvz && \ + wget -qO- https://github.com/Unidata/netcdf-c/archive/refs/tags/v4.9.2.tar.gz | tar xvz && \ + wget -qO- https://github.com/Unidata/netcdf-fortran/archive/refs/tags/v4.6.1.tar.gz | tar xvz && \ + wget -qO- https://www.zlib.net/zlib-1.2.13.tar.gz | tar xvz && \ + apt-get update && apt-get upgrade -y && \ + DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + libxml2-dev libcurl4-gnutls-dev libzstd-dev libbz2-dev libaec-dev m4 && \ + rm -rf /var/lib/apt/lists/* && \ + cd hdf && \ + ./HDF5-1.14.1-Linux.sh --skip-license && \ + cp -R HDF_Group/HDF5/1.14.1/lib/*.a ${HDF5_ROOT}/lib/ && \ + cp -R HDF_Group/HDF5/1.14.1/include/* ${HDF5_ROOT}/include/ && \ + cp zlib-1.2.13/zlib.h ${HDF5_INCLUDE_DIR}/ ENV LD_LIBRARY_PATH="/lib/x86_64-linux-gnu:${LD_LIBRARY_PATH}" ENV LDFLAGS="-static-intel -lhdf5_hl -lhdf5 -lsz -lm -lz -lzstd -lbz2 -lcurl -lxml2" @@ -126,7 +115,7 @@ RUN cd netcdf-c-4.9.2 && \ # NetCDF-Fortran library ENV F77=${FC} ENV CFLAGS="-fPIC" -ENV FCFLAGS=${CFLAGS} +ENV FCFLAGS="${CFLAGS} -standard-semantics" ENV FFLAGS=${CFLAGS} ENV CPPFLAGS="-I${INSTALL_DIR}/include -I/usr/include -I/usr/include/x86_64-linux-gnu/curl" ENV LDFLAGS="-static-intel" @@ -161,9 +150,8 @@ RUN echo 'find_path(NETCDF_INCLUDE_DIR NAMES netcdf.mod HINTS ENV NETCDF_FORTRAN 'set(NETCDF_FOUND TRUE)\n' \ 'set(NETCDF_INCLUDE_DIRS ${NETCDF_INCLUDE_DIR})\n' \ 'set(NETCDF_LIBRARIES ${NETCDF_FORTRAN_LIBRARY} ${NETCDF_LIBRARY} ${HDF5_HL_LIBRARY} ${HDF5_LIBRARY} ${SZ_LIBRARY} ${Z_LIBRARY} ${ZSTD_LIBRARY} ${BZ2_LIBRARY} ${CURL_LIBRARY} ${XML2_LIBRARY} )\n' \ - 'mark_as_advanced(NETCDF_LIBRARY NETCDF_FORTRAN_LIBRARY NETCDF_INCLUDE_DIR)\n' > /swiftest/cmake/Modules/FindNETCDF.cmake - -RUN cd swiftest && \ + 'mark_as_advanced(NETCDF_LIBRARY NETCDF_FORTRAN_LIBRARY NETCDF_INCLUDE_DIR)\n' > /swiftest/cmake/Modules/FindNETCDF.cmake && \ + cd swiftest && \ cmake -S . -B build -DCMAKE_INSTALL_PREFIX="${INSTALL_DIR}" -DCONTAINERIZE=ON -DUSE_COARRAY=OFF -DCMAKE_BUILD_TYPE=DEBUG -DBUILD_SHARED_LIBS=OFF &&\ cmake --build build --verbose && \ cmake --install build diff --git a/cmake/Modules/SetFortranFlags.cmake b/cmake/Modules/SetFortranFlags.cmake index cb5a40768..e78782ef3 100644 --- a/cmake/Modules/SetFortranFlags.cmake +++ b/cmake/Modules/SetFortranFlags.cmake @@ -83,17 +83,11 @@ SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}" # Determines whether the current Fortran Standard behavior of the compiler is fully implemented. -SET_COMPILE_FLAG(CMAKE_Fortran_Flags "${CMAKE_Fortran_FLAGS}" +SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}" Fortran "-standard-semantics" # Intel "/standard-semantics" # Intel Windows ) -# Tells the compiler to issue compile-time messages for nonstandard language elements (Fortran 2018). -SET_COMPILE_FLAG(CMAKE_Fortran_Flags "${CMAKE_Fortran_FLAGS}" - Fortran "-stand f18" # Intel - "/stand:f18" # Intel Windows - "-fstd=f2018" # GNU - ) # Allows for lines longer than 80 characters without truncation SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}" @@ -215,6 +209,12 @@ SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" Fortran "-Wno-unused-dummy-argument" # GNU ) +# Tells the compiler to issue compile-time messages for nonstandard language elements (Fortran 2018). +SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}" + Fortran "-stand f18" # Intel + "/stand:f18" # Intel Windows + "-fstd=f2018" # GNU + ) # Traceback SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" From 7f9cacbe8549d1305c057f0babce705df0d25b84 Mon Sep 17 00:00:00 2001 From: David Minton Date: Tue, 6 Jun 2023 12:52:01 -0400 Subject: [PATCH 60/95] Set debug flags correctly for the standards check --- cmake/Modules/SetFortranFlags.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/Modules/SetFortranFlags.cmake b/cmake/Modules/SetFortranFlags.cmake index e78782ef3..550738f13 100644 --- a/cmake/Modules/SetFortranFlags.cmake +++ b/cmake/Modules/SetFortranFlags.cmake @@ -210,7 +210,7 @@ SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" ) # Tells the compiler to issue compile-time messages for nonstandard language elements (Fortran 2018). -SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}" +SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" Fortran "-stand f18" # Intel "/stand:f18" # Intel Windows "-fstd=f2018" # GNU From ed4b2f0610b95fd893de3e81f6769cb532e441eb Mon Sep 17 00:00:00 2001 From: David Minton Date: Tue, 6 Jun 2023 12:54:11 -0400 Subject: [PATCH 61/95] Fixed issues that were causing do concurrent to give bad results when OMP_NUM_THREADS>1 when the F2018 locality-spec is used. --- src/helio/helio_gr.f90 | 16 ++++++++-------- src/swiftest/swiftest_gr.f90 | 26 +++++++++++++++----------- src/swiftest/swiftest_module.f90 | 10 +++++----- src/swiftest/swiftest_orbel.f90 | 32 ++++++++++++++++++-------------- src/swiftest/swiftest_util.f90 | 6 ++++-- src/whm/whm_gr.f90 | 16 ++++++++-------- 6 files changed, 58 insertions(+), 48 deletions(-) diff --git a/src/helio/helio_gr.f90 b/src/helio/helio_gr.f90 index 6de300cae..6b43714b7 100644 --- a/src/helio/helio_gr.f90 +++ b/src/helio/helio_gr.f90 @@ -75,14 +75,14 @@ pure module subroutine helio_gr_p4_pl(self, nbody_system, param, dt) if (self%nbody == 0) return - associate(pl => self) + associate(lmask => self%lmask, rh => self%rh, vb => self%vb, inv_c2 => param%inv_c2) npl = self%nbody #ifdef DOCONLOC - do concurrent(i = 1:npl, pl%lmask(i)) shared(param,pl,dt) + do concurrent(i = 1:npl, lmask(i)) shared(inv_c2, lmask, rh, vb, dt) #else - do concurrent(i = 1:npl, pl%lmask(i)) + do concurrent(i = 1:npl, lmask(i)) #endif - call swiftest_gr_p4_pos_kick(param, pl%rh(:, i), pl%vb(:, i), dt) + call swiftest_gr_p4_pos_kick(inv_c2, rh(1,i), rh(2,i), rh(3,i), vb(1,i), vb(2,i), vb(3,i), dt) end do end associate @@ -108,14 +108,14 @@ pure module subroutine helio_gr_p4_tp(self, nbody_system, param, dt) if (self%nbody == 0) return - associate(tp => self) + associate(rh => self%rh, vb => self%vb, lmask => self%lmask, inv_c2 => param%inv_c2) ntp = self%nbody #ifdef DOCONLOC - do concurrent(i = 1:ntp, tp%lmask(i)) shared(param,tp,dt) + do concurrent(i = 1:ntp, lmask(i)) shared(inv_c2, lmask, rh, vb, dt) #else - do concurrent(i = 1:ntp, tp%lmask(i)) + do concurrent(i = 1:ntp, lmask(i)) #endif - call swiftest_gr_p4_pos_kick(param, tp%rh(:, i), tp%vb(:, i), dt) + call swiftest_gr_p4_pos_kick(inv_c2, rh(1,i), rh(2,i), rh(3,i), vb(1,i), vb(2,i), vb(3,i), dt) end do end associate diff --git a/src/swiftest/swiftest_gr.f90 b/src/swiftest/swiftest_gr.f90 index 1985f6dd1..083e5de1b 100644 --- a/src/swiftest/swiftest_gr.f90 +++ b/src/swiftest/swiftest_gr.f90 @@ -87,7 +87,7 @@ pure module subroutine swiftest_gr_kick_getacch(mu, x, lmask, n, inv_c2, agr) end subroutine swiftest_gr_kick_getacch - pure module subroutine swiftest_gr_p4_pos_kick(param, x, v, dt) + pure elemental module subroutine swiftest_gr_p4_pos_kick(inv_c2, rx, ry, rz, vx, vy, vz, dt) !! author: David A. Minton !! !! Position kick due to p**4 term in the post-Newtonian correction @@ -100,17 +100,21 @@ pure module subroutine swiftest_gr_p4_pos_kick(param, x, v, dt) !! Adapted from David A. Minton's Swifter routine gr_whm_p4.f90 implicit none ! Arguments - class(swiftest_parameters), intent(in) :: param !! Current run configuration parameters - real(DP), dimension(:), intent(inout) :: x !! Position vector - real(DP), dimension(:), intent(in) :: v !! Velocity vector - real(DP), intent(in) :: dt !! Step size + real(DP), intent(in) :: inv_c2 !! One over speed of light squared (1/c**2) + real(DP), intent(inout) :: rx, ry, rz !! Position vector + real(DP), intent(in) :: vx, vy, vz !! Velocity vector + real(DP), intent(in) :: dt !! Step size ! Internals - real(DP), dimension(NDIM) :: dr - real(DP) :: vmag2 - - vmag2 = dot_product(v(:), v(:)) - dr(:) = -2 * param%inv_c2 * vmag2 * v(:) - x(:) = x(:) + dr(:) * dt + real(DP) :: drx, dry, drz + real(DP) :: vmag2 + + vmag2 = vx*vx + vy*vy + vz*vz + drx = -2 * inv_c2 * vmag2 * vx + dry = -2 * inv_c2 * vmag2 * vy + drz = -2 * inv_c2 * vmag2 * vz + rx = rx + drx * dt + ry = ry + dry * dt + rz = rz + drz * dt return end subroutine swiftest_gr_p4_pos_kick diff --git a/src/swiftest/swiftest_module.f90 b/src/swiftest/swiftest_module.f90 index 8349c12c1..a54e2351b 100644 --- a/src/swiftest/swiftest_module.f90 +++ b/src/swiftest/swiftest_module.f90 @@ -550,12 +550,12 @@ pure module subroutine swiftest_gr_kick_getacch(mu, x, lmask, n, inv_c2, agr) real(DP), dimension(:,:), intent(out) :: agr !! Accelerations end subroutine swiftest_gr_kick_getacch - pure module subroutine swiftest_gr_p4_pos_kick(param, x, v, dt) + pure elemental module subroutine swiftest_gr_p4_pos_kick(inv_c2, rx, ry, rz, vx, vy, vz, dt) implicit none - class(swiftest_parameters), intent(in) :: param !! Current run configuration parameters - real(DP), dimension(:), intent(inout) :: x !! Position vector - real(DP), dimension(:), intent(in) :: v !! Velocity vector - real(DP), intent(in) :: dt !! Step size + real(DP), intent(in) :: inv_c2 !! One over speed of light squared (1/c**2) + real(DP), intent(inout) :: rx, ry, rz !! Position vector + real(DP), intent(in) :: vx, vy, vz !! Velocity vector + real(DP), intent(in) :: dt !! Step size end subroutine swiftest_gr_p4_pos_kick pure module subroutine swiftest_gr_pseudovel2vel(param, mu, rh, pv, vh) diff --git a/src/swiftest/swiftest_orbel.f90 b/src/swiftest/swiftest_orbel.f90 index 3827c1b59..431d182ab 100644 --- a/src/swiftest/swiftest_orbel.f90 +++ b/src/swiftest/swiftest_orbel.f90 @@ -21,24 +21,28 @@ module subroutine swiftest_orbel_el2xv_vec(self, cb) class(swiftest_body), intent(inout) :: self !! Swiftest body object class(swiftest_cb), intent(inout) :: cb !! Swiftest central body objec ! Internals - integer(I4B) :: i + integer(I4B) :: i, n if (self%nbody == 0) return + n = self%nbody call self%set_mu(cb) + associate(mu => self%mu, a => self%a, e => self%e, inc => self%inc, capom => self%capom, omega => self%omega, & + capm => self%capm, rh => self%rh, vh => self%vh) #ifdef DOCONLOC - do concurrent (i = 1:self%nbody) shared(self) + do concurrent (i = 1:n) shared(mu, a, e, inc, capom, omega, capm, rh, vh) #else - do concurrent (i = 1:self%nbody) + do concurrent (i = 1:n) #endif - call swiftest_orbel_el2xv(self%mu(i), self%a(i), self%e(i), self%inc(i), self%capom(i), & - self%omega(i), self%capm(i), self%rh(:, i), self%vh(:, i)) - end do + call swiftest_orbel_el2xv(mu(i), a(i), e(i), inc(i), capom(i), omega(i), capm(i), & + rh(1,i), rh(2,i), rh(3,i), vh(1,i), vh(2,i), vh(3,i)) + end do + end associate return end subroutine swiftest_orbel_el2xv_vec - pure subroutine swiftest_orbel_el2xv(mu, a, ie, inc, capom, omega, capm, x, v) + pure elemental subroutine swiftest_orbel_el2xv(mu, a, ie, inc, capom, omega, capm, rx, ry, rz, vx, vy, vz) !! author: David A. Minton !! !! Compute osculating orbital elements from relative C)rtesian position and velocity @@ -56,7 +60,7 @@ pure subroutine swiftest_orbel_el2xv(mu, a, ie, inc, capom, omega, capm, x, v) implicit none real(DP), intent(in) :: mu real(DP), intent(in) :: a, ie, inc, capom, omega, capm - real(DP), dimension(:), intent(out) :: x, v + real(DP), intent(out) :: rx, ry, rz, vx, vy, vz integer(I4B) :: iorbit_type real(DP) :: e, cape, capf, zpara, em1 @@ -129,12 +133,12 @@ pure subroutine swiftest_orbel_el2xv(mu, a, ie, inc, capom, omega, capm, x, v) vfac2 = ri * sqgma endif !-- - x(1) = d11 * xfac1 + d21 * xfac2 - x(2) = d12 * xfac1 + d22 * xfac2 - x(3) = d13 * xfac1 + d23 * xfac2 - v(1) = d11 * vfac1 + d21 * vfac2 - v(2) = d12 * vfac1 + d22 * vfac2 - v(3) = d13 * vfac1 + d23 * vfac2 + rx = d11 * xfac1 + d21 * xfac2 + ry = d12 * xfac1 + d22 * xfac2 + rz = d13 * xfac1 + d23 * xfac2 + vx = d11 * vfac1 + d21 * vfac2 + vy = d12 * vfac1 + d22 * vfac2 + vz = d13 * vfac1 + d23 * vfac2 return end subroutine swiftest_orbel_el2xv diff --git a/src/swiftest/swiftest_util.f90 b/src/swiftest/swiftest_util.f90 index c164a365a..f3ce3082f 100644 --- a/src/swiftest/swiftest_util.f90 +++ b/src/swiftest/swiftest_util.f90 @@ -1213,7 +1213,9 @@ module subroutine swiftest_util_get_energy_and_momentum_system(self, param) #else do concurrent (i = 1:npl, pl%lmask(i)) #endif - h(:) = pl%rb(:,i) .cross. pl%vb(:,i) + h(1) = pl%rb(2,i) * pl%vb(3,i) - pl%rb(3,i) * pl%vb(2,i) + h(2) = pl%rb(3,i) * pl%vb(1,i) - pl%rb(1,i) * pl%vb(3,i) + h(3) = pl%rb(1,i) * pl%vb(2,i) - pl%rb(2,i) * pl%vb(1,i) ! Angular momentum from orbit Lplorbit(:,i) = pl%mass(i) * h(:) @@ -1269,7 +1271,7 @@ module subroutine swiftest_util_get_energy_and_momentum_system(self, param) nbody_system%ke_orbit = 0.5_DP * (kecb + sum(kepl(1:npl), pl%lmask(1:npl))) #ifdef DOCONLOC - do concurrent (j = 1:NDIM) shared(nbody_system,pl,Lcborbit,Lplorbit) + do concurrent (j = 1:NDIM) shared(nbody_system,pl,Lcborbit,Lplorbit,npl) #else do concurrent (j = 1:NDIM) #endif diff --git a/src/whm/whm_gr.f90 b/src/whm/whm_gr.f90 index c46a5ce2d..6e23ca21b 100644 --- a/src/whm/whm_gr.f90 +++ b/src/whm/whm_gr.f90 @@ -84,14 +84,14 @@ pure module subroutine whm_gr_p4_pl(self, nbody_system, param, dt) if (self%nbody == 0) return - associate(pl => self) + associate(xj => self%xj, vj => self%vj, lmask => self%lmask, inv_c2 => param%inv_c2) npl = self%nbody #ifdef DOCONLOC - do concurrent(i = 1:npl, pl%lmask(i)) shared(pl,dt) + do concurrent(i = 1:npl, lmask(i)) shared(lmask, inv_c2, xj, vj,dt) #else - do concurrent(i = 1:npl, pl%lmask(i)) + do concurrent(i = 1:npl, lmask(i)) #endif - call swiftest_gr_p4_pos_kick(param, pl%xj(:, i), pl%vj(:, i), dt) + call swiftest_gr_p4_pos_kick(inv_c2, xj(1,i), xj(2,i), xj(3,i), vj(1,i), vj(2,i), vj(3,i), dt) end do end associate @@ -115,15 +115,15 @@ pure module subroutine whm_gr_p4_tp(self, nbody_system, param, dt) ! Internals integer(I4B) :: i, ntp - associate(tp => self) + associate(rh => self%rh, vh => self%vh, lmask => self%lmask, inv_c2 => param%inv_c2) ntp = self%nbody if (ntp == 0) return #ifdef DOCONLOC - do concurrent(i = 1:ntp, tp%lmask(i)) shared(tp,dt) + do concurrent(i = 1:ntp, lmask(i)) shared(lmask, rh, vh, inv_c2, dt) #else - do concurrent(i = 1:ntp, tp%lmask(i)) + do concurrent(i = 1:ntp, lmask(i)) #endif - call swiftest_gr_p4_pos_kick(param, tp%rh(:, i), tp%vh(:, i), dt) + call swiftest_gr_p4_pos_kick(inv_c2, rh(1,i), rh(2,i), rh(3,i), vh(1,i), vh(2,i), vh(3,i), dt) end do end associate From 2aacbe3f63a23730645552e70412efc1b68a7c16 Mon Sep 17 00:00:00 2001 From: David Minton Date: Tue, 6 Jun 2023 12:54:37 -0400 Subject: [PATCH 62/95] Fixed line lengths based on standards compliance warning flags in debug mode --- src/base/base_module.f90 | 311 +++++++++++++++++++-------------- src/globals/globals_module.f90 | 18 +- 2 files changed, 189 insertions(+), 140 deletions(-) diff --git a/src/base/base_module.f90 b/src/base/base_module.f90 index 0f91e3473..502a42515 100644 --- a/src/base/base_module.f90 +++ b/src/base/base_module.f90 @@ -22,90 +22,100 @@ module base !> User defined parameters that are read in from the parameters input file. !> Each paramter is initialized to a default values. type, abstract :: base_parameters - character(STRMAX) :: integrator !! Name of the nbody integrator used - character(STRMAX) :: param_file_name !! The name of the parameter file - real(DP) :: t0 = 0.0_DP !! Integration reference time - real(DP) :: tstart = -1.0_DP !! Integration start time - real(DP) :: tstop = -1.0_DP !! Integration stop time - real(DP) :: dt = -1.0_DP !! Time step - integer(I8B) :: iloop = 0_I8B !! Main loop counter - integer(I8B) :: nloops = 0_I8B !! Total number of loops to execute - integer(I8B) :: istart = 0_I8B !! Starting index for loop counter - integer(I4B) :: iout = 0 !! Output cadence counter - integer(I4B) :: idump = 0 !! Dump cadence counter - integer(I4B) :: nout = 0 !! Current output step - integer(I4B) :: istep = 0 !! Current value of istep (used for time stretching) - character(STRMAX) :: incbfile = CB_INFILE !! Name of input file for the central body - character(STRMAX) :: inplfile = PL_INFILE !! Name of input file for massive bodies - character(STRMAX) :: intpfile = TP_INFILE !! Name of input file for test particles - character(STRMAX) :: nc_in = NC_INFILE !! Name of system input file for NetCDF input - character(STRMAX) :: in_type = "NETCDF_DOUBLE" !! Data representation type of input data files - character(STRMAX) :: in_form = "XV" !! Format of input data files ("EL" or ["XV"]) - integer(I4B) :: istep_out = -1 !! Number of time steps between saved outputs - integer(I4B) :: nstep_out = -1 !! Total number of saved outputs - real(DP) :: fstep_out = 1.0_DP !! The output step time stretching factor - logical :: ltstretch = .false. !! Whether to employ time stretching or not - character(STRMAX) :: outfile = BIN_OUTFILE !! Name of output binary file - character(STRMAX) :: out_type = "NETCDF_DOUBLE" !! Binary format of output file - character(STRMAX) :: out_form = "XVEL" !! Data to write to output file - character(STRMAX) :: out_stat = 'NEW' !! Open status for output binary file - integer(I4B) :: dump_cadence = 10 !! Number of output steps between dumping simulation data to file - real(DP) :: rmin = -1.0_DP !! Minimum heliocentric radius for test particle - real(DP) :: rmax = -1.0_DP !! Maximum heliocentric radius for test particle - real(DP) :: rmaxu = -1.0_DP !! Maximum unbound heliocentric radius for test particle - real(DP) :: qmin = -1.0_DP !! Minimum pericenter distance for test particle - character(STRMAX) :: qmin_coord = "HELIO" !! Coordinate frame to use for qmin (["HELIO"] or "BARY") - real(DP) :: qmin_alo = -1.0_DP !! Minimum semimajor axis for qmin - real(DP) :: qmin_ahi = -1.0_DP !! Maximum semimajor axis for qmin - real(QP) :: MU2KG = -1.0_QP !! Converts mass units to grams - real(QP) :: TU2S = -1.0_QP !! Converts time units to seconds - real(QP) :: DU2M = -1.0_QP !! Converts distance unit to centimeters - real(DP) :: GU = -1.0_DP !! Universal gravitational constant in the system units - real(DP) :: inv_c2 = -1.0_DP !! Inverse speed of light squared in the system units - real(DP) :: GMTINY = -1.0_DP !! Smallest G*mass that is fully gravitating - real(DP) :: min_GMfrag = -1.0_DP !! Smallest G*mass that can be produced in a fragmentation event - real(DP) :: nfrag_reduction = 30.0_DP !! Reduction factor for limiting the number of fragments in a collision - integer(I4B), dimension(:), allocatable :: seed !! Random seeds for fragmentation modeling - logical :: lmtiny_pl = .false. !! Include semi-interacting massive bodies - character(STRMAX) :: collision_model = "MERGE" !! The Coll - character(STRMAX) :: encounter_save = "NONE" !! Indicate if and how encounter data should be saved - logical :: lenc_save_trajectory = .false. !! Indicates that when encounters are saved, the full trajectory through recursion steps are saved - logical :: lenc_save_closest = .false. !! Indicates that when encounters are saved, the closest approach distance between pairs of bodies is saved - character(NAMELEN) :: interaction_loops = "ADAPTIVE" !! Method used to compute interaction loops. Options are "TRIANGULAR", "FLAT", or "ADAPTIVE" - character(NAMELEN) :: encounter_check_plpl = "ADAPTIVE" !! Method used to compute pl-pl encounter checks. Options are "TRIANGULAR", "SORTSWEEP", or "ADAPTIVE" - character(NAMELEN) :: encounter_check_pltp = "ADAPTIVE" !! Method used to compute pl-tp encounter checks. Options are "TRIANGULAR", "SORTSWEEP", or "ADAPTIVE" - logical :: lcoarray = .false. !! Use Coarrays for test particle parallelization. - - ! The following are used internally, and are not set by the user, but instead are determined by the input value of INTERACTION_LOOPS + character(STRMAX) :: integrator !! Name of the nbody integrator used + character(STRMAX) :: param_file_name !! The name of the parameter file + real(DP) :: t0 = 0.0_DP !! Integration reference time + real(DP) :: tstart = -1.0_DP !! Integration start time + real(DP) :: tstop = -1.0_DP !! Integration stop time + real(DP) :: dt = -1.0_DP !! Time step + integer(I8B) :: iloop = 0_I8B !! Main loop counter + integer(I8B) :: nloops = 0_I8B !! Total number of loops to execute + integer(I8B) :: istart = 0_I8B !! Starting index for loop counter + integer(I4B) :: iout = 0 !! Output cadence counter + integer(I4B) :: idump = 0 !! Dump cadence counter + integer(I4B) :: nout = 0 !! Current output step + integer(I4B) :: istep = 0 !! Current value of istep (used for time stretching) + character(STRMAX) :: incbfile = CB_INFILE !! Name of input file for the central body + character(STRMAX) :: inplfile = PL_INFILE !! Name of input file for massive bodies + character(STRMAX) :: intpfile = TP_INFILE !! Name of input file for test particles + character(STRMAX) :: nc_in = NC_INFILE !! Name of system input file for NetCDF input + character(STRMAX) :: in_type = "NETCDF_DOUBLE" !! Data representation type of input data files + character(STRMAX) :: in_form = "XV" !! Format of input data files ("EL" or ["XV"]) + integer(I4B) :: istep_out = -1 !! Number of time steps between saved outputs + integer(I4B) :: nstep_out = -1 !! Total number of saved outputs + real(DP) :: fstep_out = 1.0_DP !! The output step time stretching factor + logical :: ltstretch = .false. !! Whether to employ time stretching or not + character(STRMAX) :: outfile = BIN_OUTFILE !! Name of output binary file + character(STRMAX) :: out_type = "NETCDF_DOUBLE" !! Binary format of output file + character(STRMAX) :: out_form = "XVEL" !! Data to write to output file + character(STRMAX) :: out_stat = 'NEW' !! Open status for output binary file + integer(I4B) :: dump_cadence = 10 !! Number of output steps between dumping simulation data to file + real(DP) :: rmin = -1.0_DP !! Minimum heliocentric radius for test particle + real(DP) :: rmax = -1.0_DP !! Maximum heliocentric radius for test particle + real(DP) :: rmaxu = -1.0_DP !! Maximum unbound heliocentric radius for test particle + real(DP) :: qmin = -1.0_DP !! Minimum pericenter distance for test particle + character(STRMAX) :: qmin_coord = "HELIO" !! Coordinate frame to use for qmin (["HELIO"] or "BARY") + real(DP) :: qmin_alo = -1.0_DP !! Minimum semimajor axis for qmin + real(DP) :: qmin_ahi = -1.0_DP !! Maximum semimajor axis for qmin + real(QP) :: MU2KG = -1.0_QP !! Converts mass units to grams + real(QP) :: TU2S = -1.0_QP !! Converts time units to seconds + real(QP) :: DU2M = -1.0_QP !! Converts distance unit to centimeters + real(DP) :: GU = -1.0_DP !! Universal gravitational constant in the system units + real(DP) :: inv_c2 = -1.0_DP !! Inverse speed of light squared in the system units + real(DP) :: GMTINY = -1.0_DP !! Smallest G*mass that is fully gravitating + real(DP) :: min_GMfrag = -1.0_DP !! Smallest G*mass that can be produced in a fragmentation event + real(DP) :: nfrag_reduction = 30.0_DP !! Reduction factor for limiting the number of collision fragments + integer(I4B), dimension(:), allocatable :: seed !! Random seeds for fragmentation modeling + logical :: lmtiny_pl = .false. !! Include semi-interacting massive bodies + character(STRMAX) :: collision_model = "MERGE" !! The Coll + character(STRMAX) :: encounter_save = "NONE" !! Indicate if and how encounter data should be saved + logical :: lenc_save_trajectory = .false. !! Indicates that when encounters are saved, the full trajectory + !! through recursion steps are saved + logical :: lenc_save_closest = .false. !! Indicates that when encounters are saved, the closest approach + !! distance between pairs of bodies is saved + character(NAMELEN):: interaction_loops = "ADAPTIVE" !! Method used to compute interaction loops. + !! Options are "TRIANGULAR", "FLAT", or "ADAPTIVE" + character(NAMELEN):: encounter_check_plpl = "ADAPTIVE" !! Method used to compute pl-pl encounter checks. + !! Options are "TRIANGULAR", "SORTSWEEP", or "ADAPTIVE" + character(NAMELEN):: encounter_check_pltp = "ADAPTIVE" !! Method used to compute pl-tp encounter checks. + !! Options are "TRIANGULAR", "SORTSWEEP", or "ADAPTIVE" + logical :: lcoarray = .false. !! Use Coarrays for test particle parallelization. + + ! The following are not set by the user, but instead are determined by the input value of INTERACTION_LOOPS logical :: lflatten_interactions = .false. !! Use the flattened upper triangular matrix for pl-pl interaction loops - logical :: lencounter_sas_plpl = .false. !! Use the Sort and Sweep algorithm to prune the encounter list before checking for close encounters - logical :: lencounter_sas_pltp = .false. !! Use the Sort and Sweep algorithm to prune the encounter list before checking for close encounters + logical :: lencounter_sas_plpl = .false. !! Use the Sort and Sweep algorithm to prune the encounter list before checking + !! for close encounters + logical :: lencounter_sas_pltp = .false. !! Use the Sort and Sweep algorithm to prune the encounter list before checking + !! for close encounters ! Logical flags to turn on or off various features of the code - logical :: lrhill_present = .false. !! Hill radii are given as an input rather than calculated by the code (can be used to inflate close encounter regions manually) + logical :: lrhill_present = .false. !! Hill radii are given as an input rather than calculated by the code (can be used to + !! inflate close encounter regions manually) logical :: lextra_force = .false. !! User defined force function turned on logical :: lbig_discard = .false. !! Save big bodies on every discard logical :: lclose = .false. !! Turn on close encounters logical :: lenergy = .false. !! Track the total energy of the system - logical :: loblatecb = .false. !! Calculate acceleration from oblate central body (automatically turns true if nonzero J2 is input) + logical :: loblatecb = .false. !! Calculate acceleration from oblate central body (automatically turns true if nonzero J2 + !! is input) logical :: lrotation = .false. !! Include rotation states of big bodies logical :: ltides = .false. !! Include tidal dissipation - ! Initial values to pass to the energy report subroutine (usually only used in the case of a restart, otherwise these will be updated with initial conditions values) - real(DP) :: E_orbit_orig = 0.0_DP !! Initial orbital energy + ! Initial values to pass to the energy report subroutine (usually only used in the case of a restart, otherwise these will be + ! updated with initial conditions values) + real(DP) :: E_orbit_orig = 0.0_DP !! Initial orbital energy real(DP) :: GMtot_orig = 0.0_DP !! Initial system mass - real(DP), dimension(NDIM) :: L_total_orig = 0.0_DP !! Initial total angular momentum vector - real(DP), dimension(NDIM) :: L_orbit_orig = 0.0_DP !! Initial orbital angular momentum - real(DP), dimension(NDIM) :: L_spin_orig = 0.0_DP !! Initial spin angular momentum vector - real(DP), dimension(NDIM) :: L_escape = 0.0_DP !! Angular momentum of bodies that escaped the system (used for bookeeping) + real(DP), dimension(NDIM) :: L_total_orig = 0.0_DP !! Initial total angular momentum vector + real(DP), dimension(NDIM) :: L_orbit_orig = 0.0_DP !! Initial orbital angular momentum + real(DP), dimension(NDIM) :: L_spin_orig = 0.0_DP !! Initial spin angular momentum vector + real(DP), dimension(NDIM) :: L_escape = 0.0_DP !! Angular momentum of escaped bodies (used for bookeeping) real(DP) :: GMescape = 0.0_DP !! Mass of bodies that escaped the system (used for bookeeping) - real(DP) :: E_collisions = 0.0_DP !! Energy lost from system due to collisions - real(DP) :: E_untracked = 0.0_DP !! Energy gained from system due to escaped bodies + real(DP) :: E_collisions = 0.0_DP !! Energy lost from system due to collisions + real(DP) :: E_untracked = 0.0_DP !! Energy gained from system due to escaped bodies logical :: lfirstenergy = .true. !! This is the first time computing energe logical :: lfirstkick = .true. !! Initiate the first kick in a symplectic step logical :: lrestart = .false. !! Indicates whether or not this is a restarted run - character(NAMELEN) :: display_style !! Style of the output display {"STANDARD", "COMPACT"}). Default is "STANDARD" + character(NAMELEN) :: display_style !! Style of the output display {["STANDARD"], "COMPACT"}). integer(I4B) :: display_unit !! File unit number for display (either to stdout or to a log file) logical :: log_output = .false. !! Logs the output to file instead of displaying it on the terminal @@ -137,8 +147,10 @@ subroutine abstract_io_param_reader(self, unit, iotype, v_list, iostat, iomsg) implicit none class(base_parameters), intent(inout) :: self !! Collection of parameters integer(I4B), intent(in) :: unit !! File unit number - character(len=*), intent(in) :: iotype !! Dummy argument passed to the input/output procedure contains the text from the char-literal-constant, prefixed with DT. - !! If you do not include a char-literal-constant, the iotype argument contains only DT. + character(len=*), intent(in) :: iotype !! Dummy argument passed to the input/output procedure contains the + !! text from the char-literal-constant, prefixed with DT. If you do + !! not include a char-literal-constant, the iotype argument contains + !! only DT. character(len=*), intent(in) :: v_list(:) !! The first element passes the integrator code to the reader integer(I4B), intent(out) :: iostat !! IO status code character(len=*), intent(inout) :: iomsg !! Message to pass if iostat /= 0 @@ -149,8 +161,10 @@ subroutine abstract_io_param_writer(self, unit, iotype, v_list, iostat, iomsg) implicit none class(base_parameters), intent(in) :: self !! Collection of parameters integer(I4B), intent(in) :: unit !! File unit number - character(len=*), intent(in) :: iotype !! Dummy argument passed to the input/output procedure contains the text from the char-literal-constant, prefixed with DT. - !! If you do not include a char-literal-constant, the iotype argument contains only DT. + character(len=*), intent(in) :: iotype !! Dummy argument passed to the input/output procedure contains the + !! text from the char-literal-constant, prefixed with DT. If you do + !! not include a char-literal-constant, the iotype argument contains + !! only DT. integer(I4B), intent(in) :: v_list(:) !! Not used in this procedure integer(I4B), intent(out) :: iostat !! IO status code character(len=*), intent(inout) :: iomsg !! Message to pass if iostat /= 0 @@ -168,7 +182,8 @@ end subroutine abstract_io_read_in_param type :: base_storage_frame class(*), allocatable :: item contains - procedure :: store => base_util_copy_store !! Stores a snapshot of the nbody system so that later it can be retrieved for saving to file. + procedure :: store => base_util_copy_store !! Stores a snapshot of the nbody system so that later it can be + !! retrieved for saving to file. generic :: assignment(=) => store final :: base_final_storage_frame end type @@ -179,25 +194,26 @@ end subroutine abstract_io_read_in_param integer(I4B) :: nframes !! Total number of frames that can be stored !! An class that establishes the pattern for various storage objects - type(base_storage_frame), dimension(:), allocatable :: frame !! Array of stored frames - integer(I4B) :: iframe = 0 !! Index of the last frame stored in the system - integer(I4B) :: nid !! Number of unique id values in all saved snapshots - integer(I4B), dimension(:), allocatable :: idvals !! The set of unique id values contained in the snapshots - integer(I4B), dimension(:), allocatable :: idmap !! The id value -> index map - integer(I4B) :: nt !! Number of unique time values in all saved snapshots - real(DP), dimension(:), allocatable :: tvals !! The set of unique time values contained in the snapshots - integer(I4B), dimension(:), allocatable :: tmap !! The t value -> index map + type(base_storage_frame), dimension(:), allocatable :: frame !! Array of stored frames + integer(I4B) :: iframe = 0 !! Index of the last frame stored in the system + integer(I4B) :: nid !! Number of unique id values in all saved snapshots + integer(I4B), dimension(:), allocatable :: idvals !! The set of unique id values contained in the snapshots + integer(I4B), dimension(:), allocatable :: idmap !! The id value -> index map + integer(I4B) :: nt !! Number of unique time values in all saved snapshots + real(DP), dimension(:), allocatable :: tvals !! The set of unique time values contained in the snapshots + integer(I4B), dimension(:), allocatable :: tmap !! The t value -> index map contains procedure :: dealloc => base_util_dealloc_storage !! Deallocates all allocatables - procedure :: reset => base_util_reset_storage !! Resets the storage object back to its original state by removing all of the saved items from the storage frames + procedure :: reset => base_util_reset_storage !! Resets the storage object back to its original state by removing all of + !! the saved items from the storage frames procedure :: resize => base_util_resize_storage !! Resizes storage if it is too small procedure :: setup => base_util_setup_storage !! Sets up a storage system with a set number of frames procedure :: save => base_util_snapshot_save !! Takes a snapshot of the current system end type base_storage - !> Class definition for the particle origin information object. This object is used to track time, location, and collisional regime - !> of fragments produced in collisional events. + !> Class definition for the particle origin information object. This object is used to track time, location, and collisional + !> regime of fragments produced in collisional events. type, abstract :: base_particle_info end type base_particle_info @@ -291,13 +307,15 @@ end subroutine abstract_util_dealloc_object subroutine base_util_append_arr_char_string(arr, source, nold, lsource_mask) !! author: David A. Minton !! - !! Append a single array of character string type onto another. If the destination array is not allocated, or is not big enough, this will allocate space for it. + !! Append a single array of character string type onto another. If the destination array is not allocated, or is not big + !! enough, this will allocate space for it. implicit none ! Arguments - character(len=STRMAX), dimension(:), allocatable, intent(inout) :: arr !! Destination array - character(len=STRMAX), dimension(:), allocatable, intent(in) :: source !! Array to append - integer(I4B), intent(in), optional :: nold !! Extent of original array. If passed, the source array will begin at arr(nold+1). Otherwise, the size of arr will be used. - logical, dimension(:), intent(in), optional :: lsource_mask !! Logical mask indicating which elements to append to + character(len=STRMAX), dimension(:), allocatable, intent(inout) :: arr !! Destination array + character(len=STRMAX), dimension(:), allocatable, intent(in) :: source !! Array to append + integer(I4B), intent(in), optional :: nold !! Extent of original array. If passed, the source array will begin at + !! arr(nold+1). Otherwise, the size of arr will be used. + logical, dimension(:), intent(in), optional :: lsource_mask !! Logical mask indicating which elements to append to ! Internals integer(I4B) :: nnew, nsrc, nend_orig @@ -336,13 +354,15 @@ end subroutine base_util_append_arr_char_string subroutine base_util_append_arr_DP(arr, source, nold, lsource_mask) !! author: David A. Minton !! - !! Append a single array of double precision type onto another. If the destination array is not allocated, or is not big enough, this will allocate space for it. + !! Append a single array of double precision type onto another. If the destination array is not allocated, or is not big + !! enough, this will allocate space for it. implicit none ! Arguments - real(DP), dimension(:), allocatable, intent(inout) :: arr !! Destination array - real(DP), dimension(:), allocatable, intent(in) :: source !! Array to append - integer(I4B), intent(in), optional :: nold !! Extent of original array. If passed, the source array will begin at arr(nold+1). Otherwise, the size of arr will be used. - logical, dimension(:), intent(in), optional :: lsource_mask !! Logical mask indicating which elements to append to + real(DP), dimension(:), allocatable, intent(inout) :: arr !! Destination array + real(DP), dimension(:), allocatable, intent(in) :: source !! Array to append + integer(I4B), intent(in), optional :: nold !! Extent of original array. If passed, the source array will begin at + !! arr(nold+1). Otherwise, the size of arr will be used. + logical, dimension(:), intent(in), optional :: lsource_mask !! Logical mask indicating which elements to append to ! Internals integer(I4B) :: nnew, nsrc, nend_orig @@ -381,13 +401,15 @@ end subroutine base_util_append_arr_DP subroutine base_util_append_arr_DPvec(arr, source, nold, lsource_mask) !! author: David A. Minton !! - !! Append a single array of double precision vector type of size (NDIM, n) onto another. If the destination array is not allocated, or is not big enough, this will allocate space for it. + !! Append a single array of double precision vector type of size (NDIM, n) onto another. If the destination array is not + !! allocated, or is not big enough, this will allocate space for it. implicit none ! Arguments - real(DP), dimension(:,:), allocatable, intent(inout) :: arr !! Destination array - real(DP), dimension(:,:), allocatable, intent(in) :: source !! Array to append - integer(I4B), intent(in), optional :: nold !! Extent of original array. If passed, the source array will begin at arr(nold+1). Otherwise, the size of arr will be used. - logical, dimension(:), intent(in), optional :: lsource_mask !! Logical mask indicating which elements to append to + real(DP), dimension(:,:), allocatable, intent(inout) :: arr !! Destination array + real(DP), dimension(:,:), allocatable, intent(in) :: source !! Array to append + integer(I4B), intent(in), optional :: nold !! Extent of original array. If passed, the source array will begin at + !! arr(nold+1). Otherwise, the size of arr will be used. + logical, dimension(:), intent(in), optional :: lsource_mask !! Logical mask indicating which elements to append to ! Internals integer(I4B) :: nnew, nsrc, nend_orig @@ -428,13 +450,15 @@ end subroutine base_util_append_arr_DPvec subroutine base_util_append_arr_I4B(arr, source, nold, lsource_mask) !! author: David A. Minton !! - !! Append a single array of integer(I4B) onto another. If the destination array is not allocated, or is not big enough, this will allocate space for it. + !! Append a single array of integer(I4B) onto another. If the destination array is not allocated, or is not big enough, + !! this will allocate space for it. implicit none ! Arguments - integer(I4B), dimension(:), allocatable, intent(inout) :: arr !! Destination array - integer(I4B), dimension(:), allocatable, intent(in) :: source !! Array to append - integer(I4B), intent(in), optional :: nold !! Extent of original array. If passed, the source array will begin at arr(nold+1). Otherwise, the size of arr will be used. - logical, dimension(:), intent(in), optional :: lsource_mask !! Logical mask indicating which elements to append to + integer(I4B), dimension(:), allocatable, intent(inout) :: arr !! Destination array + integer(I4B), dimension(:), allocatable, intent(in) :: source !! Array to append + integer(I4B), intent(in), optional :: nold !! Extent of original array. If passed, the source array will begin at + !! arr(nold+1). Otherwise, the size of arr will be used. + logical, dimension(:), intent(in), optional :: lsource_mask !! Logical mask indicating which elements to append to ! Internals integer(I4B) :: nnew, nsrc, nend_orig @@ -473,13 +497,15 @@ end subroutine base_util_append_arr_I4B subroutine base_util_append_arr_logical(arr, source, nold, lsource_mask) !! author: David A. Minton !! - !! Append a single array of logical type onto another. If the destination array is not allocated, or is not big enough, this will allocate space for it. + !! Append a single array of logical type onto another. If the destination array is not allocated, or is not big enough, + !! this will allocate space for it. implicit none ! Arguments - logical, dimension(:), allocatable, intent(inout) :: arr !! Destination array - logical, dimension(:), allocatable, intent(in) :: source !! Array to append - integer(I4B), intent(in), optional :: nold !! Extent of original array. If passed, the source array will begin at arr(nold+1). Otherwise, the size of arr will be used. - logical, dimension(:), intent(in), optional :: lsource_mask !! Logical mask indicating which elements to append to + logical, dimension(:), allocatable, intent(inout) :: arr !! Destination array + logical, dimension(:), allocatable, intent(in) :: source !! Array to append + integer(I4B), intent(in), optional :: nold !! Extent of original array. If passed, the source array will begin at + !! arr(nold+1). Otherwise, the size of arr will be used. + logical, dimension(:), intent(in), optional :: lsource_mask !! Logical mask indicating which elements to append to ! Internals integer(I4B) :: nnew, nsrc, nend_orig @@ -574,7 +600,8 @@ subroutine base_util_exit(code) character(*), parameter :: BAR = '("------------------------------------------------")' character(*), parameter :: SUCCESS_MSG = '(/, "Normal termination of Swiftest (version ", f3.1, ")")' character(*), parameter :: FAIL_MSG = '(/, "Terminating Swiftest (version ", f3.1, ") due to error!!")' - character(*), parameter :: USAGE_MSG = '("Usage: swiftest [bs|helio|ra15|rmvs|symba|tu4|whm] [standard|compact|progress|NONE]")' + character(*), parameter :: USAGE_MSG = '("Usage: swiftest [bs|helio|ra15|rmvs|symba|tu4|whm] ' // & + '[standard|compact|progress|NONE]")' character(*), parameter :: HELP_MSG = USAGE_MSG select case(code) @@ -605,7 +632,8 @@ subroutine base_util_fill_arr_char_string(keeps, inserts, lfill_list) ! Arguments character(len=STRMAX), dimension(:), allocatable, intent(inout) :: keeps !! Array of values to keep character(len=STRMAX), dimension(:), allocatable, intent(in) :: inserts !! Array of values to insert into keep - logical, dimension(:), intent(in) :: lfill_list !! Logical array of bodies to merge into the keeps + logical, dimension(:), intent(in) :: lfill_list !! Logical array of bodies to merge into the + !! keeps if (.not.allocated(keeps) .or. .not.allocated(inserts)) return @@ -702,7 +730,8 @@ end subroutine base_util_fill_arr_logical subroutine base_util_reset_storage(self) !! author: David A. Minton !! - !! Resets the storage object back to its original state by removing all of the saved items from the storage frames, but does not deallocate the frames + !! Resets the storage object back to its original state by removing all of the saved items from the storage frames, but + !! does not deallocate the frames implicit none ! Arguments class(base_storage), intent(inout) :: self @@ -736,7 +765,7 @@ subroutine base_util_resize_arr_char_string(arr, nnew) character(len=STRMAX), dimension(:), allocatable, intent(inout) :: arr !! Array to resize integer(I4B), intent(in) :: nnew !! New size ! Internals - character(len=STRMAX), dimension(:), allocatable :: tmp !! Temporary storage array in case the input array is already allocated + character(len=STRMAX), dimension(:), allocatable :: tmp !! Temp. storage array in case the input array is already allocated integer(I4B) :: nold !! Old size if (nnew < 0) return @@ -1008,10 +1037,12 @@ end subroutine base_util_setup_storage subroutine base_util_snapshot_save(self, snapshot) !! author: David A. Minton !! - !! Checks the current size of the storage object against the required size and extends it by a factor of 2 more than requested if it is too small. - !! Note: The reason to extend it by a factor of 2 is for performance. When there are many enounters per step, resizing every time you want to add an - !! encounter takes significant computational effort. Resizing by a factor of 2 is a tradeoff between performance (fewer resize calls) and memory managment - !! Memory usage grows by a factor of 2 each time it fills up, but no more. + !! Checks the current size of the storage object against the required size and extends it by a factor of 2 more than + !! requested if it is too small. + !! Note: The reason to extend it by a factor of 2 is for performance. When there are many enounters per step, resizing + !! every time you want to add an encounter takes significant computational effort. Resizing by a factor of 2 is a tradeoff + !! between performance (fewer resize calls) and memory managment. Memory usage grows by a factor of 2 each time it fills + !! up, but no more. implicit none ! Arguments class(base_storage), intent(inout) :: self !! Storage encounter storage object @@ -1043,8 +1074,11 @@ subroutine base_util_spill_arr_char_string(keeps, discards, lspill_list, ldestru ! Arguments character(len=STRMAX), dimension(:), allocatable, intent(inout) :: keeps !! Array of values to keep character(len=STRMAX), dimension(:), allocatable, intent(inout) :: discards !! Array of discards - logical, dimension(:), intent(in) :: lspill_list !! Logical array of bodies to spill into the discards - logical, intent(in) :: ldestructive !! Logical flag indicating whether or not this operation should alter the keeps array or not + logical, dimension(:), intent(in) :: lspill_list !! Logical array of bodies to spill into + !! the discards + logical, intent(in) :: ldestructive !! Logical flag indicating whether or not + !! this operation should alter the keeps + !! array or not ! Internals integer(I4B) :: nspill, nkeep, nlist character(len=STRMAX), dimension(:), allocatable :: tmp !! Array of values to keep @@ -1087,7 +1121,8 @@ subroutine base_util_spill_arr_DP(keeps, discards, lspill_list, ldestructive) real(DP), dimension(:), allocatable, intent(inout) :: keeps !! Array of values to keep real(DP), dimension(:), allocatable, intent(inout) :: discards !! Array of discards logical, dimension(:), intent(in) :: lspill_list !! Logical array of bodies to spill into the discardss - logical, intent(in) :: ldestructive !! Logical flag indicating whether or not this operation should alter the keeps array or not + logical, intent(in) :: ldestructive !! Logical flag indicating whether or not this operation + !! should alter the keeps array or not ! Internals integer(I4B) :: nspill, nkeep, nlist real(DP), dimension(:), allocatable :: tmp !! Array of values to keep @@ -1130,7 +1165,8 @@ subroutine base_util_spill_arr_DPvec(keeps, discards, lspill_list, ldestructive) real(DP), dimension(:,:), allocatable, intent(inout) :: keeps !! Array of values to keep real(DP), dimension(:,:), allocatable, intent(inout) :: discards !! Array discards logical, dimension(:), intent(in) :: lspill_list !! Logical array of bodies to spill into the discards - logical, intent(in) :: ldestructive !! Logical flag indicating whether or not this operation should alter the keeps array or not + logical, intent(in) :: ldestructive !! Logical flag indicating whether or not this + !! operation should alter the keeps array or not ! Internals integer(I4B) :: i, nspill, nkeep, nlist real(DP), dimension(:,:), allocatable :: tmp !! Array of values to keep @@ -1174,13 +1210,14 @@ subroutine base_util_spill_arr_I4B(keeps, discards, lspill_list, ldestructive) !! This is the inverse of a spill operation implicit none ! Arguments - integer(I4B), dimension(:), allocatable, intent(inout) :: keeps !! Array of values to keep - integer(I4B), dimension(:), allocatable, intent(inout) :: discards !! Array of discards - logical, dimension(:), intent(in) :: lspill_list !! Logical array of bodies to spill into the discards - logical, intent(in) :: ldestructive !! Logical flag indicating whether or not this operation should alter the keeps array or not + integer(I4B), dimension(:), allocatable, intent(inout) :: keeps !! Array of values to keep + integer(I4B), dimension(:), allocatable, intent(inout) :: discards !! Array of discards + logical, dimension(:), intent(in) :: lspill_list !! Logical array of bodies to spill into the discards + logical, intent(in) :: ldestructive!! Logical flag indicating whether or not this + !! operation should alter the keeps array or not ! Internals integer(I4B) :: nspill, nkeep, nlist - integer(I4B), dimension(:), allocatable :: tmp !! Array of values to keep + integer(I4B), dimension(:), allocatable :: tmp !! Array of values to keep nkeep = count(.not.lspill_list(:)) nspill = count(lspill_list(:)) @@ -1217,10 +1254,11 @@ subroutine base_util_spill_arr_I8B(keeps, discards, lspill_list, ldestructive) !! This is the inverse of a spill operation implicit none ! Arguments - integer(I8B), dimension(:), allocatable, intent(inout) :: keeps !! Array of values to keep - integer(I8B), dimension(:), allocatable, intent(inout) :: discards !! Array of discards - logical, dimension(:), intent(in) :: lspill_list !! Logical array of bodies to spill into the discards - logical, intent(in) :: ldestructive !! Logical flag indicating whether or not this operation should alter the keeps array or not + integer(I8B), dimension(:), allocatable, intent(inout) :: keeps !! Array of values to keep + integer(I8B), dimension(:), allocatable, intent(inout) :: discards !! Array of discards + logical, dimension(:), intent(in) :: lspill_list !! Logical array of bodies to spill into the discards + logical, intent(in) :: ldestructive!! Logical flag indicating whether or not this + !! operation should alter the keeps array or not ! Internals integer(I4B) :: nspill, nkeep, nlist integer(I8B), dimension(:), allocatable :: tmp !! Array of values to keep @@ -1263,7 +1301,8 @@ subroutine base_util_spill_arr_logical(keeps, discards, lspill_list, ldestructiv logical, dimension(:), allocatable, intent(inout) :: keeps !! Array of values to keep logical, dimension(:), allocatable, intent(inout) :: discards !! Array of discards logical, dimension(:), intent(in) :: lspill_list !! Logical array of bodies to spill into the discards - logical, intent(in) :: ldestructive !! Logical flag indicating whether or not this operation should alter the keeps array or no + logical, intent(in) :: ldestructive !! Logical flag indicating whether or not this operation + !! should alter the keeps array or no ! Internals integer(I4B) :: nspill, nkeep, nlist logical, dimension(:), allocatable :: tmp !! Array of values to keep @@ -1918,7 +1957,7 @@ pure subroutine base_util_sort_rearrange_arr_char_string(arr, ind, n) integer(I4B), dimension(:), intent(in) :: ind !! Index to rearrange against integer(I4B), intent(in) :: n !! Number of elements in arr and ind to rearrange ! Internals - character(len=STRMAX), dimension(:), allocatable :: tmp !! Temporary copy of arry used during rearrange operation + character(len=STRMAX), dimension(:), allocatable :: tmp !! Temporary copy of arry used during rearrange operation if (.not. allocated(arr) .or. n <= 0) return allocate(tmp, mold=arr) @@ -2062,7 +2101,9 @@ subroutine base_util_unique_DP(input_array, output_array, index_map) ! Arguments real(DP), dimension(:), intent(in) :: input_array !! Unsorted input array real(DP), dimension(:), allocatable, intent(out) :: output_array !! Sorted array of unique values - integer(I4B), dimension(:), allocatable, intent(out) :: index_map !! An array of the same size as input_array that such that any for any index i, output_array(index_map(i)) = input_array(i) + integer(I4B), dimension(:), allocatable, intent(out) :: index_map !! An array of the same size as input_array that such + !! that any for any index i, + !! output_array(index_map(i)) = input_array(i) ! Internals real(DP), dimension(:), allocatable :: unique_array integer(I4B) :: n @@ -2095,7 +2136,9 @@ subroutine base_util_unique_I4B(input_array, output_array, index_map) ! Arguments integer(I4B), dimension(:), intent(in) :: input_array !! Unsorted input array integer(I4B), dimension(:), allocatable, intent(out) :: output_array !! Sorted array of unique values - integer(I4B), dimension(:), allocatable, intent(out) :: index_map !! An array of the same size as input_array that such that any for any index i, output_array(index_map(i)) = input_array(i) + integer(I4B), dimension(:), allocatable, intent(out) :: index_map !! An array of the same size as input_array that such + !! that any for any index i, + !! output_array(index_map(i)) = input_array(i) ! Internals integer(I4B), dimension(:), allocatable :: unique_array integer(I4B) :: n, lo, hi diff --git a/src/globals/globals_module.f90 b/src/globals/globals_module.f90 index fd26b3404..dd58d6dae 100644 --- a/src/globals/globals_module.f90 +++ b/src/globals/globals_module.f90 @@ -37,9 +37,12 @@ module globals real(DP), parameter :: GC = 6.6743E-11_DP !! Universal gravitational constant in SI units real(DP), parameter :: einsteinC = 299792458.0_DP !! Speed of light in SI units - integer(I4B), parameter :: LOWERCASE_BEGIN = iachar('a') !! ASCII character set parameter for lower to upper conversion - start of lowercase - integer(I4B), parameter :: LOWERCASE_END = iachar('z') !! ASCII character set parameter for lower to upper conversion - end of lowercase - integer(I4B), parameter :: UPPERCASE_OFFSET = iachar('A') - iachar('a') !! ASCII character set parameter for lower to upper conversion - offset between upper and lower + integer(I4B), parameter :: LOWERCASE_BEGIN = iachar('a') !! ASCII character set parameter for lower to upper conversion - start + !! of lowercase + integer(I4B), parameter :: LOWERCASE_END = iachar('z') !! ASCII character set parameter for lower to upper conversion - end of + !! lowercase + integer(I4B), parameter :: UPPERCASE_OFFSET = iachar('A') - iachar('a') !! ASCII character set parameter for lower to upper + !! conversion - offset between upper and lower real(SP), parameter :: VERSION_NUMBER = 1.0_SP !! Swiftest version @@ -103,9 +106,11 @@ module globals integer(I4B), parameter :: NDUMPFILES = 2 character(*), parameter :: PARAM_RESTART_FILE = "param.restart.in" #ifdef COARRAY - character(STRMAX) :: SWIFTEST_LOG_FILE !! Name of file to use to log output when using "COMPACT" or "PROGRESS" display style (each co-image gets its own log file) + character(STRMAX) :: SWIFTEST_LOG_FILE !! Name of file to use to log output when using "COMPACT" or + !! "PROGRESS" display style (each co-image gets its own log file) #else - character(*), parameter :: SWIFTEST_LOG_FILE = "swiftest.log" !! Name of file to use to log output when using "COMPACT" or "PROGRESS" display style + character(*), parameter :: SWIFTEST_LOG_FILE = "swiftest.log" !! Name of file to use to log output when using "COMPACT" or + !! "PROGRESS" display style #endif integer(I4B), parameter :: SWIFTEST_LOG_OUT = 33 !! File unit for log file when using "COMPACT" display style @@ -117,7 +122,8 @@ module globals character(*), parameter :: BIN_OUTFILE = 'data.nc' integer(I4B), parameter :: BINUNIT = 20 !! File unit number for the binary output file integer(I4B), parameter :: PARTICLEUNIT = 44 !! File unit number for the binary particle info output file - integer(I4B), parameter :: LUN = 42 !! File unit number for files that are opened and closed within a single subroutine call, and therefore should not collide + integer(I4B), parameter :: LUN = 42 !! File unit number for files that are opened and closed within a single + !! subroutine call, and therefore should not collide !> Miscellaneous constants: integer(I4B), parameter :: NDIM = 3 !! Number of dimensions in our reality From 6b474370c95e44ef50e98a5cba2eaaa14ef32bac Mon Sep 17 00:00:00 2001 From: David Minton Date: Tue, 6 Jun 2023 14:38:57 -0400 Subject: [PATCH 63/95] Fixed typo in Dockerfile and set the Swiftest build type to RELEASE --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index cb81fb7f6..ca322e71d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,7 +13,7 @@ RUN apt-get update && apt-get upgrade -y && \ | gpg --dearmor | tee /usr/share/keyrings/oneapi-archive-keyring.gpg > /dev/null && \ echo "deb [signed-by=/usr/share/keyrings/oneapi-archive-keyring.gpg] https://apt.repos.intel.com/oneapi all main" | tee /etc/apt/sources.list.d/oneAPI.list && \ apt-get -y update && apt-get upgrade -y && \ - apt-get install -y intel-hpckit && \ + apt-get install -y intel-hpckit # Set Intel compiler environment variables ENV INTEL_DIR="/opt/intel/oneapi" @@ -152,7 +152,7 @@ RUN echo 'find_path(NETCDF_INCLUDE_DIR NAMES netcdf.mod HINTS ENV NETCDF_FORTRAN 'set(NETCDF_LIBRARIES ${NETCDF_FORTRAN_LIBRARY} ${NETCDF_LIBRARY} ${HDF5_HL_LIBRARY} ${HDF5_LIBRARY} ${SZ_LIBRARY} ${Z_LIBRARY} ${ZSTD_LIBRARY} ${BZ2_LIBRARY} ${CURL_LIBRARY} ${XML2_LIBRARY} )\n' \ 'mark_as_advanced(NETCDF_LIBRARY NETCDF_FORTRAN_LIBRARY NETCDF_INCLUDE_DIR)\n' > /swiftest/cmake/Modules/FindNETCDF.cmake && \ cd swiftest && \ - cmake -S . -B build -DCMAKE_INSTALL_PREFIX="${INSTALL_DIR}" -DCONTAINERIZE=ON -DUSE_COARRAY=OFF -DCMAKE_BUILD_TYPE=DEBUG -DBUILD_SHARED_LIBS=OFF &&\ + cmake -S . -B build -DCMAKE_INSTALL_PREFIX="${INSTALL_DIR}" -DCONTAINERIZE=ON -DUSE_COARRAY=OFF -DCMAKE_BUILD_TYPE=RELEASE -DBUILD_SHARED_LIBS=OFF &&\ cmake --build build --verbose && \ cmake --install build From a621339a35db81095f68abbfd0d7b41177868de4 Mon Sep 17 00:00:00 2001 From: David Minton Date: Tue, 6 Jun 2023 15:34:20 -0400 Subject: [PATCH 64/95] Fixed another Dockerfile typo --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index ca322e71d..0ac00b25d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -100,7 +100,7 @@ RUN wget -qO- https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.14/hdf5-1.14 ./HDF5-1.14.1-Linux.sh --skip-license && \ cp -R HDF_Group/HDF5/1.14.1/lib/*.a ${HDF5_ROOT}/lib/ && \ cp -R HDF_Group/HDF5/1.14.1/include/* ${HDF5_ROOT}/include/ && \ - cp zlib-1.2.13/zlib.h ${HDF5_INCLUDE_DIR}/ + cp /zlib-1.2.13/zlib.h ${HDF5_INCLUDE_DIR}/ ENV LD_LIBRARY_PATH="/lib/x86_64-linux-gnu:${LD_LIBRARY_PATH}" ENV LDFLAGS="-static-intel -lhdf5_hl -lhdf5 -lsz -lm -lz -lzstd -lbz2 -lcurl -lxml2" From 20865a6dc92a45353a6a05ca0a74be5281338999 Mon Sep 17 00:00:00 2001 From: David Minton Date: Tue, 6 Jun 2023 15:35:08 -0400 Subject: [PATCH 65/95] Removed do concurrents from operators and switched to manual cross product when in a do concurrent --- src/collision/collision_util.f90 | 62 +++++++++----- src/encounter/encounter_check.f90 | 10 +-- src/fraggle/fraggle_generate.f90 | 130 ++++++++++++++++++++---------- src/operator/operator_cross.f90 | 42 ++-------- src/operator/operator_mag.f90 | 18 +---- src/operator/operator_unit.f90 | 18 +---- 6 files changed, 147 insertions(+), 133 deletions(-) diff --git a/src/collision/collision_util.f90 b/src/collision/collision_util.f90 index 179fb289c..75c836b4c 100644 --- a/src/collision/collision_util.f90 +++ b/src/collision/collision_util.f90 @@ -146,13 +146,15 @@ end subroutine collision_util_get_idvalues_snapshot module subroutine collision_util_get_energy_and_momentum(self, nbody_system, param, phase) !! Author: David A. Minton !! - !! Calculates total system energy in either the pre-collision outcome state (phase = "before") or the post-collision outcome state (lbefore = .false.) + !! Calculates total system energy in either the pre-collision outcome state (phase = "before") or the post-collision outcome + !! state (lbefore = .false.) implicit none ! Arguments class(collision_basic), intent(inout) :: self !! Encounter collision system object class(base_nbody_system), intent(inout) :: nbody_system !! Swiftest nbody system object class(base_parameters), intent(inout) :: param !! Current Swiftest run configuration parameters - character(len=*), intent(in) :: phase !! One of "before" or "after", indicating which phase of the calculation this needs to be done + character(len=*), intent(in) :: phase !! One of "before" or "after", indicating which phase of the + !! calculation this needs to be done ! Internals integer(I4B) :: i, phase_val, nfrag @@ -179,9 +181,15 @@ module subroutine collision_util_get_energy_and_momentum(self, nbody_system, par do concurrent(i = 1:2) #endif impactors%ke_orbit(i) = 0.5_DP * impactors%mass(i) * dot_product(impactors%vc(:,i), impactors%vc(:,i)) - impactors%ke_spin(i) = 0.5_DP * impactors%mass(i) * impactors%radius(i)**2 * impactors%Ip(3,i) * dot_product(impactors%rot(:,i), impactors%rot(:,i)) + impactors%ke_spin(i) = 0.5_DP * impactors%mass(i) * impactors%radius(i)**2 * impactors%Ip(3,i) & + * dot_product(impactors%rot(:,i), impactors%rot(:,i)) impactors%be(i) = -3 * impactors%Gmass(i) * impactors%mass(i) / (5 * impactors%radius(i)) - impactors%L_orbit(:,i) = impactors%mass(i) * impactors%rc(:,i) .cross. impactors%vc(:,i) + impactors%L_orbit(1,i) = impactors%mass(i) * (impactors%rc(2,i) * impactors%vc(3,i) & + - impactors%rc(3,i) * impactors%vc(2,i)) + impactors%L_orbit(2,i) = impactors%mass(i) * (impactors%rc(3,i) * impactors%vc(1,i) & + - impactors%rc(1,i) * impactors%vc(3,i)) + impactors%L_orbit(3,i) = impactors%mass(i) * (impactors%rc(1,i) * impactors%vc(2,i) & + - impactors%rc(2,i) * impactors%vc(1,i)) impactors%L_spin(:,i) = impactors%mass(i) * impactors%radius(i)**2 * impactors%Ip(3,i) * impactors%rot(:,i) end do self%L_orbit(:,phase_val) = sum(impactors%L_orbit(:,1:2),dim=2) @@ -190,7 +198,8 @@ module subroutine collision_util_get_energy_and_momentum(self, nbody_system, par self%ke_orbit(phase_val) = sum(impactors%ke_orbit(1:2)) self%ke_spin(phase_val) = sum(impactors%ke_spin(1:2)) self%be(phase_val) = sum(impactors%be(1:2)) - call swiftest_util_get_potential_energy(2, [(.true., i = 1, 2)], 0.0_DP, impactors%Gmass, impactors%mass, impactors%rb, self%pe(phase_val)) + call swiftest_util_get_potential_energy(2, [(.true., i = 1, 2)], 0.0_DP, impactors%Gmass, impactors%mass, & + impactors%rb, self%pe(phase_val)) self%te(phase_val) = self%ke_orbit(phase_val) + self%ke_spin(phase_val) + self%be(phase_val) + self%pe(phase_val) else if (phase_val == 2) then #ifdef DOCONLOC @@ -199,11 +208,18 @@ module subroutine collision_util_get_energy_and_momentum(self, nbody_system, par do concurrent(i = 1:nfrag) #endif fragments%ke_orbit(i) = 0.5_DP * fragments%mass(i) * dot_product(fragments%vc(:,i), fragments%vc(:,i)) - fragments%ke_spin(i) = 0.5_DP * fragments%mass(i) * fragments%radius(i)**2 * fragments%Ip(3,i) * dot_product(fragments%rot(:,i), fragments%rot(:,i)) - fragments%L_orbit(:,i) = fragments%mass(i) * fragments%rc(:,i) .cross. fragments%vc(:,i) + fragments%ke_spin(i) = 0.5_DP * fragments%mass(i) * fragments%radius(i)**2 * fragments%Ip(3,i) & + * dot_product(fragments%rot(:,i), fragments%rot(:,i)) + fragments%L_orbit(1,i) = fragments%mass(i) * (fragments%rc(2,i) * fragments%vc(3,i) - & + fragments%rc(3,i) * fragments%vc(2,i)) + fragments%L_orbit(2,i) = fragments%mass(i) * (fragments%rc(3,i) * fragments%vc(1,i) - & + fragments%rc(1,i) * fragments%vc(3,i)) + fragments%L_orbit(3,i) = fragments%mass(i) * (fragments%rc(1,i) * fragments%vc(2,i) - & + fragments%rc(2,i) * fragments%vc(1,i)) fragments%L_spin(:,i) = fragments%mass(i) * fragments%radius(i)**2 * fragments%Ip(3,i) * fragments%rot(:,i) end do - call swiftest_util_get_potential_energy(nfrag, [(.true., i = 1, nfrag)], 0.0_DP, fragments%Gmass, fragments%mass, fragments%rb, fragments%pe) + call swiftest_util_get_potential_energy(nfrag, [(.true., i = 1, nfrag)], 0.0_DP, fragments%Gmass, fragments%mass, & + fragments%rb, fragments%pe) fragments%be = sum(-3*fragments%Gmass(1:nfrag)*fragments%mass(1:nfrag)/(5*fragments%radius(1:nfrag))) fragments%L_orbit_tot(:) = sum(fragments%L_orbit(:,1:nfrag),dim=2) fragments%L_spin_tot(:) = sum(fragments%L_spin(:,1:nfrag),dim=2) @@ -541,9 +557,11 @@ end subroutine collision_util_setup_fragments module subroutine collision_util_set_coordinate_collider(self) - + !! author: David A. Minton + !! !! - !! Defines the collisional coordinate nbody_system, including the unit vectors of both the nbody_system and individual fragments. + !! Defines the collisional coordinate nbody_system, including the unit vectors of both the nbody_system and individual + !! fragments. implicit none ! Arguments class(collision_basic), intent(inout) :: self !! Collisional nbody_system @@ -564,7 +582,8 @@ end subroutine collision_util_set_coordinate_collider module subroutine collision_util_set_coordinate_fragments(self) !! author: David A. Minton !! - !! Defines the collisional coordinate nbody_system, including the unit vectors of both the nbody_system and individual fragments. + !! Defines the collisional coordinate nbody_system, including the unit vectors of both the nbody_system and individual + !! fragments. implicit none ! Arguments class(collision_fragments), intent(inout) :: self !! Collisional nbody_system @@ -590,7 +609,8 @@ end subroutine collision_util_set_coordinate_fragments module subroutine collision_util_set_coordinate_impactors(self) !! author: David A. Minton !! - !! Defines the collisional coordinate nbody_system, including the unit vectors of both the nbody_system and individual fragments. + !! Defines the collisional coordinate nbody_system, including the unit vectors of both the nbody_system and individual + !! fragments. implicit none ! Arguments class(collision_impactors), intent(inout) :: self !! Collisional nbody_system @@ -602,8 +622,8 @@ module subroutine collision_util_set_coordinate_impactors(self) delta_v(:) = impactors%vb(:, 2) - impactors%vb(:, 1) delta_r(:) = impactors%rb(:, 2) - impactors%rb(:, 1) - ! We will initialize fragments on a plane defined by the pre-impact nbody_system, with the z-axis aligned with the angular momentum vector - ! and the y-axis aligned with the pre-impact distance vector. + ! We will initialize fragments on a plane defined by the pre-impact nbody_system, with the z-axis aligned with the angular + ! momentum vector and the y-axis aligned with the pre-impact distance vector. ! y-axis is the separation distance impactors%y_unit(:) = .unit.delta_r(:) @@ -632,14 +652,16 @@ module subroutine collision_util_set_coordinate_impactors(self) impactors%vc(:,1) = impactors%vb(:,1) - impactors%vbcom(:) impactors%vc(:,2) = impactors%vb(:,2) - impactors%vbcom(:) - ! Find the point of impact between the two bodies, defined as the location (in the collisional coordinate system) at the surface of body 1 along the line connecting the two bodies. + ! Find the point of impact between the two bodies, defined as the location (in the collisional coordinate system) at the + ! surface of body 1 along the line connecting the two bodies. impactors%rcimp(:) = impactors%rb(:,1) + impactors%radius(1) * impactors%y_unit(:) - impactors%rbcom(:) ! Set the velocity direction as the "bounce" direction" for disruptions, and body 2's direction for hit and runs if (impactors%regime == COLLRESOLVE_REGIME_HIT_AND_RUN) then impactors%bounce_unit(:) = .unit. impactors%vc(:,2) else - impactors%bounce_unit(:) = .unit. (impactors%vc(:,2) - 2 * dot_product(impactors%vc(:,2),impactors%y_unit(:)) * impactors%y_unit(:)) + impactors%bounce_unit(:) = .unit. (impactors%vc(:,2) - 2 * dot_product(impactors%vc(:,2),impactors%y_unit(:)) & + * impactors%y_unit(:)) end if end associate @@ -742,7 +764,8 @@ module subroutine collision_util_snapshot(self, param, nbody_system, t, arg) class(base_parameters), intent(inout) :: param !! Current run configuration parameters class(base_nbody_system), intent(inout) :: nbody_system !! Swiftest nbody system object to store real(DP), intent(in), optional :: t !! Time of snapshot if different from nbody_system time - character(*), intent(in), optional :: arg !! "before": takes a snapshot just before the collision. "after" takes the snapshot just after the collision. + character(*), intent(in), optional :: arg !! "before": takes a snapshot just before the collision. "after" + !! takes the snapshot just after the collision. ! Arguments class(collision_snapshot), allocatable, save :: snapshot character(len=:), allocatable :: stage @@ -816,8 +839,9 @@ module subroutine collision_util_snapshot(self, param, nbody_system, t, arg) write(message,*) trim(adjustl(plnew%info(i)%name)), " (", trim(adjustl(plnew%info(i)%particle_type)),")" call swiftest_io_log_one_message(COLLISION_LOG_OUT, message) end do - call swiftest_io_log_one_message(COLLISION_LOG_OUT, "***********************************************************" // & - "***********************************************************") + call swiftest_io_log_one_message(COLLISION_LOG_OUT, & + "***********************************************************" // & + "***********************************************************") allocate(after_snap%pl, source=plnew) end select deallocate(after_orig%pl) diff --git a/src/encounter/encounter_check.f90 b/src/encounter/encounter_check.f90 index 2d934e7d8..deef9bdda 100644 --- a/src/encounter/encounter_check.f90 +++ b/src/encounter/encounter_check.f90 @@ -179,7 +179,7 @@ subroutine encounter_check_all_sort_and_sweep_plpl(npl, r, v, renc, dt, nenc, in #else do concurrent (i = 1:npl) #endif - rmag = .mag.r(:,i) + rmag = norm2(r(:,i)) rmax(i) = rmag + RSWEEP_FACTOR * renc(i) rmin(i) = rmag - RSWEEP_FACTOR * renc(i) end do @@ -236,7 +236,7 @@ subroutine encounter_check_all_sort_and_sweep_plplm(nplm, nplt, rplm, vplm, rplt #else do concurrent (i = 1:nplm) #endif - rmag = .mag.rplm(:,i) + rmag = norm2(rplm(:,i)) rmax(i) = rmag + RSWEEP_FACTOR * rencm(i) rmin(i) = rmag - RSWEEP_FACTOR * rencm(i) end do @@ -245,7 +245,7 @@ subroutine encounter_check_all_sort_and_sweep_plplm(nplm, nplt, rplm, vplm, rplt #else do concurrent (i = 1:nplt) #endif - rmag = .mag.rplt(:,i) + rmag = norm2(rplt(:,i)) rmax(nplm+i) = rmag + RSWEEP_FACTOR * renct(i) rmin(nplm+i) = rmag - RSWEEP_FACTOR * renct(i) end do @@ -304,7 +304,7 @@ subroutine encounter_check_all_sort_and_sweep_pltp(npl, ntp, rpl, vpl, rtp, vtp, #else do concurrent (i = 1:npl) #endif - rmag = .mag.rpl(:,i) + rmag = norm2(rpl(:,i)) rmax(i) = rmag + RSWEEP_FACTOR * rencpl(i) rmin(i) = rmag - RSWEEP_FACTOR * rencpl(i) end do @@ -313,7 +313,7 @@ subroutine encounter_check_all_sort_and_sweep_pltp(npl, ntp, rpl, vpl, rtp, vtp, #else do concurrent (i = 1:ntp) #endif - rmag = .mag.rtp(:,i) + rmag = norm2(rtp(:,i)) rmax(npl+i) = rmag + RSWEEP_FACTOR * renctp(i) rmin(npl+i) = rmag - RSWEEP_FACTOR * renctp(i) end do diff --git a/src/fraggle/fraggle_generate.f90 b/src/fraggle/fraggle_generate.f90 index 5ec993fba..cd1df7033 100644 --- a/src/fraggle/fraggle_generate.f90 +++ b/src/fraggle/fraggle_generate.f90 @@ -59,7 +59,8 @@ module subroutine fraggle_generate(self, nbody_system, param, t) call self%set_mass_dist(param) call self%disrupt(nbody_system, param, t, lfailure) if (lfailure) then - call swiftest_io_log_one_message(COLLISION_LOG_OUT, "Fraggle failed to find a solution to match energy contraint. Treating this as a merge.") + call swiftest_io_log_one_message(COLLISION_LOG_OUT, & + "Fraggle failed to find a solution to match energy contraint. Treating this as a merge.") call self%merge(nbody_system, param, t) ! Use the default collision model, which is merge return end if @@ -131,8 +132,9 @@ module subroutine fraggle_generate_disrupt(self, nbody_system, param, t, lfailur real(DP), parameter :: fail_scale_initial = 1.0003_DP integer(I4B) :: nfrag_start - ! The minimization and linear solvers can sometimes lead to floating point exceptions. Rather than halting the code entirely if this occurs, we - ! can simply fail the attempt and try again. So we need to turn off any floating point exception halting modes temporarily + ! The minimization and linear solvers can sometimes lead to floating point exceptions. Rather than halting the code entirely + ! if this occurs, we can simply fail the attempt and try again. So we need to turn off any floating point exception halting + ! modes temporarily call ieee_get_halting_mode(IEEE_ALL,fpe_halting_modes) ! Save the current halting modes so we can turn them off temporarily fpe_quiet_modes(:) = .false. call ieee_set_halting_mode(IEEE_ALL,fpe_quiet_modes) @@ -168,7 +170,8 @@ module subroutine fraggle_generate_disrupt(self, nbody_system, param, t, lfailur if (.not.lfailure) then if (self%fragments%nbody /= nfrag_start) then write(message,*) self%fragments%nbody - call swiftest_io_log_one_message(COLLISION_LOG_OUT, "Fraggle found a solution with " // trim(adjustl(message)) // " fragments" ) + call swiftest_io_log_one_message(COLLISION_LOG_OUT, "Fraggle found a solution with " // trim(adjustl(message)) & + // " fragments" ) end if call self%get_energy_and_momentum(nbody_system, param, phase="after") @@ -176,7 +179,8 @@ module subroutine fraggle_generate_disrupt(self, nbody_system, param, t, lfailur dE = self%te(2) - self%te(1) call swiftest_io_log_one_message(COLLISION_LOG_OUT, "All quantities in collision system natural units") - call swiftest_io_log_one_message(COLLISION_LOG_OUT, "* Conversion factors (collision system units / nbody system units):") + call swiftest_io_log_one_message(COLLISION_LOG_OUT, & + "* Conversion factors (collision system units / nbody system units):") write(message,*) "* Mass: ", self%mscale call swiftest_io_log_one_message(COLLISION_LOG_OUT, message) write(message,*) "* Distance: ", self%dscale @@ -200,7 +204,8 @@ module subroutine fraggle_generate_disrupt(self, nbody_system, param, t, lfailur end if call self%set_original_scale() - self%max_rot = MAX_ROT_SI * param%TU2S ! Re-compute the spin limit from scratch so it doesn't drift due to floating point errors every time we convert + self%max_rot = MAX_ROT_SI * param%TU2S ! Re-compute the spin limit from scratch so it doesn't drift due to floating point + ! errors every time we convert ! Restore the big array if (lk_plpl) call pl%flatten(param) @@ -248,7 +253,8 @@ module subroutine fraggle_generate_hitandrun(self, nbody_system, param, t) end if ! The Fraggle disruption model (and its extended types allow for non-pure hit and run. - if (impactors%mass_dist(2) > 0.9_DP * impactors%mass(jproj)) then ! Pure hit and run, so we'll just keep the two bodies untouched + if (impactors%mass_dist(2) > 0.9_DP * impactors%mass(jproj)) then ! Pure hit and run, so we'll just keep the two bodies + ! untouched call swiftest_io_log_one_message(COLLISION_LOG_OUT, "Pure hit and run. No new fragments generated.") call self%collision_basic%hitandrun(nbody_system, param, t) return @@ -327,7 +333,8 @@ module subroutine fraggle_generate_merge(self, nbody_system, param, t) if (rotmag < self%max_rot) then call self%collision_basic%merge(nbody_system, param, t) else - call swiftest_io_log_one_message(COLLISION_LOG_OUT, "Merger would break the spin barrier. Converting to pure hit and run" ) + call swiftest_io_log_one_message(COLLISION_LOG_OUT, & + "Merger would break the spin barrier. Converting to pure hit and run" ) impactors%mass_dist(1:2) = impactors%mass(1:2) call self%hitandrun(nbody_system, param, t) end if @@ -342,9 +349,9 @@ module subroutine fraggle_generate_pos_vec(collider, nbody_system, param, lfailu !! Author: Jennifer L.L. Pouplin, Carlisle A. Wishard, and David A. Minton !! !! Initializes the position vectors of the fragments around the center of mass based on the collision style. - !! For hit and run with disruption, the fragments are generated in a random cloud around the smallest of the two colliders (body 2) - !! For disruptive collisions, the fragments are generated in a random cloud around the impact point. Bodies are checked for overlap and - !! regenerated if they overlap. + !! For hit and run with disruption, the fragments are generated in a random cloud around the smallest of the two colliders + !! (body 2). For disruptive collisions, the fragments are generated in a random cloud around the impact point. Bodies are + !! checked for overlap and regenerated if they overlap. implicit none ! Arguments class(collision_fraggle), intent(inout) :: collider !! Fraggle collision system object @@ -372,7 +379,8 @@ module subroutine fraggle_generate_pos_vec(collider, nbody_system, param, lfailu lhitandrun = (impactors%regime == COLLRESOLVE_REGIME_HIT_AND_RUN) ! We will treat the first two fragments of the list as special cases. - ! Place the first two bodies at the centers of the two fragment clouds, but be sure they are sufficiently far apart to avoid overlap + ! Place the first two bodies at the centers of the two fragment clouds, but be sure they are sufficiently far apart to + ! avoid overlap if (lhitandrun) then rdistance = impactors%radius(2) istart = 2 @@ -385,11 +393,14 @@ module subroutine fraggle_generate_pos_vec(collider, nbody_system, param, lfailu end if mass_rscale(1:istart-1) = 1.0_DP - ! Give the fragment positions a random value that is scaled with fragment mass so that the more massive bodies tend to be closer to the impact point - ! Later, velocities will be scaled such that the farther away a fragment is placed from the impact point, the higher will its velocity be. + ! Give the fragment positions a random value that is scaled with fragment mass so that the more massive bodies tend to be + ! closer to the impact point. Later, velocities will be scaled such that the farther away a fragment is placed from the + ! impact point, the higher will its velocity be. call random_number(mass_rscale(istart:nfrag)) mass_rscale(istart:nfrag) = (mass_rscale(istart:nfrag) + 1.0_DP) / 2 - mass_rscale(istart:nfrag) = mass_rscale(istart:nfrag) * (sum(fragments%mass(istart:nfrag)) / fragments%mass(istart:nfrag))**(0.125_DP) ! The power is arbitrary. It just gives the velocity a small mass dependence + ! The power of 0.125 in the scaling below is arbitrary. It just gives the velocity a small mass dependence + mass_rscale(istart:nfrag) = mass_rscale(istart:nfrag) * (sum(fragments%mass(istart:nfrag)) & + / fragments%mass(istart:nfrag))**(0.125_DP) mass_rscale(istart:nfrag) = mass_rscale(istart:nfrag) / minval(mass_rscale(istart:nfrag)) loverlap(:) = .true. @@ -402,8 +413,10 @@ module subroutine fraggle_generate_pos_vec(collider, nbody_system, param, lfailu fragment_cloud_center(:,2) = impactors%rc(:,2) fragments%rc(:,1) = fragment_cloud_center(:,1) else ! Keep the first and second bodies at approximately their original location, but so as not to be overlapping - fragment_cloud_center(:,1) = impactors%rcimp(:) - rbuffer * max(fragments%radius(1),impactors%radius(1)) * impactors%y_unit(:) - fragment_cloud_center(:,2) = impactors%rcimp(:) + rbuffer * max(fragments%radius(2),impactors%radius(2)) * impactors%y_unit(:) + fragment_cloud_center(:,1) = impactors%rcimp(:) - rbuffer * max(fragments%radius(1),& + impactors%radius(1)) * impactors%y_unit(:) + fragment_cloud_center(:,2) = impactors%rcimp(:) + rbuffer * max(fragments%radius(2), & + impactors%radius(2)) * impactors%y_unit(:) fragment_cloud_radius(:) = rdistance / pack_density fragments%rc(:,1:2) = fragment_cloud_center(:,1:2) end if @@ -420,7 +433,8 @@ module subroutine fraggle_generate_pos_vec(collider, nbody_system, param, lfailu ! Randomly place the n>2 fragments inside their cloud until none are overlapping #ifdef DOCONLOC - do concurrent(i = istart:nfrag, loverlap(i)) shared(fragments, impactors, fragment_cloud_radius, fragment_cloud_center, loverlap, mass_rscale, u, phi, theta, lhitandrun) local(j, direction) + do concurrent(i = istart:nfrag, loverlap(i)) shared(fragments, impactors, fragment_cloud_radius, fragment_cloud_center,& + loverlap, mass_rscale, u, phi, theta, lhitandrun) local(j, direction) #else do concurrent(i = istart:nfrag, loverlap(i)) #endif @@ -442,13 +456,15 @@ module subroutine fraggle_generate_pos_vec(collider, nbody_system, param, lfailu ! Stretch out the hit and run cloud along the flight trajectory if (lhitandrun) then - fragments%rc(:,i) = fragments%rc(:,i) * (1.0_DP + 2 * fragment_cloud_radius(j) * mass_rscale(i) * impactors%bounce_unit(:)) + fragments%rc(:,i) = fragments%rc(:,i) * (1.0_DP + 2 * fragment_cloud_radius(j) * mass_rscale(i) & + * impactors%bounce_unit(:)) end if fragments%rc(:,i) = fragments%rc(:,i) + fragment_cloud_center(:,j) if (lhitandrun) then - fragments%rc(:,i) = fragments%rc(:,i) + 2 * fragment_cloud_radius(j) * mass_rscale(i) * impactors%bounce_unit(:) ! Shift the stretched cloud downrange + ! Shift the stretched cloud downrange + fragments%rc(:,i) = fragments%rc(:,i) + 2 * fragment_cloud_radius(j) * mass_rscale(i) * impactors%bounce_unit(:) else ! Make sure that the fragments are positioned away from the impact point direction = dot_product(fragments%rc(:,i) - impactors%rcimp(:), fragment_cloud_center(:,j) - impactors%rcimp(:)) @@ -460,7 +476,8 @@ module subroutine fraggle_generate_pos_vec(collider, nbody_system, param, lfailu end do ! Because body 1 and 2 are initialized near the original impactor positions, then if these bodies are still overlapping - ! when the rest are not, we will randomly walk their position in space so as not to move them too far from their starting position + ! when the rest are not, we will randomly walk their position in space so as not to move them too far from their + ! starting position if (all(.not.loverlap(istart:nfrag)) .and. any(loverlap(1:istart-1))) then #ifdef DOCONLOC do concurrent(i = 1:istart-1,loverlap(i)) shared(fragments,loverlap, u, theta, i) local(rwalk, dis) @@ -525,8 +542,10 @@ module subroutine fraggle_generate_rot_vec(collider, nbody_system, param) class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters ! Internals integer(I4B) :: i, nfrag - real(DP), parameter :: FRAG_ROT_FAC = 0.1_DP ! Fraction of projectile rotation magnitude to add as random noise to fragment rotation - real(DP), parameter :: hitandrun_momentum_transfer = 0.01_DP ! Fraction of projectile momentum transfered to target in a hit and run + real(DP), parameter :: FRAG_ROT_FAC = 0.1_DP ! Fraction of projectile rotation magnitude to add as random noise to fragment + ! rotation + real(DP), parameter :: hitandrun_momentum_transfer = 0.01_DP ! Fraction of projectile momentum transfered to target in a hit + ! and run real(DP) :: mass_fac real(DP), dimension(NDIM) :: drot, dL integer(I4B), parameter :: MAXLOOP = 10 @@ -536,14 +555,15 @@ module subroutine fraggle_generate_rot_vec(collider, nbody_system, param) nfrag = collider%fragments%nbody lhitandrun = (impactors%regime == COLLRESOLVE_REGIME_HIT_AND_RUN) - ! Initialize fragment rotations and velocities to be pre-impact rotation for body 1, and randomized for bodies >1 and scaled to the original rotation. - ! This will get updated later when conserving angular momentum + ! Initialize fragment rotations and velocities to be pre-impact rotation for body 1, and randomized for bodies >1 and + ! scaled to the original rotation. This will get updated later when conserving angular momentum mass_fac = fragments%mass(1) / impactors%mass(1) fragments%rot(:,1) = mass_fac**(5.0_DP/3.0_DP) * impactors%rot(:,1) ! If mass was added, also add spin angular momentum if (mass_fac > 1.0_DP) then - dL(:) = (fragments%mass(1) - impactors%mass(1)) * (impactors%rc(:,2) - impactors%rc(:,1)) .cross. (impactors%vc(:,2) - impactors%vc(:,1)) + dL(:) = (fragments%mass(1) - impactors%mass(1)) * (impactors%rc(:,2) - impactors%rc(:,1)) & + .cross. (impactors%vc(:,2) - impactors%vc(:,1)) drot(:) = dL(:) / (fragments%mass(1) * fragments%radius(1)**2 * fragments%Ip(3,1)) ! Check to make sure we haven't broken the spin barrier. Reduce the rotation change if so do i = 1, MAXLOOP @@ -559,7 +579,8 @@ module subroutine fraggle_generate_rot_vec(collider, nbody_system, param) end if if (lhitandrun) then - dL(:) = hitandrun_momentum_transfer * impactors%mass(2) * (impactors%rc(:,2) - impactors%rc(:,1)) .cross. (impactors%vc(:,2) - impactors%vc(:,1)) + dL(:) = hitandrun_momentum_transfer * impactors%mass(2) * (impactors%rc(:,2) - impactors%rc(:,1)) & + .cross. (impactors%vc(:,2) - impactors%vc(:,1)) drot(:) = dL(:) / (fragments%mass(1) * fragments%radius(1)**2 * fragments%Ip(3,1)) do i = 1, MAXLOOP if (.mag.(fragments%rot(:,1) + drot(:)) < collider%max_rot) exit @@ -580,7 +601,8 @@ module subroutine fraggle_generate_rot_vec(collider, nbody_system, param) do concurrent (i = 2:nfrag) #endif mass_fac = fragments%mass(i) / impactors%mass(2) - fragments%rot(:,i) = mass_fac**(5.0_DP/3.0_DP) * impactors%rot(:,2) + 2 * (fragments%rot(:,i) - 1.0_DP) * FRAG_ROT_FAC * .mag.impactors%rot(:,2) + fragments%rot(:,i) = mass_fac**(5.0_DP/3.0_DP) * impactors%rot(:,2) + 2 * (fragments%rot(:,i) - 1.0_DP) * & + FRAG_ROT_FAC * norm2(impactors%rot(:,2)) end do fragments%rotmag(:) = .mag.fragments%rot(:,:) @@ -603,17 +625,22 @@ module subroutine fraggle_generate_vel_vec(collider, nbody_system, param, lfailu class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters logical, intent(out) :: lfailure !! Did the velocity computation fail? ! Internals - real(DP), parameter :: ENERGY_SUCCESS_METRIC = 0.1_DP !! Relative energy error to accept as a success (success also must be energy-losing in addition to being within the metric amount) + real(DP), parameter :: ENERGY_SUCCESS_METRIC = 0.1_DP !! Relative energy error to accept as a success (success also must be + !! energy-losing in addition to being within the metric amount) real(DP), parameter :: ENERGY_CONVERGENCE_TOL = 1e-3_DP !! Relative change in error before giving up on energy convergence - real(DP) :: MOMENTUM_SUCCESS_METRIC = 10*epsilon(1.0_DP) !! Relative angular momentum error to accept as a success (should be *much* stricter than energy) + real(DP) :: MOMENTUM_SUCCESS_METRIC = 10*epsilon(1.0_DP) !! Relative angular momentum error to accept as a success + !! (should be *much* stricter than energy) integer(I4B) :: i, j, loop, try, istart, nfrag, nsteps, nsteps_best, posloop logical :: lhitandrun, lsupercat - real(DP), dimension(NDIM) :: vimp_unit, rimp, vrot, vdisp, L_residual, L_residual_unit, L_residual_best, dL, drot, rot_new, dL_metric - real(DP) :: vimp, vmag, vesc, dE, E_residual, E_residual_best, E_residual_last, ke_avail, ke_remove, dE_best, fscale, dE_metric, mfrag, rn, dL1_mag, dE_conv + real(DP), dimension(NDIM) :: vimp_unit, rimp, vrot, vdisp, L_residual, L_residual_unit, L_residual_best, dL, drot, rot_new + real(DP), dimension(NDIM) :: dL_metric + real(DP) :: vimp, vmag, vesc, dE, E_residual, E_residual_best, E_residual_last, ke_avail, ke_remove, dE_best, fscale + real(DP) :: dE_metric, mfrag, rn, dL1_mag, dE_conv, vumag integer(I4B), dimension(:), allocatable :: vsign real(DP), dimension(:), allocatable :: vscale real(DP), dimension(:), allocatable :: dLi_mag - ! For the initial "guess" of fragment velocities, this is the minimum and maximum velocity relative to escape velocity that the fragments will have + ! For the initial "guess" of fragment velocities, this is the minimum and maximum velocity relative to escape velocity that + ! the fragments will have real(DP), parameter :: hitandrun_vscale = 0.25_DP real(DP) :: vmin_guess real(DP) :: vmax_guess @@ -688,25 +715,34 @@ module subroutine fraggle_generate_vel_vec(collider, nbody_system, param, lfailu ! Set the velocities of all fragments using all of the scale factors determined above if (istart > 1) fragments%vc(:,1) = impactors%vc(:,1) * impactors%mass(1) / fragments%mass(1) #ifdef DOCONLOC - do concurrent(i = istart:fragments%nbody) shared(fragments,impactors,lhitandrun, vscale, vesc, vsign) local(j,vrot,vmag,vdisp,rimp,vimp_unit) + do concurrent(i = istart:fragments%nbody) shared(fragments,impactors,lhitandrun, vscale, vesc, vsign) & + local(j,vrot,vmag,vdisp,rimp,vimp_unit, vumag) #else do concurrent(i = istart:fragments%nbody) #endif j = fragments%origin_body(i) - vrot(:) = impactors%rot(:,j) .cross. (fragments%rc(:,i) - impactors%rc(:,j)) + vrot(1) = impactors%rot(2,j) * (fragments%rc(3,i) - impactors%rc(3,j)) & + - impactors%rot(3,j) * (fragments%rc(2,i) - impactors%rc(2,j)) + vrot(2) = impactors%rot(3,j) * (fragments%rc(1,i) - impactors%rc(1,j)) & + - impactors%rot(1,j) * (fragments%rc(3,i) - impactors%rc(3,j)) + vrot(3) = impactors%rot(1,j) * (fragments%rc(2,i) - impactors%rc(2,j)) & + - impactors%rot(2,j) * (fragments%rc(1,i) - impactors%rc(1,j)) if (lhitandrun) then - vdisp(:) = .unit.(fragments%rc(:,i) - impactors%rc(:,2)) * vesc + vumag = norm2(fragments%rc(:,i) - impactors%rc(:,2)) + vdisp(:) = (fragments%rc(:,i) - impactors%rc(:,2)) / vumag * vesc fragments%vc(:,i) = vsign(i) * impactors%bounce_unit(:) * vscale(i) + vrot(:) + vdisp(:) else vmag = vscale(i) rimp(:) = fragments%rc(:,i) - impactors%rcimp(:) - vimp_unit(:) = .unit. (rimp(:) + vsign(i) * impactors%bounce_unit(:)) + vumag = norm2(rimp(:) + vsign(i) * impactors%bounce_unit(:)) + vimp_unit(:) = (rimp(:) + vsign(i) * impactors%bounce_unit(:)) / vumag fragments%vc(:,i) = vmag * vimp_unit(:) + vrot(:) end if end do fragments%vmag(:) = .mag. fragments%vc(:,:) - ! Every time the collision-frame velocities are altered, we need to be sure to shift everything back to the center-of-mass frame + ! Every time the collision-frame velocities are altered, we need to be sure to shift everything back to the + ! center-of-mass frame call collision_util_shift_vector_to_origin(fragments%mass, fragments%vc) call fragments%set_coordinate_system() @@ -715,7 +751,8 @@ module subroutine fraggle_generate_vel_vec(collider, nbody_system, param, lfailu nsteps = nsteps + 1 mfrag = sum(fragments%mass(istart:fragments%nbody)) - ! Try to put residual angular momentum into the spin, but if this would go past the spin barrier, then put it into velocity shear instead + ! Try to put residual angular momentum into the spin, but if this would go past the spin barrier, then put it into + ! velocity shear instead call collider_local%get_energy_and_momentum(nbody_system, param, phase="after") L_residual(:) = (collider_local%L_total(:,2) - collider_local%L_total(:,1)) L_residual_unit(:) = .unit. L_residual(:) @@ -740,7 +777,8 @@ module subroutine fraggle_generate_vel_vec(collider, nbody_system, param, lfailu if (.mag.rot_new(:) < collider_local%max_rot) then fragments%rot(:,i) = rot_new(:) fragments%rotmag(i) = .mag.fragments%rot(:,i) - else ! We would break the spin barrier here. Add a random component of rotation that is less than what would break the limit. The rest will go in velocity shear + else ! We would break the spin barrier here. Add a random component of rotation that is less than what would + ! break the limit. The rest will go in velocity shear call random_number(drot) call random_number(rn) drot(:) = (rn * collider_local%max_rot - fragments%rotmag(i)) * 2 * (drot(:) - 0.5_DP) @@ -785,7 +823,8 @@ module subroutine fraggle_generate_vel_vec(collider, nbody_system, param, lfailu ! Check if we've converged on our constraints if (all(dL_metric(:) <= 1.0_DP)) then - if ((abs(E_residual) < abs(E_residual_best)) .or. ((dE < 0.0_DP) .and. (dE_best >= 0.0_DP))) then ! This is our best case so far. Save it for posterity + if ((abs(E_residual) < abs(E_residual_best)) .or. ((dE < 0.0_DP) .and. (dE_best >= 0.0_DP))) then + ! This is our best case so far. Save it for posterity E_residual_best = E_residual L_residual_best(:) = L_residual(:) dE_best = dE @@ -799,7 +838,8 @@ module subroutine fraggle_generate_vel_vec(collider, nbody_system, param, lfailu if (dE_conv < ENERGY_CONVERGENCE_TOL) exit inner end if - ! Remove a constant amount of velocity from the bodies so we don't shift the center of mass and screw up the momentum + ! Remove a constant amount of velocity from the bodies so we don't shift the center of mass and screw up the + ! momentum ke_avail = 0.0_DP do i = fragments%nbody, 1, -1 ke_avail = ke_avail + 0.5_DP * fragments%mass(i) * max(fragments%vmag(i) - vesc / try,0.0_DP)**2 @@ -830,9 +870,11 @@ module subroutine fraggle_generate_vel_vec(collider, nbody_system, param, lfailu write(message, *) nsteps if (lfailure) then - call swiftest_io_log_one_message(COLLISION_LOG_OUT, "Fraggle velocity calculation failed to converge after " // trim(adjustl(message)) // " steps. The best solution found had:") + call swiftest_io_log_one_message(COLLISION_LOG_OUT, "Fraggle velocity calculation failed to converge after " & + // trim(adjustl(message)) // " steps. The best solution found had:") else - call swiftest_io_log_one_message(COLLISION_LOG_OUT,"Fraggle velocity calculation converged after " // trim(adjustl(message)) // " steps.") + call swiftest_io_log_one_message(COLLISION_LOG_OUT,"Fraggle velocity calculation converged after " & + // trim(adjustl(message)) // " steps.") call collider%get_energy_and_momentum(nbody_system, param, phase="after") L_residual(:) = (collider%L_total(:,2) - collider%L_total(:,1)) diff --git a/src/operator/operator_cross.f90 b/src/operator/operator_cross.f90 index ef80e1fb8..72c24a176 100644 --- a/src/operator/operator_cross.f90 +++ b/src/operator/operator_cross.f90 @@ -104,11 +104,7 @@ pure module function operator_cross_el_sp(A, B) result(C) n = size(A, 2) if (allocated(C)) deallocate(C) allocate(C, mold = A) -#ifdef DOCONLOC - do concurrent (i = 1:n) shared(A,B,C) -#else - do concurrent (i = 1:n) -#endif + do i = 1,n C(:,i) = operator_cross_sp(A(:,i), B(:,i)) end do return @@ -122,11 +118,7 @@ pure module function operator_cross_el_dp(A, B) result(C) n = size(A, 2) if (allocated(C)) deallocate(C) allocate(C, mold = A) -#ifdef DOCONLOC - do concurrent (i = 1:n) shared(A,B,C) -#else - do concurrent (i = 1:n) -#endif + do i = 1,n C(:,i) = operator_cross_dp(A(:,i), B(:,i)) end do return @@ -140,11 +132,7 @@ pure module function operator_cross_el_qp(A, B) result(C) n = size(A, 2) if (allocated(C)) deallocate(C) allocate(C, mold = A) -#ifdef DOCONLOC - do concurrent (i = 1:n) shared(A,B,C) -#else - do concurrent (i = 1:n) -#endif + do i = 1,n C(:,i) = operator_cross_qp(A(:,i), B(:,i)) end do return @@ -158,11 +146,7 @@ pure module function operator_cross_el_i1b(A, B) result(C) n = size(A, 2) if (allocated(C)) deallocate(C) allocate(C, mold = A) -#ifdef DOCONLOC - do concurrent (i = 1:n) shared(A,B,C) -#else - do concurrent (i = 1:n) -#endif + do i = 1,n C(:,i) = operator_cross_i1b(A(:,i), B(:,i)) end do return @@ -176,11 +160,7 @@ pure module function operator_cross_el_i2b(A, B) result(C) n = size(A, 2) if (allocated(C)) deallocate(C) allocate(C, mold = A) -#ifdef DOCONLOC - do concurrent (i = 1:n) shared(A,B,C) -#else - do concurrent (i = 1:n) -#endif + do i = 1,n C(:,i) = operator_cross_i2b(A(:,i), B(:,i)) end do return @@ -194,11 +174,7 @@ pure module function operator_cross_el_i4b(A, B) result(C) n = size(A, 2) if (allocated(C)) deallocate(C) allocate(C, mold = A) -#ifdef DOCONLOC - do concurrent (i = 1:n) shared(A,B,C) -#else - do concurrent (i = 1:n) -#endif + do i = 1,n C(:,i) = operator_cross_i4b(A(:,i), B(:,i)) end do return @@ -212,11 +188,7 @@ pure module function operator_cross_el_i8b(A, B) result(C) n = size(A, 2) if (allocated(C)) deallocate(C) allocate(C, mold = A) -#ifdef DOCONLOC - do concurrent (i = 1:n) shared(A,B,C) -#else - do concurrent (i = 1:n) -#endif + do i = 1,n C(:,i) = operator_cross_i8b(A(:,i), B(:,i)) end do return diff --git a/src/operator/operator_mag.f90 b/src/operator/operator_mag.f90 index 55f653fb9..721e4a930 100644 --- a/src/operator/operator_mag.f90 +++ b/src/operator/operator_mag.f90 @@ -44,11 +44,7 @@ pure module function operator_mag_el_sp(A) result(B) if (allocated(B)) deallocate(B) allocate(B(n)) call ieee_set_halting_mode(ieee_underflow, .false.) -#ifdef DOCONLOC - do concurrent (i = 1:n) shared(A,B) -#else - do concurrent (i = 1:n) -#endif + do i = 1,n B(i) = norm2(A(:, i)) end do return @@ -63,11 +59,7 @@ pure module function operator_mag_el_dp(A) result(B) if (allocated(B)) deallocate(B) allocate(B(n)) call ieee_set_halting_mode(ieee_underflow, .false.) -#ifdef DOCONLOC - do concurrent (i = 1:n) shared(A,B) -#else - do concurrent (i = 1:n) -#endif + do i = 1,n B(i) = norm2(A(:, i)) end do return @@ -82,11 +74,7 @@ pure module function operator_mag_el_qp(A) result(B) if (allocated(B)) deallocate(B) allocate(B(n)) call ieee_set_halting_mode(ieee_underflow, .false.) -#ifdef DOCONLOC - do concurrent (i = 1:n) shared(A,B) -#else - do concurrent (i = 1:n) -#endif + do i = 1,n B(i) = norm2(A(:, i)) end do return diff --git a/src/operator/operator_unit.f90 b/src/operator/operator_unit.f90 index a25ee1bb1..2a14f6645 100644 --- a/src/operator/operator_unit.f90 +++ b/src/operator/operator_unit.f90 @@ -89,11 +89,7 @@ pure module function operator_unit_el_sp(A) result(B) if (allocated(B)) deallocate(B) allocate(B(NDIM,n)) -#ifdef DOCONLOC - do concurrent (i=1:n) shared(A,B) -#else - do concurrent (i=1:n) -#endif + do i=1,n B(:,i) = operator_unit_sp(A(:,i)) end do @@ -113,11 +109,7 @@ pure module function operator_unit_el_dp(A) result(B) if (allocated(B)) deallocate(B) allocate(B(NDIM,n)) -#ifdef DOCONLOC - do concurrent (i=1:n) shared(A,B) -#else - do concurrent (i=1:n) -#endif + do i=1,n B(:,i) = operator_unit_dp(A(:,i)) end do @@ -136,11 +128,7 @@ pure module function operator_unit_el_qp(A) result(B) if (allocated(B)) deallocate(B) allocate(B(NDIM,n)) -#ifdef DOCONLOC - do concurrent (i=1:n) shared(A,B) -#else - do concurrent (i=1:n) -#endif + do i=1,n B(:,i) = operator_unit_qp(A(:,i)) end do From b8be3684a07da6424ad674a140bab8d411594890 Mon Sep 17 00:00:00 2001 From: David Minton Date: Tue, 6 Jun 2023 16:01:35 -0400 Subject: [PATCH 66/95] Removed -standard-semantics from the default flag list, because it is not compatible with the pre-built NetCDF Fortran library. Kept it in the containerized version. --- Dockerfile | 1 + cmake/Modules/SetFortranFlags.cmake | 8 -------- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index 0ac00b25d..d0f2dcb88 100644 --- a/Dockerfile +++ b/Dockerfile @@ -132,6 +132,7 @@ ENV NETCDF_LIBRARY=${NETCDF_HOME} ENV FOR_COARRAY_NUM_IMAGES=1 ENV OMP_NUM_THREADS=1 ENV FC="${INTEL_DIR}/mpi/latest/bin/mpiifort" +ENV FFLAGS="-fPIC -standard-semantics" ENV LDFLAGS="-L/usr/local/lib -L/usr/lib/x86_64-linux-gnu -lnetcdff -lnetcdf -lhdf5_hl -lhdf5 -lsz -lz -lzstd -lbz2 -lcurl -lxml2" COPY ./cmake/ /swiftest/cmake/ COPY ./src/ /swiftest/src/ diff --git a/cmake/Modules/SetFortranFlags.cmake b/cmake/Modules/SetFortranFlags.cmake index 550738f13..d1edd9ae9 100644 --- a/cmake/Modules/SetFortranFlags.cmake +++ b/cmake/Modules/SetFortranFlags.cmake @@ -81,14 +81,6 @@ SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}" Fortran "-fsignaling-nans " # GNU ) - -# Determines whether the current Fortran Standard behavior of the compiler is fully implemented. -SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}" - Fortran "-standard-semantics" # Intel - "/standard-semantics" # Intel Windows - ) - - # Allows for lines longer than 80 characters without truncation SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}" Fortran "-ffree-line-length-none" # GNU (gfortran) From f7b8f46205f4c431627f4452506c54d195b3fbf9 Mon Sep 17 00:00:00 2001 From: David Minton Date: Tue, 6 Jun 2023 18:21:47 -0400 Subject: [PATCH 67/95] Updated coarray code so it can compile in the container. --- Dockerfile | 14 +++++------ cmake/Modules/SetFortranFlags.cmake | 4 ++++ docker/bin/swiftest | 2 +- src/coarray/coarray_clone.f90 | 8 +++---- src/rmvs/rmvs_coarray.f90 | 10 +------- src/swiftest/swiftest_coarray.f90 | 36 ++++++++++++++++++----------- src/swiftest/swiftest_module.f90 | 8 +++++++ 7 files changed, 47 insertions(+), 35 deletions(-) diff --git a/Dockerfile b/Dockerfile index d0f2dcb88..35e450d7e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -94,7 +94,7 @@ RUN wget -qO- https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.14/hdf5-1.14 wget -qO- https://www.zlib.net/zlib-1.2.13.tar.gz | tar xvz && \ apt-get update && apt-get upgrade -y && \ DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ - libxml2-dev libcurl4-gnutls-dev libzstd-dev libbz2-dev libaec-dev m4 && \ + libxml2-dev libcurl4-gnutls-dev libzstd-dev libbz2-dev libaec-dev m4 && \ rm -rf /var/lib/apt/lists/* && \ cd hdf && \ ./HDF5-1.14.1-Linux.sh --skip-license && \ @@ -153,14 +153,13 @@ RUN echo 'find_path(NETCDF_INCLUDE_DIR NAMES netcdf.mod HINTS ENV NETCDF_FORTRAN 'set(NETCDF_LIBRARIES ${NETCDF_FORTRAN_LIBRARY} ${NETCDF_LIBRARY} ${HDF5_HL_LIBRARY} ${HDF5_LIBRARY} ${SZ_LIBRARY} ${Z_LIBRARY} ${ZSTD_LIBRARY} ${BZ2_LIBRARY} ${CURL_LIBRARY} ${XML2_LIBRARY} )\n' \ 'mark_as_advanced(NETCDF_LIBRARY NETCDF_FORTRAN_LIBRARY NETCDF_INCLUDE_DIR)\n' > /swiftest/cmake/Modules/FindNETCDF.cmake && \ cd swiftest && \ - cmake -S . -B build -DCMAKE_INSTALL_PREFIX="${INSTALL_DIR}" -DCONTAINERIZE=ON -DUSE_COARRAY=OFF -DCMAKE_BUILD_TYPE=RELEASE -DBUILD_SHARED_LIBS=OFF &&\ + cmake -S . -B build -DCMAKE_INSTALL_PREFIX="${INSTALL_DIR}" -DCONTAINERIZE=ON -DUSE_COARRAY=ON -DCMAKE_BUILD_TYPE=RELEASE -DBUILD_SHARED_LIBS=OFF &&\ cmake --build build --verbose && \ cmake --install build # Driver container FROM ubuntu:20.04 as Driver -COPY --from=build /opt/intel/oneapi/mpi/latest/lib/libmpifort.so.12 /usr/local/lib/ -COPY --from=build /opt/intel/oneapi/mpi/latest/lib/release/libmpi.so.12 /usr/local/lib/ +COPY --from=build /opt/intel/oneapi/compiler/2023.1.0/linux/compiler/lib/intel64_lin/libicaf.so /usr/local/lib/ COPY --from=build /usr/local/bin/swiftest_driver /usr/local/bin RUN apt-get update && apt-get upgrade -y && \ DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ @@ -172,9 +171,8 @@ FROM continuumio/miniconda3 ENV LD_LIBRARY_PATH="/usr/local/lib" ENV SHELL="/bin/bash" -COPY --from=build /opt/intel/oneapi/mpi/latest/lib/libmpifort.so.12 /usr/local/lib/ -COPY --from=build /opt/intel/oneapi/mpi/latest/lib/release/libmpi.so.12 /usr/local/lib/ COPY ./python/ . +COPY --from=build /opt/intel/oneapi/compiler/2023.1.0/linux/compiler/lib/intel64_lin/libicaf.so /usr/local/lib/ COPY --from=build /usr/local/bin/swiftest_driver /bin/ RUN apt-get update && apt-get upgrade -y && \ @@ -188,6 +186,8 @@ RUN apt-get update && apt-get upgrade -y && \ conda update --all -y && \ cd swiftest && conda develop . && \ mkdir -p /.astropy && \ - chmod -R 777 /.astropy + chmod -R 777 /.astropy && \ + mkdir -p /.config/matplotlib && \ + chmod -R 777 /.config/matplotlib ENTRYPOINT ["/opt/conda/bin/python"] \ No newline at end of file diff --git a/cmake/Modules/SetFortranFlags.cmake b/cmake/Modules/SetFortranFlags.cmake index d1edd9ae9..47361de08 100644 --- a/cmake/Modules/SetFortranFlags.cmake +++ b/cmake/Modules/SetFortranFlags.cmake @@ -117,6 +117,10 @@ IF (CONTAINERIZE) SET_COMPILE_FLAG(CMAKE_Fortran_LINK_FLAGS "${CMAKE_Fortran_LINK_FLAGS}" Fortran "-static-intel" # Intel ) + # Use static Intel MPI libraries + SET_COMPILE_FLAG(CMAKE_Fortran_LINK_FLAGS "${CMAKE_Fortran_LINK_FLAGS}" + Fortran "-static_mpi" # Intel + ) IF (USE_OPENMP) SET_COMPILE_FLAG(CMAKE_Fortran_LINK_FLAGS "${CMAKE_Fortran_LINK_FLAGS}" diff --git a/docker/bin/swiftest b/docker/bin/swiftest index bc94b2cb0..fead7f338 100755 --- a/docker/bin/swiftest +++ b/docker/bin/swiftest @@ -1,2 +1,2 @@ #!/bin/sh -- -docker run -v $(pwd):$(pwd) -w $(pwd) --user "$(id -u):$(id -g)" -t -e OMP_NUM_THREADS -e FOR_COARRAY_NUM_IMAGES swiftest:1.0.0 "$@" \ No newline at end of file +docker run -v $(pwd):$(pwd) -w $(pwd) --user "$(id -u):$(id -g)" -ti -e OMP_NUM_THREADS -e FOR_COARRAY_NUM_IMAGES swiftest:1.0.0 "$@" \ No newline at end of file diff --git a/src/coarray/coarray_clone.f90 b/src/coarray/coarray_clone.f90 index 9f7e1ea1a..893cff147 100644 --- a/src/coarray/coarray_clone.f90 +++ b/src/coarray/coarray_clone.f90 @@ -71,7 +71,7 @@ module subroutine coarray_component_clone_DP(var,src_img) sync all if (this_image() == si) then do img = 1, num_images() - tmp[img] = var + tmp[img] = var end do sync images(*) else @@ -117,7 +117,7 @@ module subroutine coarray_component_clone_DP_arr1D(var,src_img) allocate(tmp(n[si])[*]) if (this_image() == si) then do img = 1, num_images() - tmp(:)[img] = var + tmp(:)[img] = var end do sync images(*) else @@ -167,7 +167,7 @@ module subroutine coarray_component_clone_DP_arr2D(var,src_img) allocate(tmp(n1[si],n2[si])[*]) if (this_image() == si) then do img = 1, num_images() - tmp(:,:)[img] = var(:,:) + tmp(:,:)[img] = var(:,:) end do sync images(*) else @@ -252,7 +252,7 @@ module subroutine coarray_component_clone_DP_vec2D(var,src_img) allocate(tmp(NDIM,n[si])[*]) if (this_image() == si) then do img = 1, num_images() - tmp(:,:)[img] = var(:,:) + tmp(:,:)[img] = var(:,:) end do sync images(*) else diff --git a/src/rmvs/rmvs_coarray.f90 b/src/rmvs/rmvs_coarray.f90 index 6f7467df8..3a7508159 100644 --- a/src/rmvs/rmvs_coarray.f90 +++ b/src/rmvs/rmvs_coarray.f90 @@ -68,7 +68,6 @@ module subroutine rmvs_coarray_coclone_pl(self) end subroutine rmvs_coarray_coclone_pl - module subroutine rmvs_coarray_coclone_system(self) !! author: David A. Minton !! @@ -141,14 +140,7 @@ module subroutine rmvs_coarray_component_clone_interp_arr1D(var,src_img) do i = 1, n[si] call tmp(i)%coclone() end do - if (this_image() == si) then - do img = 1, num_images() - tmp(:)[img] = var(:) - end do - - sync images(*) - else - sync images(si) + if (this_image() /= si) then if (allocated(var)) deallocate(var) allocate(var, source=tmp) end if diff --git a/src/swiftest/swiftest_coarray.f90 b/src/swiftest/swiftest_coarray.f90 index 7dbd1a816..8329856b9 100644 --- a/src/swiftest/swiftest_coarray.f90 +++ b/src/swiftest/swiftest_coarray.f90 @@ -54,6 +54,7 @@ module subroutine swiftest_coarray_balance_system(nbody_system, param) return end subroutine swiftest_coarray_balance_system + module subroutine swiftest_coarray_coclone_body(self) !! author: David A. Minton !! @@ -94,6 +95,21 @@ module subroutine swiftest_coarray_coclone_body(self) return end subroutine swiftest_coarray_coclone_body + module subroutine swiftest_coarray_coclone_kin(self) + !! author: David A. Minton + !! + !! Broadcasts the image 1 object to all other images in a coarray + implicit none + ! Arguments + class(swiftest_kinship),intent(inout),codimension[*] :: self !! Swiftest kinship object + + call coclone(self%parent) + call coclone(self%nchild) + call coclone(self%child) + + return + end subroutine swiftest_coarray_coclone_kin + module subroutine swiftest_coarray_coclone_nc(self) !! author: David A. Minton !! @@ -327,10 +343,6 @@ module subroutine swiftest_coarray_coclone_system(self) ! Internals integer(I4B) :: i - call self%cb%coclone() - call self%pl%coclone() - call self%tp%coclone() - call coclone(self%maxid) call coclone(self%t) call coclone(self%GMtot) @@ -474,7 +486,7 @@ module subroutine swiftest_coarray_component_clone_kin_arr1D(var,src_img) integer(I4B), intent(in),optional :: src_img ! Internals type(swiftest_kinship), dimension(:), codimension[:], allocatable :: tmp - integer(I4B) :: img, si + integer(I4B) :: i, img, si integer(I4B), allocatable :: n[:] logical, allocatable :: isalloc[:] @@ -484,21 +496,17 @@ module subroutine swiftest_coarray_component_clone_kin_arr1D(var,src_img) si = 1 end if - allocate(isalloc[*]) - allocate(n[*]) + sync all isalloc = allocated(var) if (isalloc) n = size(var) sync all if (.not. isalloc[si]) return allocate(tmp(n[si])[*]) - if (this_image() == si) then - do img = 1, num_images() - tmp(:)[img] = var - end do - sync images(*) - else - sync images(si) + do i = 1, n[si] + call tmp(i)%coclone() + end do + if (this_image() /= si) then if (allocated(var)) deallocate(var) allocate(var, source=tmp) end if diff --git a/src/swiftest/swiftest_module.f90 b/src/swiftest/swiftest_module.f90 index a54e2351b..b7bbd109c 100644 --- a/src/swiftest/swiftest_module.f90 +++ b/src/swiftest/swiftest_module.f90 @@ -93,6 +93,9 @@ module swiftest integer(I4B), dimension(:), allocatable :: child !! Index of children particles contains procedure :: dealloc => swiftest_util_dealloc_kin !! Deallocates all allocatable arrays +#ifdef COARRAY + procedure :: coclone => swiftest_coarray_coclone_kin !! Clones the image 1 body object to all other images in the coarray structure. +#endif final :: swiftest_final_kin !! Finalizes the Swiftest kinship object - deallocates all allocatables end type swiftest_kinship @@ -1776,6 +1779,11 @@ module subroutine swiftest_coarray_coclone_cb(self) class(swiftest_cb),intent(inout),codimension[*] :: self !! Swiftest cb object end subroutine swiftest_coarray_coclone_cb + module subroutine swiftest_coarray_coclone_kin(self) + implicit none + class(swiftest_kinship),intent(inout),codimension[*] :: self !! Swiftest kinship object + end subroutine swiftest_coarray_coclone_kin + module subroutine swiftest_coarray_coclone_nc(self) implicit none class(swiftest_netcdf_parameters),intent(inout),codimension[*] :: self !! Swiftest body object From c0546f649ee9ec7dd4e9b0cb87b23170f54bed4a Mon Sep 17 00:00:00 2001 From: David Minton Date: Tue, 6 Jun 2023 22:25:20 -0400 Subject: [PATCH 68/95] Improved Docker container --- Dockerfile | 51 ++++++++++++++++-------- docker/.gitignore | 3 +- docker/bin/swiftest_driver | 2 + docker/bin/{swiftest => swiftest_python} | 0 4 files changed, 38 insertions(+), 18 deletions(-) create mode 100755 docker/bin/swiftest_driver rename docker/bin/{swiftest => swiftest_python} (100%) diff --git a/Dockerfile b/Dockerfile index 35e450d7e..9fe400197 100644 --- a/Dockerfile +++ b/Dockerfile @@ -154,26 +154,19 @@ RUN echo 'find_path(NETCDF_INCLUDE_DIR NAMES netcdf.mod HINTS ENV NETCDF_FORTRAN 'mark_as_advanced(NETCDF_LIBRARY NETCDF_FORTRAN_LIBRARY NETCDF_INCLUDE_DIR)\n' > /swiftest/cmake/Modules/FindNETCDF.cmake && \ cd swiftest && \ cmake -S . -B build -DCMAKE_INSTALL_PREFIX="${INSTALL_DIR}" -DCONTAINERIZE=ON -DUSE_COARRAY=ON -DCMAKE_BUILD_TYPE=RELEASE -DBUILD_SHARED_LIBS=OFF &&\ - cmake --build build --verbose && \ + cmake --build build && \ + cp bin/swiftest_driver /usr/local/bin/swiftest_driver_caf && \ + rm -rf build && \ + cmake -S . -B build -DCMAKE_INSTALL_PREFIX="${INSTALL_DIR}" -DCONTAINERIZE=ON -DUSE_COARRAY=OFF -DCMAKE_BUILD_TYPE=RELEASE -DBUILD_SHARED_LIBS=OFF &&\ + cmake --build build && \ cmake --install build # Driver container -FROM ubuntu:20.04 as Driver +FROM continuumio/miniconda3 as setup_conda COPY --from=build /opt/intel/oneapi/compiler/2023.1.0/linux/compiler/lib/intel64_lin/libicaf.so /usr/local/lib/ COPY --from=build /usr/local/bin/swiftest_driver /usr/local/bin -RUN apt-get update && apt-get upgrade -y && \ - DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ - libsz2 libcurl3-gnutls libxml2 && \ - rm -rf /var/lib/apt/lists/* - -# Production container -FROM continuumio/miniconda3 - -ENV LD_LIBRARY_PATH="/usr/local/lib" -ENV SHELL="/bin/bash" -COPY ./python/ . -COPY --from=build /opt/intel/oneapi/compiler/2023.1.0/linux/compiler/lib/intel64_lin/libicaf.so /usr/local/lib/ COPY --from=build /usr/local/bin/swiftest_driver /bin/ +COPY ./python/. /opt/conda/pkgs/swiftest/python/ RUN apt-get update && apt-get upgrade -y && \ DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ @@ -184,10 +177,34 @@ RUN apt-get update && apt-get upgrade -y && \ conda config --set solver libmamba && \ conda install -c conda-forge conda-build numpy scipy matplotlib pandas xarray astropy astroquery tqdm x264 bottleneck ffmpeg h5netcdf netcdf4 dask -y && \ conda update --all -y && \ - cd swiftest && conda develop . && \ - mkdir -p /.astropy && \ + cd /opt/conda/pkgs/swiftest/python/swiftest && conda develop . && \ + conda clean --all -y + +# Production container +FROM ubuntu:20.04 + +RUN apt-get update && apt-get upgrade -y && \ + DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + libsz2 libcurl3-gnutls libxml2 && \ + rm -rf /var/lib/apt/lists/* + +ENV LD_LIBRARY_PATH="/usr/local/lib" +ENV SHELL="/bin/bash" +COPY --from=build /opt/intel/oneapi/compiler/2023.1.0/linux/compiler/lib/intel64_lin/libicaf.so /usr/local/lib/ +COPY --from=build /opt/intel/oneapi/mpi/2021.9.0//lib/release/libmpi.so.12 /usr/local/lib/ +COPY --from=build /opt/intel/oneapi/compiler/2023.1.0/linux/compiler/lib/intel64_lin/libintlc.so.5 /usr/local/lib/ +COPY --from=setup_conda /opt/conda/. /opt/conda/ +COPY --from=build /opt/intel/oneapi/mpi/latest/bin/mpiexec.hydra /usr/local/bin/ +COPY --from=build /usr/local/bin/swiftest_driver /usr/local/bin +COPY --from=build /usr/local/bin/swiftest_driver_caf /usr/local/bin/ + +RUN mkdir -p /.astropy && \ chmod -R 777 /.astropy && \ + mkdir -p /.cache/matplotlib && \ mkdir -p /.config/matplotlib && \ - chmod -R 777 /.config/matplotlib + chmod -R 777 /.cache/matplotlib && \ + chmod -R 777 /.config/matplotlib && \ + mkdir -p /opt/conda/pkgs/swiftest/bin && \ + ln -s /usr/local/bin/swiftest_driver /opt/conda/pkgs/swiftest/bin/swiftest_driver ENTRYPOINT ["/opt/conda/bin/python"] \ No newline at end of file diff --git a/docker/.gitignore b/docker/.gitignore index 09c5585d1..772f5a9d9 100644 --- a/docker/.gitignore +++ b/docker/.gitignore @@ -2,4 +2,5 @@ !.gitignore !install.sh !bin -!bin/swiftest +!bin/swiftest_python +!bin/swiftest_driver diff --git a/docker/bin/swiftest_driver b/docker/bin/swiftest_driver new file mode 100755 index 000000000..0f7d8b5dd --- /dev/null +++ b/docker/bin/swiftest_driver @@ -0,0 +1,2 @@ +#!/bin/sh -- +docker run -v $(pwd):$(pwd) -w $(pwd) --user "$(id -u):$(id -g)" -ti --entrypoint /usr/local/bin/swiftest_driver -e OMP_NUM_THREADS -e FOR_COARRAY_NUM_IMAGES swiftest:1.0.0 "$@" \ No newline at end of file diff --git a/docker/bin/swiftest b/docker/bin/swiftest_python similarity index 100% rename from docker/bin/swiftest rename to docker/bin/swiftest_python From 7152017d63c6e13f2c1be48d014329152499a9e7 Mon Sep 17 00:00:00 2001 From: David Minton Date: Tue, 6 Jun 2023 22:33:28 -0400 Subject: [PATCH 69/95] More improvements to containers --- Dockerfile | 16 ++-------------- singularity/bin/swiftest_driver | 2 +- singularity/install.sh | 2 +- singularity/setenv.sh | 2 +- 4 files changed, 5 insertions(+), 17 deletions(-) diff --git a/Dockerfile b/Dockerfile index 9fe400197..2d7821992 100644 --- a/Dockerfile +++ b/Dockerfile @@ -161,11 +161,8 @@ RUN echo 'find_path(NETCDF_INCLUDE_DIR NAMES netcdf.mod HINTS ENV NETCDF_FORTRAN cmake --build build && \ cmake --install build -# Driver container -FROM continuumio/miniconda3 as setup_conda -COPY --from=build /opt/intel/oneapi/compiler/2023.1.0/linux/compiler/lib/intel64_lin/libicaf.so /usr/local/lib/ -COPY --from=build /usr/local/bin/swiftest_driver /usr/local/bin -COPY --from=build /usr/local/bin/swiftest_driver /bin/ +# Production container +FROM continuumio/miniconda3 COPY ./python/. /opt/conda/pkgs/swiftest/python/ RUN apt-get update && apt-get upgrade -y && \ @@ -180,20 +177,11 @@ RUN apt-get update && apt-get upgrade -y && \ cd /opt/conda/pkgs/swiftest/python/swiftest && conda develop . && \ conda clean --all -y -# Production container -FROM ubuntu:20.04 - -RUN apt-get update && apt-get upgrade -y && \ - DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ - libsz2 libcurl3-gnutls libxml2 && \ - rm -rf /var/lib/apt/lists/* - ENV LD_LIBRARY_PATH="/usr/local/lib" ENV SHELL="/bin/bash" COPY --from=build /opt/intel/oneapi/compiler/2023.1.0/linux/compiler/lib/intel64_lin/libicaf.so /usr/local/lib/ COPY --from=build /opt/intel/oneapi/mpi/2021.9.0//lib/release/libmpi.so.12 /usr/local/lib/ COPY --from=build /opt/intel/oneapi/compiler/2023.1.0/linux/compiler/lib/intel64_lin/libintlc.so.5 /usr/local/lib/ -COPY --from=setup_conda /opt/conda/. /opt/conda/ COPY --from=build /opt/intel/oneapi/mpi/latest/bin/mpiexec.hydra /usr/local/bin/ COPY --from=build /usr/local/bin/swiftest_driver /usr/local/bin COPY --from=build /usr/local/bin/swiftest_driver_caf /usr/local/bin/ diff --git a/singularity/bin/swiftest_driver b/singularity/bin/swiftest_driver index dba0863a9..30fe6352b 100755 --- a/singularity/bin/swiftest_driver +++ b/singularity/bin/swiftest_driver @@ -1,2 +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} "$@" \ No newline at end of file +singularity run --bind $(pwd):$(pwd) exec --env OMP_NUM_THREADS=${OMP_NUM_THREADS},FOR_COARRAY_NUM_IMAGES=${FOR_COARRAY_NUM_IMAGES} ${SWIFTEST_SIF} swiftest_driver "$@" \ No newline at end of file diff --git a/singularity/install.sh b/singularity/install.sh index ff2be8596..99cae29c1 100755 --- a/singularity/install.sh +++ b/singularity/install.sh @@ -5,6 +5,6 @@ # tag=${1:-latest} echo "Installing swiftest_driver.sif Singularity container and executable script from swiftest_driver:${tag} Docker container" -singularity pull --force swiftest_driver.sif docker://daminton/swiftest_driver:${tag} +singularity pull --force swiftest.sif docker://daminton/swiftest:${tag} cp -rf bin/swiftest_driver ../bin/ source ./setenv.sh \ No newline at end of file diff --git a/singularity/setenv.sh b/singularity/setenv.sh index cc8905033..82ca7d408 100755 --- a/singularity/setenv.sh +++ b/singularity/setenv.sh @@ -1,4 +1,4 @@ #!/bin/sh -- # This will set the SWIFTEST_SIF environment variable as long as it is executed by source. # $ . ./setenv.sh -export SWIFTEST_SIF="${PWD}/swiftest_driver.sif" \ No newline at end of file +export SWIFTEST="${PWD}/swiftest.sif" \ No newline at end of file From 35e0099e9934c18b07c5add1ca4cbf93207823f0 Mon Sep 17 00:00:00 2001 From: David Minton Date: Wed, 7 Jun 2023 08:52:57 -0400 Subject: [PATCH 70/95] Updates to singularity scripts and also added apptainer scripts --- apptainer/.gitignore | 5 +++++ apptainer/bin/swiftest_driver | 2 ++ apptainer/bin/swiftest_python | 2 ++ apptainer/install.sh | 10 ++++++++++ apptainer/setenv.sh | 4 ++++ singularity/.gitignore | 1 + singularity/bin/swiftest_driver | 2 +- singularity/bin/swiftest_python | 2 ++ 8 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 apptainer/.gitignore create mode 100755 apptainer/bin/swiftest_driver create mode 100755 apptainer/bin/swiftest_python create mode 100755 apptainer/install.sh create mode 100755 apptainer/setenv.sh create mode 100755 singularity/bin/swiftest_python diff --git a/apptainer/.gitignore b/apptainer/.gitignore new file mode 100644 index 000000000..6ddbdba9f --- /dev/null +++ b/apptainer/.gitignore @@ -0,0 +1,5 @@ +!bin/ +!bin/swiftest_driver +!bin/swiftest_python +!install.sh +!setenv.sh diff --git a/apptainer/bin/swiftest_driver b/apptainer/bin/swiftest_driver new file mode 100755 index 000000000..fa008737a --- /dev/null +++ b/apptainer/bin/swiftest_driver @@ -0,0 +1,2 @@ +#!/bin/sh -- +apptainer exec --bind $(pwd):$(pwd) --env OMP_NUM_THREADS=${OMP_NUM_THREADS},FOR_COARRAY_NUM_IMAGES=${FOR_COARRAY_NUM_IMAGES} ${SWIFTEST_SIF} swiftest_driver "$@" \ No newline at end of file diff --git a/apptainer/bin/swiftest_python b/apptainer/bin/swiftest_python new file mode 100755 index 000000000..b33012e4a --- /dev/null +++ b/apptainer/bin/swiftest_python @@ -0,0 +1,2 @@ +#!/bin/sh -- +apptainer run --bind $(pwd):$(pwd) --env OMP_NUM_THREADS=${OMP_NUM_THREADS},FOR_COARRAY_NUM_IMAGES=${FOR_COARRAY_NUM_IMAGES} ${SWIFTEST_SIF} swiftest_driver "$@" \ No newline at end of file diff --git a/apptainer/install.sh b/apptainer/install.sh new file mode 100755 index 000000000..abf9f4f91 --- /dev/null +++ b/apptainer/install.sh @@ -0,0 +1,10 @@ +#!/bin/sh -- +# This will install the Singularity container version of the swiftest_driver in place of the native compiled version into ../bin. +# In order to use the executable script, the SWIFTEST_SIF environment variable must be set to point to the location of swiftest_driver.sif, which requires this script to be called via source: +# $ . ./install.sh +# +tag=${1:-latest} +echo "Installing swiftest_driver.sif Singularity container and executable script from swiftest_driver:${tag} Docker container" +apptainer pull --force swiftest.sif docker://daminton/swiftest:${tag} +cp -rf bin/swiftest_driver ../bin/ +source ./setenv.sh \ No newline at end of file diff --git a/apptainer/setenv.sh b/apptainer/setenv.sh new file mode 100755 index 000000000..82ca7d408 --- /dev/null +++ b/apptainer/setenv.sh @@ -0,0 +1,4 @@ +#!/bin/sh -- +# This will set the SWIFTEST_SIF environment variable as long as it is executed by source. +# $ . ./setenv.sh +export SWIFTEST="${PWD}/swiftest.sif" \ No newline at end of file diff --git a/singularity/.gitignore b/singularity/.gitignore index 2a259d270..6ddbdba9f 100644 --- a/singularity/.gitignore +++ b/singularity/.gitignore @@ -1,4 +1,5 @@ !bin/ !bin/swiftest_driver +!bin/swiftest_python !install.sh !setenv.sh diff --git a/singularity/bin/swiftest_driver b/singularity/bin/swiftest_driver index 30fe6352b..03876195b 100755 --- a/singularity/bin/swiftest_driver +++ b/singularity/bin/swiftest_driver @@ -1,2 +1,2 @@ #!/bin/sh -- -singularity run --bind $(pwd):$(pwd) exec --env OMP_NUM_THREADS=${OMP_NUM_THREADS},FOR_COARRAY_NUM_IMAGES=${FOR_COARRAY_NUM_IMAGES} ${SWIFTEST_SIF} swiftest_driver "$@" \ No newline at end of file +singularity exec --bind $(pwd):$(pwd) --env OMP_NUM_THREADS=${OMP_NUM_THREADS},FOR_COARRAY_NUM_IMAGES=${FOR_COARRAY_NUM_IMAGES} ${SWIFTEST_SIF} swiftest_driver "$@" \ No newline at end of file diff --git a/singularity/bin/swiftest_python b/singularity/bin/swiftest_python new file mode 100755 index 000000000..4061ff119 --- /dev/null +++ b/singularity/bin/swiftest_python @@ -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} swiftest_driver "$@" \ No newline at end of file From aa0acbfacc44834a80d7d1c79248c8f10c1669fc Mon Sep 17 00:00:00 2001 From: David Minton Date: Wed, 7 Jun 2023 08:56:09 -0400 Subject: [PATCH 71/95] Fixed typos in Singularity/Apptainer scripts --- apptainer/bin/swiftest_python | 2 +- singularity/bin/swiftest_python | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apptainer/bin/swiftest_python b/apptainer/bin/swiftest_python index b33012e4a..6d562c962 100755 --- a/apptainer/bin/swiftest_python +++ b/apptainer/bin/swiftest_python @@ -1,2 +1,2 @@ #!/bin/sh -- -apptainer run --bind $(pwd):$(pwd) --env OMP_NUM_THREADS=${OMP_NUM_THREADS},FOR_COARRAY_NUM_IMAGES=${FOR_COARRAY_NUM_IMAGES} ${SWIFTEST_SIF} swiftest_driver "$@" \ No newline at end of file +apptainer run --bind $(pwd):$(pwd) --env OMP_NUM_THREADS=${OMP_NUM_THREADS},FOR_COARRAY_NUM_IMAGES=${FOR_COARRAY_NUM_IMAGES} ${SWIFTEST_SIF} "$@" \ No newline at end of file diff --git a/singularity/bin/swiftest_python b/singularity/bin/swiftest_python index 4061ff119..2a7b13735 100755 --- a/singularity/bin/swiftest_python +++ b/singularity/bin/swiftest_python @@ -1,2 +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} swiftest_driver "$@" \ No newline at end of file +singularity run --bind $(pwd):$(pwd) --env OMP_NUM_THREADS=${OMP_NUM_THREADS},FOR_COARRAY_NUM_IMAGES=${FOR_COARRAY_NUM_IMAGES} ${SWIFTEST_SIF} "$@" \ No newline at end of file From 5f2e9bfc6ce1df4f3bbc90dffb1fa1c7b0c762ef Mon Sep 17 00:00:00 2001 From: David Minton Date: Wed, 7 Jun 2023 08:58:03 -0400 Subject: [PATCH 72/95] Fixed typo in Singularity/Apptainer install scripts --- apptainer/setenv.sh | 2 +- singularity/setenv.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apptainer/setenv.sh b/apptainer/setenv.sh index 82ca7d408..d9f215d7c 100755 --- a/apptainer/setenv.sh +++ b/apptainer/setenv.sh @@ -1,4 +1,4 @@ #!/bin/sh -- # This will set the SWIFTEST_SIF environment variable as long as it is executed by source. # $ . ./setenv.sh -export SWIFTEST="${PWD}/swiftest.sif" \ No newline at end of file +export SWIFTEST_SIF="${PWD}/swiftest.sif" \ No newline at end of file diff --git a/singularity/setenv.sh b/singularity/setenv.sh index 82ca7d408..d9f215d7c 100755 --- a/singularity/setenv.sh +++ b/singularity/setenv.sh @@ -1,4 +1,4 @@ #!/bin/sh -- # This will set the SWIFTEST_SIF environment variable as long as it is executed by source. # $ . ./setenv.sh -export SWIFTEST="${PWD}/swiftest.sif" \ No newline at end of file +export SWIFTEST_SIF="${PWD}/swiftest.sif" \ No newline at end of file From da9b30019a921bed44197cee321a0350f2e46ce5 Mon Sep 17 00:00:00 2001 From: David Minton Date: Wed, 7 Jun 2023 09:00:36 -0400 Subject: [PATCH 73/95] More typo fixes and cleanup --- apptainer/install.sh | 5 +++-- singularity/install.sh | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/apptainer/install.sh b/apptainer/install.sh index abf9f4f91..a36eaf3a1 100755 --- a/apptainer/install.sh +++ b/apptainer/install.sh @@ -1,10 +1,11 @@ #!/bin/sh -- # This will install the Singularity container version of the swiftest_driver in place of the native compiled version into ../bin. -# In order to use the executable script, the SWIFTEST_SIF environment variable must be set to point to the location of swiftest_driver.sif, which requires this script to be called via source: +# In order to use the executable script, the SWIFTEST_SIF environment variable must be set to point to the location of swiftest.sif, which requires this script to be called via source: # $ . ./install.sh # tag=${1:-latest} -echo "Installing swiftest_driver.sif Singularity container and executable script from swiftest_driver:${tag} Docker container" +echo "Installing swiftest_driver.sif Singularity container and executable script from swiftest:${tag} Docker container" apptainer pull --force swiftest.sif docker://daminton/swiftest:${tag} cp -rf bin/swiftest_driver ../bin/ +cp -rf bin/swiftest_python ../bin/ source ./setenv.sh \ No newline at end of file diff --git a/singularity/install.sh b/singularity/install.sh index 99cae29c1..3c1f3445d 100755 --- a/singularity/install.sh +++ b/singularity/install.sh @@ -1,10 +1,11 @@ #!/bin/sh -- # This will install the Singularity container version of the swiftest_driver in place of the native compiled version into ../bin. -# In order to use the executable script, the SWIFTEST_SIF environment variable must be set to point to the location of swiftest_driver.sif, which requires this script to be called via source: +# In order to use the executable script, the SWIFTEST_SIF environment variable must be set to point to the location of swiftest.sif, which requires this script to be called via source: # $ . ./install.sh # tag=${1:-latest} -echo "Installing swiftest_driver.sif Singularity container and executable script from swiftest_driver:${tag} Docker container" +echo "Installing swiftest_driver.sif Singularity container and executable script from swiftest:${tag} Docker container" singularity pull --force swiftest.sif docker://daminton/swiftest:${tag} cp -rf bin/swiftest_driver ../bin/ +cp -rf bin/swiftest_python ../bin/ source ./setenv.sh \ No newline at end of file From c8ba0905b5dce9d56c4f518c1b3031defc8fe00f Mon Sep 17 00:00:00 2001 From: David Minton Date: Wed, 7 Jun 2023 09:03:42 -0400 Subject: [PATCH 74/95] Typos in install scripts --- apptainer/install.sh | 2 +- singularity/install.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apptainer/install.sh b/apptainer/install.sh index a36eaf3a1..4250b5abb 100755 --- a/apptainer/install.sh +++ b/apptainer/install.sh @@ -4,7 +4,7 @@ # $ . ./install.sh # tag=${1:-latest} -echo "Installing swiftest_driver.sif Singularity container and executable script from swiftest:${tag} Docker container" +echo "Installing swiftest.sif Singularity container and executable script from swiftest:${tag} Docker container" apptainer pull --force swiftest.sif docker://daminton/swiftest:${tag} cp -rf bin/swiftest_driver ../bin/ cp -rf bin/swiftest_python ../bin/ diff --git a/singularity/install.sh b/singularity/install.sh index 3c1f3445d..e7c47e2b3 100755 --- a/singularity/install.sh +++ b/singularity/install.sh @@ -4,7 +4,7 @@ # $ . ./install.sh # tag=${1:-latest} -echo "Installing swiftest_driver.sif Singularity container and executable script from swiftest:${tag} Docker container" +echo "Installing swiftest.sif Singularity container and executable script from swiftest:${tag} Docker container" singularity pull --force swiftest.sif docker://daminton/swiftest:${tag} cp -rf bin/swiftest_driver ../bin/ cp -rf bin/swiftest_python ../bin/ From 10935fb97bc0dc1cc094de6d47ce8b3ba57174da Mon Sep 17 00:00:00 2001 From: David Minton Date: Wed, 7 Jun 2023 16:23:29 -0400 Subject: [PATCH 75/95] Made significant improvements to the Docker, Apptainer, and Singularity containers. --- Dockerfile | 40 +++++++++++--------- apptainer/.gitignore | 3 +- apptainer/bin/{swiftest_python => swiftest} | 2 + apptainer/bin/swiftest_driver | 2 + apptainer/install.sh | 26 +++++++++---- apptainer/setenv.sh | 4 -- docker/.gitignore | 2 +- docker/bin/swiftest | 4 ++ docker/bin/swiftest_driver | 4 +- docker/bin/swiftest_python | 2 - docker/install.sh | 5 ++- python/swiftest/swiftest/simulation_class.py | 23 +++++------ singularity/.gitignore | 1 - singularity/bin/swiftest_driver | 2 + singularity/bin/swiftest_python | 2 - singularity/install.sh | 26 +++++++++---- singularity/setenv.sh | 4 -- 17 files changed, 86 insertions(+), 66 deletions(-) rename apptainer/bin/{swiftest_python => swiftest} (60%) delete mode 100755 apptainer/setenv.sh create mode 100755 docker/bin/swiftest delete mode 100755 docker/bin/swiftest_python delete mode 100755 singularity/bin/swiftest_python delete mode 100755 singularity/setenv.sh diff --git a/Dockerfile b/Dockerfile index 2d7821992..b53f8dc8c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -163,7 +163,12 @@ RUN echo 'find_path(NETCDF_INCLUDE_DIR NAMES netcdf.mod HINTS ENV NETCDF_FORTRAN # Production container FROM continuumio/miniconda3 -COPY ./python/. /opt/conda/pkgs/swiftest/python/ +SHELL ["/bin/bash", "--login", "-c"] +ENV SHELL="/bin/bash" +ENV PATH="/opt/conda/bin:${PATH}" +ENV LD_LIBRARY_PATH="/usr/local/lib" + +COPY environment.yml . RUN apt-get update && apt-get upgrade -y && \ DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ @@ -172,27 +177,28 @@ RUN apt-get update && apt-get upgrade -y && \ conda update --all -y && \ conda install conda-libmamba-solver -y && \ conda config --set solver libmamba && \ - conda install -c conda-forge conda-build numpy scipy matplotlib pandas xarray astropy astroquery tqdm x264 bottleneck ffmpeg h5netcdf netcdf4 dask -y && \ - conda update --all -y && \ - cd /opt/conda/pkgs/swiftest/python/swiftest && conda develop . && \ - conda clean --all -y + conda env create -f environment.yml && \ + conda init bash && \ + echo "conda activate swiftest-env" >> ~/.bashrc -ENV LD_LIBRARY_PATH="/usr/local/lib" -ENV SHELL="/bin/bash" -COPY --from=build /opt/intel/oneapi/compiler/2023.1.0/linux/compiler/lib/intel64_lin/libicaf.so /usr/local/lib/ -COPY --from=build /opt/intel/oneapi/mpi/2021.9.0//lib/release/libmpi.so.12 /usr/local/lib/ -COPY --from=build /opt/intel/oneapi/compiler/2023.1.0/linux/compiler/lib/intel64_lin/libintlc.so.5 /usr/local/lib/ -COPY --from=build /opt/intel/oneapi/mpi/latest/bin/mpiexec.hydra /usr/local/bin/ -COPY --from=build /usr/local/bin/swiftest_driver /usr/local/bin -COPY --from=build /usr/local/bin/swiftest_driver_caf /usr/local/bin/ +COPY ./python/. /opt/conda/pkgs/ +COPY --from=build /usr/local/bin/swiftest_driver /opt/conda/envs/swiftest-env/bin/ +COPY --from=build /usr/local/bin/swiftest_driver /opt/conda/bin/ +COPY --from=build /usr/local/bin/swiftest_driver_caf /opt/conda/envs/swiftest-env/bin/ +COPY --from=build /opt/intel/oneapi/compiler/2023.1.0/linux/compiler/lib/intel64_lin/libicaf.so /opt/conda/envs/swiftest-env/lib/ +COPY --from=build /opt/intel/oneapi/mpi/2021.9.0//lib/release/libmpi.so.12 /opt/conda/envs/swiftest-env/lib/ +COPY --from=build /opt/intel/oneapi/compiler/2023.1.0/linux/compiler/lib/intel64_lin/libintlc.so.5 /opt/conda/envs/swiftest-env/lib/ +COPY --from=build /opt/intel/oneapi/mpi/latest/bin/mpiexec.hydra /opt/conda/envs/swiftest-env/bin/ -RUN mkdir -p /.astropy && \ +# Start new shell to activate the environment and install Swiftest +RUN cd /opt/conda/pkgs/swiftest && conda develop . && \ + conda clean --all -y && \ + mkdir -p /.astropy && \ chmod -R 777 /.astropy && \ mkdir -p /.cache/matplotlib && \ mkdir -p /.config/matplotlib && \ chmod -R 777 /.cache/matplotlib && \ chmod -R 777 /.config/matplotlib && \ - mkdir -p /opt/conda/pkgs/swiftest/bin && \ - ln -s /usr/local/bin/swiftest_driver /opt/conda/pkgs/swiftest/bin/swiftest_driver + ln -s /opt/conda/bin/swiftest_driver /opt/conda/bin/driver -ENTRYPOINT ["/opt/conda/bin/python"] \ No newline at end of file +ENTRYPOINT ["conda", "run", "--no-capture-output", "-n", "swiftest-env"] \ No newline at end of file diff --git a/apptainer/.gitignore b/apptainer/.gitignore index 6ddbdba9f..baed94e88 100644 --- a/apptainer/.gitignore +++ b/apptainer/.gitignore @@ -1,5 +1,4 @@ !bin/ !bin/swiftest_driver -!bin/swiftest_python +!bin/swiftest !install.sh -!setenv.sh diff --git a/apptainer/bin/swiftest_python b/apptainer/bin/swiftest similarity index 60% rename from apptainer/bin/swiftest_python rename to apptainer/bin/swiftest index 6d562c962..ca0fcfadd 100755 --- a/apptainer/bin/swiftest_python +++ b/apptainer/bin/swiftest @@ -1,2 +1,4 @@ #!/bin/sh -- +OMP_NUM_THREADS=${OMP_NUM_THREADS:-`nproc --all`} +FOR_COARRAY_NUM_IMAGES=${FOR_COARRAY_NUM_IMAGES:-1} apptainer run --bind $(pwd):$(pwd) --env OMP_NUM_THREADS=${OMP_NUM_THREADS},FOR_COARRAY_NUM_IMAGES=${FOR_COARRAY_NUM_IMAGES} ${SWIFTEST_SIF} "$@" \ No newline at end of file diff --git a/apptainer/bin/swiftest_driver b/apptainer/bin/swiftest_driver index fa008737a..e88be2805 100755 --- a/apptainer/bin/swiftest_driver +++ b/apptainer/bin/swiftest_driver @@ -1,2 +1,4 @@ #!/bin/sh -- +OMP_NUM_THREADS=${OMP_NUM_THREADS:-`nproc --all`} +FOR_COARRAY_NUM_IMAGES=${FOR_COARRAY_NUM_IMAGES:-1} apptainer exec --bind $(pwd):$(pwd) --env OMP_NUM_THREADS=${OMP_NUM_THREADS},FOR_COARRAY_NUM_IMAGES=${FOR_COARRAY_NUM_IMAGES} ${SWIFTEST_SIF} swiftest_driver "$@" \ No newline at end of file diff --git a/apptainer/install.sh b/apptainer/install.sh index 4250b5abb..5d84ca34a 100755 --- a/apptainer/install.sh +++ b/apptainer/install.sh @@ -1,11 +1,21 @@ #!/bin/sh -- -# This will install the Singularity container version of the swiftest_driver in place of the native compiled version into ../bin. -# In order to use the executable script, the SWIFTEST_SIF environment variable must be set to point to the location of swiftest.sif, which requires this script to be called via source: -# $ . ./install.sh +# This will install the Apptainer version of the swiftest_driver in place of the native compiled version into ../bin as +# well as the swiftest_python script that is used to execute a Python input file. +# The swiftest.sif file will be copied to the SIF_DIR directory. The default location is ${HOME}/.apptainer. +# To change this, just set environment variable SIF_DIR prior to running this script. +# +# The script takes an optional argument "tag" if you want to pull a container other than "latest". # -tag=${1:-latest} -echo "Installing swiftest.sif Singularity container and executable script from swiftest:${tag} Docker container" -apptainer pull --force swiftest.sif docker://daminton/swiftest:${tag} +# In order to use one executable script, the SWIFTEST_SIF environment variable must be set to point to the location of swiftest.sif, +# which requires this script to be called via source: +# $ source ./install.sh +# or +# $ . ./install.sh +TAG=${1:-latest} + +SIF_DIR=${SIF_DIR:-${HOME}/.apptainer} +echo "Installing ${SIF_DIR}/swiftest.sif container from mintongroup/swiftest:${TAG} Docker container" +apptainer pull --force ${SIF_DIR}/swiftest.sif docker://mintongroup/swiftest:${TAG} +cp -rf bin/swiftest ../bin/ cp -rf bin/swiftest_driver ../bin/ -cp -rf bin/swiftest_python ../bin/ -source ./setenv.sh \ No newline at end of file +export SWIFTEST_SIF=${SIF_DIR}/swiftest.sif \ No newline at end of file diff --git a/apptainer/setenv.sh b/apptainer/setenv.sh deleted file mode 100755 index d9f215d7c..000000000 --- a/apptainer/setenv.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh -- -# This will set the SWIFTEST_SIF environment variable as long as it is executed by source. -# $ . ./setenv.sh -export SWIFTEST_SIF="${PWD}/swiftest.sif" \ No newline at end of file diff --git a/docker/.gitignore b/docker/.gitignore index 772f5a9d9..5c73deb60 100644 --- a/docker/.gitignore +++ b/docker/.gitignore @@ -2,5 +2,5 @@ !.gitignore !install.sh !bin -!bin/swiftest_python +!bin/swiftest !bin/swiftest_driver diff --git a/docker/bin/swiftest b/docker/bin/swiftest new file mode 100755 index 000000000..8c985e065 --- /dev/null +++ b/docker/bin/swiftest @@ -0,0 +1,4 @@ +#!/bin/sh -- +OMP_NUM_THREADS=${OMP_NUM_THREADS:-`nproc --all`} +FOR_COARRAY_NUM_IMAGES=${FOR_COARRAY_NUM_IMAGES:-1} +docker run -v $(pwd):$(pwd) -w $(pwd) --user "$(id -u):$(id -g)" -ti -e OMP_NUM_THREADS -e FOR_COARRAY_NUM_IMAGES mintongroup/swiftest "$@" \ No newline at end of file diff --git a/docker/bin/swiftest_driver b/docker/bin/swiftest_driver index 0f7d8b5dd..146509c36 100755 --- a/docker/bin/swiftest_driver +++ b/docker/bin/swiftest_driver @@ -1,2 +1,4 @@ #!/bin/sh -- -docker run -v $(pwd):$(pwd) -w $(pwd) --user "$(id -u):$(id -g)" -ti --entrypoint /usr/local/bin/swiftest_driver -e OMP_NUM_THREADS -e FOR_COARRAY_NUM_IMAGES swiftest:1.0.0 "$@" \ No newline at end of file +OMP_NUM_THREADS=${OMP_NUM_THREADS:-`nproc --all`} +FOR_COARRAY_NUM_IMAGES=${FOR_COARRAY_NUM_IMAGES:-1} +docker run -v $(pwd):$(pwd) -w $(pwd) --user "$(id -u):$(id -g)" -ti --entrypoint /usr/local/bin/swiftest_driver -e OMP_NUM_THREADS -e FOR_COARRAY_NUM_IMAGES MintonGroup/swiftest "$@" \ No newline at end of file diff --git a/docker/bin/swiftest_python b/docker/bin/swiftest_python deleted file mode 100755 index fead7f338..000000000 --- a/docker/bin/swiftest_python +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -- -docker run -v $(pwd):$(pwd) -w $(pwd) --user "$(id -u):$(id -g)" -ti -e OMP_NUM_THREADS -e FOR_COARRAY_NUM_IMAGES swiftest:1.0.0 "$@" \ No newline at end of file diff --git a/docker/install.sh b/docker/install.sh index 1a0b2b20c..296223149 100755 --- a/docker/install.sh +++ b/docker/install.sh @@ -1,5 +1,6 @@ #!/bin/sh -- tag=${1:-latest} echo "Installing swiftest:${tag} Docker container and executable script" -docker pull daminton/swiftest:${tag} -cp -rf bin/swiftest ../bin/ \ No newline at end of file +docker pull mintongroup/swiftest:${tag} +cp -rf bin/swiftest ../bin/ +cp -rf bin/swiftest_driver ../bin/ \ No newline at end of file diff --git a/python/swiftest/swiftest/simulation_class.py b/python/swiftest/swiftest/simulation_class.py index 8971b897a..399ab0d38 100644 --- a/python/swiftest/swiftest/simulation_class.py +++ b/python/swiftest/swiftest/simulation_class.py @@ -470,6 +470,9 @@ def _type_scrub(output_data): sys.exit() except: warnings.warn(f"Error executing main swiftest_driver program", stacklevel=2) + res = p.communicate() + for line in res[1]: + print(line, end='') sys.exit() pbar.close() @@ -502,11 +505,9 @@ def run(self,dask: bool = False, **kwargs): if not self.binary_source.exists(): msg = "Path to swiftest_driver has not been set!" - msg += f"\nMake sure swiftest_driver is compiled and the executable is in {str(self.binary_path)}" + msg += f"\nMake sure swiftest_driver is compiled and the executable is in {str(self.binary_source.parent)}" warnings.warn(msg,stacklevel=2) return - else: - shutil.copy2(self.binary_source, self.driver_executable) if not self.restart: self.clean() @@ -942,16 +943,15 @@ def set_integrator(self, update_list.append("codename") if self.codename == "Swiftest": self.binary_source = Path(_pyfile).parent.parent.parent.parent / "bin" / "swiftest_driver" - self.binary_path = self.simdir.resolve() - self.driver_executable = self.binary_path / "swiftest_driver" + self.driver_executable = self.binary_source if not self.binary_source.exists(): - warnings.warn(f"Cannot find the Swiftest driver in {str(self.binary_path)}",stacklevel=2) + warnings.warn(f"Cannot find the Swiftest driver at {str(self.binary_source)}",stacklevel=2) self.driver_executable = None else: - if self.binary_path.exists(): + if self.binary_source.exists(): self.driver_executable.resolve() else: - self.binary_path = "NOT IMPLEMENTED FOR THIS CODE" + self.binary_source = "NOT IMPLEMENTED FOR THIS CODE" self.driver_executable = None update_list.append("driver_executable") @@ -1200,8 +1200,6 @@ def set_feature(self, msg = f"Cannot create the {self.simdir.resolve()} directory: File exists." msg += "\nDelete the file or change the location of param_file" raise NotADirectoryError(msg) - self.binary_path = self.simdir.resolve() - self.driver_executable = self.binary_path / "swiftest_driver" self.param_file = Path(kwargs.pop("param_file","param.in")) if self.codename == "Swiftest": @@ -2754,7 +2752,6 @@ def write_param(self, self.driver_script = os.path.join(self.simdir, "swiftest_driver.sh") with open(self.driver_script, 'w') as f: f.write(f"#{self._shell_full}\n") - #f.write(f"source ~/.{self._shell}rc\n") f.write(f"cd {self.simdir}\n") f.write(f"{str(self.driver_executable)} {self.integrator} {str(self.param_file)} compact\n") @@ -2991,11 +2988,9 @@ def save(self, self.write_param(param_file=param_file,**kwargs) if not self.binary_source.exists(): msg = "Path to swiftest_driver has not been set!" - msg += f"\nMake sure swiftest_driver is compiled and the executable is in {str(self.binary_path)}" + msg += f"\nMake sure swiftest_driver is compiled and the executable is in {str(self.binary_source.parent)}" warnings.warn(msg,stacklevel=2) return - else: - shutil.copy2(self.binary_source, self.driver_executable) elif codename == "Swifter": swifter_param = io.swiftest2swifter_param(param) if "rhill" in self.data: diff --git a/singularity/.gitignore b/singularity/.gitignore index 6ddbdba9f..b34dd2df5 100644 --- a/singularity/.gitignore +++ b/singularity/.gitignore @@ -2,4 +2,3 @@ !bin/swiftest_driver !bin/swiftest_python !install.sh -!setenv.sh diff --git a/singularity/bin/swiftest_driver b/singularity/bin/swiftest_driver index 03876195b..024e93115 100755 --- a/singularity/bin/swiftest_driver +++ b/singularity/bin/swiftest_driver @@ -1,2 +1,4 @@ #!/bin/sh -- +OMP_NUM_THREADS=${OMP_NUM_THREADS:-`nproc --all`} +FOR_COARRAY_NUM_IMAGES=${FOR_COARRAY_NUM_IMAGES:-1} singularity exec --bind $(pwd):$(pwd) --env OMP_NUM_THREADS=${OMP_NUM_THREADS},FOR_COARRAY_NUM_IMAGES=${FOR_COARRAY_NUM_IMAGES} ${SWIFTEST_SIF} swiftest_driver "$@" \ No newline at end of file diff --git a/singularity/bin/swiftest_python b/singularity/bin/swiftest_python deleted file mode 100755 index 2a7b13735..000000000 --- a/singularity/bin/swiftest_python +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -- -singularity run --bind $(pwd):$(pwd) --env OMP_NUM_THREADS=${OMP_NUM_THREADS},FOR_COARRAY_NUM_IMAGES=${FOR_COARRAY_NUM_IMAGES} ${SWIFTEST_SIF} "$@" \ No newline at end of file diff --git a/singularity/install.sh b/singularity/install.sh index e7c47e2b3..233ee187f 100755 --- a/singularity/install.sh +++ b/singularity/install.sh @@ -1,11 +1,21 @@ #!/bin/sh -- -# This will install the Singularity container version of the swiftest_driver in place of the native compiled version into ../bin. -# In order to use the executable script, the SWIFTEST_SIF environment variable must be set to point to the location of swiftest.sif, which requires this script to be called via source: -# $ . ./install.sh +# This will install the Singularity version of the swiftest_driver in place of the native compiled version into ../bin as +# well as the swiftest_python script that is used to execute a Python input file. +# The swiftest.sif file will be copied to the SIF_DIR directory. The default location is ${HOME}/.singularity. +# To change this, just set environment variable SIF_DIR prior to running this script. +# +# The script takes an optional argument "tag" if you want to pull a container other than "latest". # -tag=${1:-latest} -echo "Installing swiftest.sif Singularity container and executable script from swiftest:${tag} Docker container" -singularity pull --force swiftest.sif docker://daminton/swiftest:${tag} +# In order to use one executable script, the SWIFTEST_SIF environment variable must be set to point to the location of swiftest.sif, +# which requires this script to be called via source: +# $ source ./install.sh +# or +# $ . ./install.sh +TAG=${1:-latest} + +SIF_DIR=${SIF_DIR:-${HOME}/.singularity} +echo "Installing ${SIF_DIR}/swiftest.sif container from mintongroup/swiftest:${TAG} Docker container" +singularity pull --force ${SIF_DIR}/swiftest.sif docker://mintongroup/swiftest:${TAG} +cp -rf bin/swiftest ../bin/ cp -rf bin/swiftest_driver ../bin/ -cp -rf bin/swiftest_python ../bin/ -source ./setenv.sh \ No newline at end of file +export SWIFTEST_SIF=${SIF_DIR}/swiftest.sif \ No newline at end of file diff --git a/singularity/setenv.sh b/singularity/setenv.sh deleted file mode 100755 index d9f215d7c..000000000 --- a/singularity/setenv.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh -- -# This will set the SWIFTEST_SIF environment variable as long as it is executed by source. -# $ . ./setenv.sh -export SWIFTEST_SIF="${PWD}/swiftest.sif" \ No newline at end of file From 49e77a3cd714fe63c7ca67035c47b6b81f9924da Mon Sep 17 00:00:00 2001 From: David Minton Date: Wed, 7 Jun 2023 19:11:11 -0400 Subject: [PATCH 76/95] Added singularity swiftest script --- singularity/.gitignore | 2 +- singularity/bin/swiftest | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100755 singularity/bin/swiftest diff --git a/singularity/.gitignore b/singularity/.gitignore index b34dd2df5..baed94e88 100644 --- a/singularity/.gitignore +++ b/singularity/.gitignore @@ -1,4 +1,4 @@ !bin/ !bin/swiftest_driver -!bin/swiftest_python +!bin/swiftest !install.sh diff --git a/singularity/bin/swiftest b/singularity/bin/swiftest new file mode 100755 index 000000000..8a5849e51 --- /dev/null +++ b/singularity/bin/swiftest @@ -0,0 +1,4 @@ +#!/bin/sh -- +OMP_NUM_THREADS=${OMP_NUM_THREADS:-`nproc --all`} +FOR_COARRAY_NUM_IMAGES=${FOR_COARRAY_NUM_IMAGES:-1} +singularity run --bind $(pwd):$(pwd) --env OMP_NUM_THREADS=${OMP_NUM_THREADS},FOR_COARRAY_NUM_IMAGES=${FOR_COARRAY_NUM_IMAGES} ${SWIFTEST_SIF} "$@" \ No newline at end of file From afb2c9f036439711a9cdf003755c7b7d4e1077a1 Mon Sep 17 00:00:00 2001 From: David Minton Date: Wed, 7 Jun 2023 19:29:32 -0400 Subject: [PATCH 77/95] Added flags to ensure that host environment variables don't get passed down to the container in Apptainer/Singularity (which wreaks havoc on the RCAC cluster) --- apptainer/bin/swiftest | 2 +- singularity/bin/swiftest | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apptainer/bin/swiftest b/apptainer/bin/swiftest index ca0fcfadd..5d91b80d6 100755 --- a/apptainer/bin/swiftest +++ b/apptainer/bin/swiftest @@ -1,4 +1,4 @@ #!/bin/sh -- OMP_NUM_THREADS=${OMP_NUM_THREADS:-`nproc --all`} FOR_COARRAY_NUM_IMAGES=${FOR_COARRAY_NUM_IMAGES:-1} -apptainer run --bind $(pwd):$(pwd) --env OMP_NUM_THREADS=${OMP_NUM_THREADS},FOR_COARRAY_NUM_IMAGES=${FOR_COARRAY_NUM_IMAGES} ${SWIFTEST_SIF} "$@" \ No newline at end of file +apptainer run --bind $(pwd):$(pwd) --cleanenv --env OMP_NUM_THREADS=${OMP_NUM_THREADS},FOR_COARRAY_NUM_IMAGES=${FOR_COARRAY_NUM_IMAGES} ${SWIFTEST_SIF} "$@" \ No newline at end of file diff --git a/singularity/bin/swiftest b/singularity/bin/swiftest index 8a5849e51..a384860fe 100755 --- a/singularity/bin/swiftest +++ b/singularity/bin/swiftest @@ -1,4 +1,4 @@ #!/bin/sh -- OMP_NUM_THREADS=${OMP_NUM_THREADS:-`nproc --all`} FOR_COARRAY_NUM_IMAGES=${FOR_COARRAY_NUM_IMAGES:-1} -singularity run --bind $(pwd):$(pwd) --env OMP_NUM_THREADS=${OMP_NUM_THREADS},FOR_COARRAY_NUM_IMAGES=${FOR_COARRAY_NUM_IMAGES} ${SWIFTEST_SIF} "$@" \ No newline at end of file +singularity run --bind $(pwd):$(pwd) --cleanenv --env OMP_NUM_THREADS=${OMP_NUM_THREADS},FOR_COARRAY_NUM_IMAGES=${FOR_COARRAY_NUM_IMAGES} ${SWIFTEST_SIF} "$@" \ No newline at end of file From 1bd3846742e67358a47c171c712b00eda9c0a72d Mon Sep 17 00:00:00 2001 From: David Minton Date: Thu, 8 Jun 2023 09:06:13 -0400 Subject: [PATCH 78/95] Updated usage message to be more accurate. --- src/base/base_module.f90 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/base/base_module.f90 b/src/base/base_module.f90 index 502a42515..51266238f 100644 --- a/src/base/base_module.f90 +++ b/src/base/base_module.f90 @@ -600,8 +600,8 @@ subroutine base_util_exit(code) character(*), parameter :: BAR = '("------------------------------------------------")' character(*), parameter :: SUCCESS_MSG = '(/, "Normal termination of Swiftest (version ", f3.1, ")")' character(*), parameter :: FAIL_MSG = '(/, "Terminating Swiftest (version ", f3.1, ") due to error!!")' - character(*), parameter :: USAGE_MSG = '("Usage: swiftest [bs|helio|ra15|rmvs|symba|tu4|whm] ' // & - '[standard|compact|progress|NONE]")' + character(*), parameter :: USAGE_MSG = '("Usage: swiftest ' // & + '[{standard}|compact|progress]")' character(*), parameter :: HELP_MSG = USAGE_MSG select case(code) From 5e6a200839487c0e53d3d65f16f0ea12b0ad8acf Mon Sep 17 00:00:00 2001 From: David Minton Date: Thu, 8 Jun 2023 09:20:47 -0400 Subject: [PATCH 79/95] Added a Dockerfile just for the driver --- docker/.gitignore | 1 + docker/Dockerfile.swiftest_driver | 176 ++++++++++++++++++++++++++++++ 2 files changed, 177 insertions(+) create mode 100644 docker/Dockerfile.swiftest_driver diff --git a/docker/.gitignore b/docker/.gitignore index 5c73deb60..c876f8c26 100644 --- a/docker/.gitignore +++ b/docker/.gitignore @@ -4,3 +4,4 @@ !bin !bin/swiftest !bin/swiftest_driver +!Dockerfile.swiftest_driver diff --git a/docker/Dockerfile.swiftest_driver b/docker/Dockerfile.swiftest_driver new file mode 100644 index 000000000..8414f9016 --- /dev/null +++ b/docker/Dockerfile.swiftest_driver @@ -0,0 +1,176 @@ +FROM ubuntu:20.04 as build + +# kick everything off +RUN apt-get update && apt-get upgrade -y && \ + DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + ca-certificates curl git wget gpg-agent software-properties-common build-essential gnupg pkg-config && \ + rm -rf /var/lib/apt/lists/* && \ + mkdir -p cmake/build && \ + cd cmake/build && \ + curl -LO https://github.com/Kitware/CMake/releases/download/v3.26.2/cmake-3.26.2-linux-x86_64.sh && \ + /bin/bash cmake-3.26.2-linux-x86_64.sh --prefix=/usr/local --skip-license && \ + wget -O- https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB \ + | gpg --dearmor | tee /usr/share/keyrings/oneapi-archive-keyring.gpg > /dev/null && \ + echo "deb [signed-by=/usr/share/keyrings/oneapi-archive-keyring.gpg] https://apt.repos.intel.com/oneapi all main" | tee /etc/apt/sources.list.d/oneAPI.list && \ + apt-get -y update && apt-get upgrade -y && \ + apt-get install -y intel-hpckit + +# Set Intel compiler environment variables +ENV INTEL_DIR="/opt/intel/oneapi" +ENV LANG=C.UTF-8 +ENV ACL_BOARD_VENDOR_PATH='/opt/Intel/OpenCLFPGA/oneAPI/Boards' +ENV ADVISOR_2023_DIR='/opt/intel/oneapi/advisor/2023.1.0' +ENV APM='/opt/intel/oneapi/advisor/2023.1.0/perfmodels' +ENV CCL_CONFIGURATION='cpu_gpu_dpcpp' +ENV CCL_ROOT='/opt/intel/oneapi/ccl/2021.9.0' +ENV CLASSPATH='/opt/intel/oneapi/mpi/2021.9.0//lib/mpi.jar:/opt/intel/oneapi/dal/2023.1.0/lib/onedal.jar' +ENV CLCK_ROOT='/opt/intel/oneapi/clck/2021.7.3' +ENV CMAKE_PREFIX_PATH='/opt/intel/oneapi/tbb/2021.9.0/env/..:/opt/intel/oneapi/dnnl/2023.1.0/cpu_dpcpp_gpu_dpcpp/../lib/cmake:/opt/intel/oneapi/dal/2023.1.0:/opt/intel/oneapi/compiler/2023.1.0/linux/IntelDPCPP:/opt/intel/oneapi/ccl/2021.9.0/lib/cmake/oneCCL' +ENV CMPLR_ROOT='/opt/intel/oneapi/compiler/2023.1.0' +ENV CPATH='/opt/intel/oneapi/tbb/2021.9.0/env/../include:/opt/intel/oneapi/mpi/2021.9.0//include:/opt/intel/oneapi/mkl/2023.1.0/include:/opt/intel/oneapi/ippcp/2021.7.0/include:/opt/intel/oneapi/ipp/2021.8.0/include:/opt/intel/oneapi/dpl/2022.1.0/linux/include:/opt/intel/oneapi/dnnl/2023.1.0/cpu_dpcpp_gpu_dpcpp/include:/opt/intel/oneapi/dev-utilities/2021.9.0/include:/opt/intel/oneapi/dal/2023.1.0/include:/opt/intel/oneapi/ccl/2021.9.0/include/cpu_gpu_dpcpp' +ENV CPLUS_INCLUDE_PATH='/opt/intel/oneapi/clck/2021.7.3/include' +ENV DAALROOT='/opt/intel/oneapi/dal/2023.1.0' +ENV DALROOT='/opt/intel/oneapi/dal/2023.1.0' +ENV DAL_MAJOR_BINARY='1' +ENV DAL_MINOR_BINARY='1' +ENV DIAGUTIL_PATH='/opt/intel/oneapi/vtune/2023.1.0/sys_check/vtune_sys_check.py:/opt/intel/oneapi/debugger/2023.1.0/sys_check/debugger_sys_check.py:/opt/intel/oneapi/compiler/2023.1.0/sys_check/sys_check.sh:/opt/intel/oneapi/advisor/2023.1.0/sys_check/advisor_sys_check.py:' +ENV DNNLROOT='/opt/intel/oneapi/dnnl/2023.1.0/cpu_dpcpp_gpu_dpcpp' +ENV DPL_ROOT='/opt/intel/oneapi/dpl/2022.1.0' +ENV FI_PROVIDER_PATH='/opt/intel/oneapi/mpi/2021.9.0//libfabric/lib/prov:/usr/lib64/libfabric' +ENV FPGA_VARS_ARGS='' +ENV FPGA_VARS_DIR='/opt/intel/oneapi/compiler/2023.1.0/linux/lib/oclfpga' +ENV GDB_INFO='/opt/intel/oneapi/debugger/2023.1.0/documentation/info/' +ENV INFOPATH='/opt/intel/oneapi/debugger/2023.1.0/gdb/intel64/lib' +ENV INSPECTOR_2023_DIR='/opt/intel/oneapi/inspector/2023.1.0' +ENV INTELFPGAOCLSDKROOT='/opt/intel/oneapi/compiler/2023.1.0/linux/lib/oclfpga' +ENV INTEL_LICENSE_FILE='/opt/intel/licenses:/root/intel/licenses:/opt/intel/oneapi/clck/2021.7.3/licensing:/opt/intel/licenses:/root/intel/licenses:/Users/Shared/Library/Application Support/Intel/Licenses' +ENV INTEL_PYTHONHOME='/opt/intel/oneapi/debugger/2023.1.0/dep' +ENV IPPCP_TARGET_ARCH='intel64' +ENV IPPCRYPTOROOT='/opt/intel/oneapi/ippcp/2021.7.0' +ENV IPPROOT='/opt/intel/oneapi/ipp/2021.8.0' +ENV IPP_TARGET_ARCH='intel64' +ENV I_MPI_ROOT='/opt/intel/oneapi/mpi/2021.9.0' +ENV LD_LIBRARY_PATH='/opt/intel/oneapi/tbb/2021.9.0/env/../lib/intel64/gcc4.8:/opt/intel/oneapi/mpi/2021.9.0//libfabric/lib:/opt/intel/oneapi/mpi/2021.9.0//lib/release:/opt/intel/oneapi/mpi/2021.9.0//lib:/opt/intel/oneapi/mkl/2023.1.0/lib/intel64:/opt/intel/oneapi/itac/2021.9.0/slib:/opt/intel/oneapi/ippcp/2021.7.0/lib/intel64:/opt/intel/oneapi/ipp/2021.8.0/lib/intel64:/opt/intel/oneapi/dnnl/2023.1.0/cpu_dpcpp_gpu_dpcpp/lib:/opt/intel/oneapi/debugger/2023.1.0/gdb/intel64/lib:/opt/intel/oneapi/debugger/2023.1.0/libipt/intel64/lib:/opt/intel/oneapi/debugger/2023.1.0/dep/lib:/opt/intel/oneapi/dal/2023.1.0/lib/intel64:/opt/intel/oneapi/compiler/2023.1.0/linux/lib:/opt/intel/oneapi/compiler/2023.1.0/linux/lib/x64:/opt/intel/oneapi/compiler/2023.1.0/linux/lib/oclfpga/host/linux64/lib:/opt/intel/oneapi/compiler/2023.1.0/linux/compiler/lib/intel64_lin:/opt/intel/oneapi/ccl/2021.9.0/lib/cpu_gpu_dpcpp' +ENV LIBRARY_PATH='/opt/intel/oneapi/tbb/2021.9.0/env/../lib/intel64/gcc4.8:/opt/intel/oneapi/mpi/2021.9.0//libfabric/lib:/opt/intel/oneapi/mpi/2021.9.0//lib/release:/opt/intel/oneapi/mpi/2021.9.0//lib:/opt/intel/oneapi/mkl/2023.1.0/lib/intel64:/opt/intel/oneapi/ippcp/2021.7.0/lib/intel64:/opt/intel/oneapi/ipp/2021.8.0/lib/intel64:/opt/intel/oneapi/dnnl/2023.1.0/cpu_dpcpp_gpu_dpcpp/lib:/opt/intel/oneapi/dal/2023.1.0/lib/intel64:/opt/intel/oneapi/compiler/2023.1.0/linux/compiler/lib/intel64_lin:/opt/intel/oneapi/compiler/2023.1.0/linux/lib:/opt/intel/oneapi/clck/2021.7.3/lib/intel64:/opt/intel/oneapi/ccl/2021.9.0/lib/cpu_gpu_dpcpp' +ENV MANPATH='/opt/intel/oneapi/mpi/2021.9.0/man:/opt/intel/oneapi/itac/2021.9.0/man:/opt/intel/oneapi/debugger/2023.1.0/documentation/man:/opt/intel/oneapi/compiler/2023.1.0/documentation/en/man/common:/opt/intel/oneapi/clck/2021.7.3/man::' +ENV MKLROOT='/opt/intel/oneapi/mkl/2023.1.0' +ENV NLSPATH='/opt/intel/oneapi/mkl/2023.1.0/lib/intel64/locale/%l_%t/%N:/opt/intel/oneapi/compiler/2023.1.0/linux/compiler/lib/intel64_lin/locale/%l_%t/%N' +ENV OCL_ICD_FILENAMES='libintelocl_emu.so:libalteracl.so:/opt/intel/oneapi/compiler/2023.1.0/linux/lib/x64/libintelocl.so' +ENV ONEAPI_ROOT='/opt/intel/oneapi' +ENV PATH='/opt/intel/oneapi/vtune/2023.1.0/bin64:/opt/intel/oneapi/mpi/2021.9.0//libfabric/bin:/opt/intel/oneapi/mpi/2021.9.0//bin:/opt/intel/oneapi/mkl/2023.1.0/bin/intel64:/opt/intel/oneapi/itac/2021.9.0/bin:/opt/intel/oneapi/inspector/2023.1.0/bin64:/opt/intel/oneapi/dev-utilities/2021.9.0/bin:/opt/intel/oneapi/debugger/2023.1.0/gdb/intel64/bin:/opt/intel/oneapi/compiler/2023.1.0/linux/lib/oclfpga/bin:/opt/intel/oneapi/compiler/2023.1.0/linux/bin/intel64:/opt/intel/oneapi/compiler/2023.1.0/linux/bin:/opt/intel/oneapi/clck/2021.7.3/bin/intel64:/opt/intel/oneapi/advisor/2023.1.0/bin64:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin' +ENV PKG_CONFIG_PATH='/opt/intel/oneapi/vtune/2023.1.0/include/pkgconfig/lib64:/opt/intel/oneapi/tbb/2021.9.0/env/../lib/pkgconfig:/opt/intel/oneapi/mpi/2021.9.0/lib/pkgconfig:/opt/intel/oneapi/mkl/2023.1.0/lib/pkgconfig:/opt/intel/oneapi/ippcp/2021.7.0/lib/pkgconfig:/opt/intel/oneapi/inspector/2023.1.0/include/pkgconfig/lib64:/opt/intel/oneapi/dpl/2022.1.0/lib/pkgconfig:/opt/intel/oneapi/dnnl/2023.1.0/cpu_dpcpp_gpu_dpcpp/../lib/pkgconfig:/opt/intel/oneapi/dal/2023.1.0/lib/pkgconfig:/opt/intel/oneapi/compiler/2023.1.0/lib/pkgconfig:/opt/intel/oneapi/ccl/2021.9.0/lib/pkgconfig:/opt/intel/oneapi/advisor/2023.1.0/include/pkgconfig/lib64:' +ENV PYTHONPATH='/opt/intel/oneapi/advisor/2023.1.0/pythonapi' +ENV SETVARS_COMPLETED='1' +ENV TBBROOT='/opt/intel/oneapi/tbb/2021.9.0/env/..' +ENV VTUNE_PROFILER_2023_DIR='/opt/intel/oneapi/vtune/2023.1.0' +ENV VTUNE_PROFILER_DIR='/opt/intel/oneapi/vtune/2023.1.0' +ENV VT_ADD_LIBS='-ldwarf -lelf -lvtunwind -lm -lpthread' +ENV VT_LIB_DIR='/opt/intel/oneapi/itac/2021.9.0/lib' +ENV VT_MPI='impi4' +ENV VT_ROOT='/opt/intel/oneapi/itac/2021.9.0' +ENV VT_SLIB_DIR='/opt/intel/oneapi/itac/2021.9.0/slib' + +# Set HDF5 and NetCDF-specific Environment variables +ENV INSTALL_DIR="/usr/local" +ENV LIB_DIR="${INSTALL_DIR}/lib" +ENV LD_LIBRARY_PATH=${LIB_DIR}:${LD_LIBRARY_PATH} +RUN mkdir -p ${LIB_DIR} + +ENV CC="${INTEL_DIR}/compiler/latest/linux/bin/icx-cc" +ENV FC="${INTEL_DIR}/compiler/latest/linux/bin/ifx" +ENV CXX="${INTEL_DIR}/compiler/latest/linux/bin/icpx" +ENV LDFLAGS="-L${LIB_DIR}" +ENV NCDIR="${INSTALL_DIR}" +ENV NFDIR="${INSTALL_DIR}" +ENV HDF5_ROOT="${INSTALL_DIR}" +ENV HDF5_LIBDIR="${HDF5_ROOT}/lib" +ENV HDF5_INCLUDE_DIR="${HDF5_ROOT}/include" +ENV HDF5_PLUGIN_PATH="${HDF5_LIBDIR}/plugin" + +# Get the HDF5, NetCDF-C and NetCDF-Fortran libraries +RUN wget -qO- https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.14/hdf5-1.14.1/bin/unix/hdf5-1.14.1-2-Std-ubuntu2004_64-Intel.tar.gz | tar xvz && \ + wget -qO- https://github.com/Unidata/netcdf-c/archive/refs/tags/v4.9.2.tar.gz | tar xvz && \ + wget -qO- https://github.com/Unidata/netcdf-fortran/archive/refs/tags/v4.6.1.tar.gz | tar xvz && \ + wget -qO- https://www.zlib.net/zlib-1.2.13.tar.gz | tar xvz && \ + apt-get update && apt-get upgrade -y && \ + DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + libxml2-dev libcurl4-gnutls-dev libzstd-dev libbz2-dev libaec-dev m4 && \ + rm -rf /var/lib/apt/lists/* && \ + cd hdf && \ + ./HDF5-1.14.1-Linux.sh --skip-license && \ + cp -R HDF_Group/HDF5/1.14.1/lib/*.a ${HDF5_ROOT}/lib/ && \ + cp -R HDF_Group/HDF5/1.14.1/include/* ${HDF5_ROOT}/include/ && \ + cp /zlib-1.2.13/zlib.h ${HDF5_INCLUDE_DIR}/ + +ENV LD_LIBRARY_PATH="/lib/x86_64-linux-gnu:${LD_LIBRARY_PATH}" +ENV LDFLAGS="-static-intel -lhdf5_hl -lhdf5 -lsz -lm -lz -lzstd -lbz2 -lcurl -lxml2" +RUN cd netcdf-c-4.9.2 && \ + cmake -S . -B build -DCMAKE_PREFIX_PATH="${INSTALL_DIR}" \ + -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} \ + -DCMAKE_POSITION_INDEPENDENT_CODE=ON \ + -DBUILD_SHARED_LIBS=OFF && \ + cmake --build build && \ + cmake --install build + +# NetCDF-Fortran library +ENV F77=${FC} +ENV CFLAGS="-fPIC" +ENV FCFLAGS="${CFLAGS} -standard-semantics" +ENV FFLAGS=${CFLAGS} +ENV CPPFLAGS="-I${INSTALL_DIR}/include -I/usr/include -I/usr/include/x86_64-linux-gnu/curl" +ENV LDFLAGS="-static-intel" +ENV LIBS="-L/usr/local/lib -L/usr/lib/x86_64-linux-gnu -lnetcdf -lhdf5_hl -lhdf5 -lsz -lm -lz -lzstd -lbz2 -lcurl -lxml2" +RUN cd netcdf-fortran-4.6.1 && \ + ./configure --disable-shared --prefix=${NFDIR} && \ + make && \ + make install + +# Swiftest +ENV NETCDF_HOME=${INSTALL_DIR} +ENV NETCDF_FORTRAN_HOME=${NETCDF_HOME} +ENV NETCDF_LIBRARY=${NETCDF_HOME} +ENV FOR_COARRAY_NUM_IMAGES=1 +ENV OMP_NUM_THREADS=1 +ENV FC="${INTEL_DIR}/mpi/latest/bin/mpiifort" +ENV FFLAGS="-fPIC -standard-semantics" +ENV LDFLAGS="-L/usr/local/lib -L/usr/lib/x86_64-linux-gnu -lnetcdff -lnetcdf -lhdf5_hl -lhdf5 -lsz -lz -lzstd -lbz2 -lcurl -lxml2" +COPY ./cmake/ /swiftest/cmake/ +COPY ./src/ /swiftest/src/ +COPY ./CMakeLists.txt /swiftest/ +RUN echo 'find_path(NETCDF_INCLUDE_DIR NAMES netcdf.mod HINTS ENV NETCDF_FORTRAN_HOME)\n' \ + 'find_library(NETCDF_FORTRAN_LIBRARY NAMES netcdff HINTS ENV LD_LIBRARY_PATH)\n' \ + 'find_library(NETCDF_LIBRARY NAMES netcdf HINTS ENV LD_LIBRARY_PATH)\n' \ + 'find_library(HDF5_HL_LIBRARY NAMES libhdf5_hl.a HINTS ENV LD_LIBRARY_PATH)\n' \ + 'find_library(HDF5_LIBRARY NAMES libhdf5.a HINTS ENV LD_LIBRARY_PATH)\n' \ + 'find_library(Z_LIBRARY NAMES libz.a HINTS ENV LD_LIBRARY_PATH)\n' \ + 'find_library(ZSTD_LIBRARY NAMES libzstd.a HINTS ENV LD_LIBRARY_PATH)\n' \ + 'find_library(SZ_LIBRARY NAMES libsz.a HINTS ENV LD_LIBRARY_PATH)\n' \ + 'find_library(BZ2_LIBRARY NAMES libbz2.a HINTS ENV LD_LIBRARY_PATH)\n' \ + 'find_library(CURL_LIBRARY NAMES libcurl.a HINTS ENV LD_LIBRARY_PATH)\n' \ + 'find_library(XML2_LIBRARY NAMES libxml2.a HINTS ENV LD_LIBRARY_PATH)\n' \ + 'set(NETCDF_FOUND TRUE)\n' \ + 'set(NETCDF_INCLUDE_DIRS ${NETCDF_INCLUDE_DIR})\n' \ + 'set(NETCDF_LIBRARIES ${NETCDF_FORTRAN_LIBRARY} ${NETCDF_LIBRARY} ${HDF5_HL_LIBRARY} ${HDF5_LIBRARY} ${SZ_LIBRARY} ${Z_LIBRARY} ${ZSTD_LIBRARY} ${BZ2_LIBRARY} ${CURL_LIBRARY} ${XML2_LIBRARY} )\n' \ + 'mark_as_advanced(NETCDF_LIBRARY NETCDF_FORTRAN_LIBRARY NETCDF_INCLUDE_DIR)\n' > /swiftest/cmake/Modules/FindNETCDF.cmake && \ + cd swiftest && \ + cmake -S . -B build -DCMAKE_INSTALL_PREFIX="${INSTALL_DIR}" -DCONTAINERIZE=ON -DUSE_COARRAY=OFF -DCMAKE_BUILD_TYPE=RELEASE -DBUILD_SHARED_LIBS=OFF &&\ + cmake --build build && \ + cmake --install build + +# Production container +FROM ubuntu:20.04 + +RUN apt-get update && apt-get upgrade -y && \ + DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + libsz2 libcurl3-gnutls libxml2 && \ + rm -rf /var/lib/apt/lists/* + +COPY --from=build /usr/local/bin/swiftest_driver /usr/local/bin/ +# COPY --from=build /usr/local/bin/swiftest_driver_caf /usr/local/bin/ +COPY --from=build /opt/intel/oneapi/compiler/2023.1.0/linux/compiler/lib/intel64_lin/libicaf.so /usr/local/lib/ +COPY --from=build /opt/intel/oneapi/mpi/2021.9.0//lib/release/libmpi.so.12 /usr/local/lib/ +COPY --from=build /opt/intel/oneapi/compiler/2023.1.0/linux/compiler/lib/intel64_lin/libintlc.so.5 /usr/local/lib/ +COPY --from=build /opt/intel/oneapi/mpi/latest/bin/mpiexec.hydra /usr/local/bin/ + + +ENTRYPOINT ["/usr/local/bin/swiftest_driver"] \ No newline at end of file From bfe55af08d47bb1f602a71e01f1f2e01e9fab818 Mon Sep 17 00:00:00 2001 From: David Minton Date: Fri, 9 Jun 2023 17:16:06 -0400 Subject: [PATCH 80/95] Made a clean, streamlined Dockerfile that contains almost no dependencies in the end. It can also spit out the binary executables so it could be used as a build tool rather than running from inside the container --- CMakeLists.txt | 8 - Dockerfile | 241 +++++++++++----------------- cmake/Modules/SetFortranFlags.cmake | 52 +++--- docker/Dockerfile.swiftest_driver | 197 +++++++---------------- src/CMakeLists.txt | 2 +- 5 files changed, 173 insertions(+), 327 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 08ec7c9e2..961683f3e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,13 +34,6 @@ OPTION(USE_SIMD "Use SIMD vectorization" ON) OPTION(CONTAINERIZE "Compiling for use in a Docker/Singularity container" OFF) OPTION(BUILD_SHARED_LIBS "Build using shared libraries" ON) -# Locate and set external libraries. There are some CMake peculiarities -# taken care of here, such as the fact that the FindOpenMP routine doesn't know -# about Fortran. -IF (NOT BUILD_SHARED_LIBS) - set(CMAKE_FIND_LIBRARY_SUFFIXES ".a" ".so") -ENDIF () - INCLUDE(${CMAKE_MODULE_PATH}/SetParallelizationLibrary.cmake) INCLUDE(${CMAKE_MODULE_PATH}/SetUpNetCDF.cmake) INCLUDE(${CMAKE_MODULE_PATH}/SetMKL.cmake) @@ -51,7 +44,6 @@ INCLUDE(${CMAKE_MODULE_PATH}/SetFortranFlags.cmake) INCLUDE_DIRECTORIES($ENV{NETCDF_FORTRAN_HOME}/include;$ENV{NETCDF_HOME}/include) - # There is an error in CMAKE with this flag for pgf90. Unset it GET_FILENAME_COMPONENT(FCNAME ${CMAKE_Fortran_COMPILER} NAME) IF(FCNAME STREQUAL "pgf90") diff --git a/Dockerfile b/Dockerfile index b53f8dc8c..33c82f700 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,85 +1,73 @@ -FROM ubuntu:20.04 as build - -# kick everything off -RUN apt-get update && apt-get upgrade -y && \ - DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ - ca-certificates curl git wget gpg-agent software-properties-common build-essential gnupg pkg-config && \ - rm -rf /var/lib/apt/lists/* && \ - mkdir -p cmake/build && \ - cd cmake/build && \ - curl -LO https://github.com/Kitware/CMake/releases/download/v3.26.2/cmake-3.26.2-linux-x86_64.sh && \ - /bin/bash cmake-3.26.2-linux-x86_64.sh --prefix=/usr/local --skip-license && \ - wget -O- https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB \ - | gpg --dearmor | tee /usr/share/keyrings/oneapi-archive-keyring.gpg > /dev/null && \ - echo "deb [signed-by=/usr/share/keyrings/oneapi-archive-keyring.gpg] https://apt.repos.intel.com/oneapi all main" | tee /etc/apt/sources.list.d/oneAPI.list && \ - apt-get -y update && apt-get upgrade -y && \ - apt-get install -y intel-hpckit - -# Set Intel compiler environment variables -ENV INTEL_DIR="/opt/intel/oneapi" -ENV LANG=C.UTF-8 -ENV ACL_BOARD_VENDOR_PATH='/opt/Intel/OpenCLFPGA/oneAPI/Boards' -ENV ADVISOR_2023_DIR='/opt/intel/oneapi/advisor/2023.1.0' -ENV APM='/opt/intel/oneapi/advisor/2023.1.0/perfmodels' -ENV CCL_CONFIGURATION='cpu_gpu_dpcpp' -ENV CCL_ROOT='/opt/intel/oneapi/ccl/2021.9.0' -ENV CLASSPATH='/opt/intel/oneapi/mpi/2021.9.0//lib/mpi.jar:/opt/intel/oneapi/dal/2023.1.0/lib/onedal.jar' -ENV CLCK_ROOT='/opt/intel/oneapi/clck/2021.7.3' -ENV CMAKE_PREFIX_PATH='/opt/intel/oneapi/tbb/2021.9.0/env/..:/opt/intel/oneapi/dnnl/2023.1.0/cpu_dpcpp_gpu_dpcpp/../lib/cmake:/opt/intel/oneapi/dal/2023.1.0:/opt/intel/oneapi/compiler/2023.1.0/linux/IntelDPCPP:/opt/intel/oneapi/ccl/2021.9.0/lib/cmake/oneCCL' -ENV CMPLR_ROOT='/opt/intel/oneapi/compiler/2023.1.0' -ENV CPATH='/opt/intel/oneapi/tbb/2021.9.0/env/../include:/opt/intel/oneapi/mpi/2021.9.0//include:/opt/intel/oneapi/mkl/2023.1.0/include:/opt/intel/oneapi/ippcp/2021.7.0/include:/opt/intel/oneapi/ipp/2021.8.0/include:/opt/intel/oneapi/dpl/2022.1.0/linux/include:/opt/intel/oneapi/dnnl/2023.1.0/cpu_dpcpp_gpu_dpcpp/include:/opt/intel/oneapi/dev-utilities/2021.9.0/include:/opt/intel/oneapi/dal/2023.1.0/include:/opt/intel/oneapi/ccl/2021.9.0/include/cpu_gpu_dpcpp' -ENV CPLUS_INCLUDE_PATH='/opt/intel/oneapi/clck/2021.7.3/include' -ENV DAALROOT='/opt/intel/oneapi/dal/2023.1.0' -ENV DALROOT='/opt/intel/oneapi/dal/2023.1.0' -ENV DAL_MAJOR_BINARY='1' -ENV DAL_MINOR_BINARY='1' -ENV DIAGUTIL_PATH='/opt/intel/oneapi/vtune/2023.1.0/sys_check/vtune_sys_check.py:/opt/intel/oneapi/debugger/2023.1.0/sys_check/debugger_sys_check.py:/opt/intel/oneapi/compiler/2023.1.0/sys_check/sys_check.sh:/opt/intel/oneapi/advisor/2023.1.0/sys_check/advisor_sys_check.py:' -ENV DNNLROOT='/opt/intel/oneapi/dnnl/2023.1.0/cpu_dpcpp_gpu_dpcpp' -ENV DPL_ROOT='/opt/intel/oneapi/dpl/2022.1.0' -ENV FI_PROVIDER_PATH='/opt/intel/oneapi/mpi/2021.9.0//libfabric/lib/prov:/usr/lib64/libfabric' -ENV FPGA_VARS_ARGS='' -ENV FPGA_VARS_DIR='/opt/intel/oneapi/compiler/2023.1.0/linux/lib/oclfpga' -ENV GDB_INFO='/opt/intel/oneapi/debugger/2023.1.0/documentation/info/' -ENV INFOPATH='/opt/intel/oneapi/debugger/2023.1.0/gdb/intel64/lib' -ENV INSPECTOR_2023_DIR='/opt/intel/oneapi/inspector/2023.1.0' -ENV INTELFPGAOCLSDKROOT='/opt/intel/oneapi/compiler/2023.1.0/linux/lib/oclfpga' -ENV INTEL_LICENSE_FILE='/opt/intel/licenses:/root/intel/licenses:/opt/intel/oneapi/clck/2021.7.3/licensing:/opt/intel/licenses:/root/intel/licenses:/Users/Shared/Library/Application Support/Intel/Licenses' -ENV INTEL_PYTHONHOME='/opt/intel/oneapi/debugger/2023.1.0/dep' -ENV IPPCP_TARGET_ARCH='intel64' -ENV IPPCRYPTOROOT='/opt/intel/oneapi/ippcp/2021.7.0' -ENV IPPROOT='/opt/intel/oneapi/ipp/2021.8.0' -ENV IPP_TARGET_ARCH='intel64' -ENV I_MPI_ROOT='/opt/intel/oneapi/mpi/2021.9.0' -ENV LD_LIBRARY_PATH='/opt/intel/oneapi/tbb/2021.9.0/env/../lib/intel64/gcc4.8:/opt/intel/oneapi/mpi/2021.9.0//libfabric/lib:/opt/intel/oneapi/mpi/2021.9.0//lib/release:/opt/intel/oneapi/mpi/2021.9.0//lib:/opt/intel/oneapi/mkl/2023.1.0/lib/intel64:/opt/intel/oneapi/itac/2021.9.0/slib:/opt/intel/oneapi/ippcp/2021.7.0/lib/intel64:/opt/intel/oneapi/ipp/2021.8.0/lib/intel64:/opt/intel/oneapi/dnnl/2023.1.0/cpu_dpcpp_gpu_dpcpp/lib:/opt/intel/oneapi/debugger/2023.1.0/gdb/intel64/lib:/opt/intel/oneapi/debugger/2023.1.0/libipt/intel64/lib:/opt/intel/oneapi/debugger/2023.1.0/dep/lib:/opt/intel/oneapi/dal/2023.1.0/lib/intel64:/opt/intel/oneapi/compiler/2023.1.0/linux/lib:/opt/intel/oneapi/compiler/2023.1.0/linux/lib/x64:/opt/intel/oneapi/compiler/2023.1.0/linux/lib/oclfpga/host/linux64/lib:/opt/intel/oneapi/compiler/2023.1.0/linux/compiler/lib/intel64_lin:/opt/intel/oneapi/ccl/2021.9.0/lib/cpu_gpu_dpcpp' -ENV LIBRARY_PATH='/opt/intel/oneapi/tbb/2021.9.0/env/../lib/intel64/gcc4.8:/opt/intel/oneapi/mpi/2021.9.0//libfabric/lib:/opt/intel/oneapi/mpi/2021.9.0//lib/release:/opt/intel/oneapi/mpi/2021.9.0//lib:/opt/intel/oneapi/mkl/2023.1.0/lib/intel64:/opt/intel/oneapi/ippcp/2021.7.0/lib/intel64:/opt/intel/oneapi/ipp/2021.8.0/lib/intel64:/opt/intel/oneapi/dnnl/2023.1.0/cpu_dpcpp_gpu_dpcpp/lib:/opt/intel/oneapi/dal/2023.1.0/lib/intel64:/opt/intel/oneapi/compiler/2023.1.0/linux/compiler/lib/intel64_lin:/opt/intel/oneapi/compiler/2023.1.0/linux/lib:/opt/intel/oneapi/clck/2021.7.3/lib/intel64:/opt/intel/oneapi/ccl/2021.9.0/lib/cpu_gpu_dpcpp' -ENV MANPATH='/opt/intel/oneapi/mpi/2021.9.0/man:/opt/intel/oneapi/itac/2021.9.0/man:/opt/intel/oneapi/debugger/2023.1.0/documentation/man:/opt/intel/oneapi/compiler/2023.1.0/documentation/en/man/common:/opt/intel/oneapi/clck/2021.7.3/man::' -ENV MKLROOT='/opt/intel/oneapi/mkl/2023.1.0' -ENV NLSPATH='/opt/intel/oneapi/mkl/2023.1.0/lib/intel64/locale/%l_%t/%N:/opt/intel/oneapi/compiler/2023.1.0/linux/compiler/lib/intel64_lin/locale/%l_%t/%N' -ENV OCL_ICD_FILENAMES='libintelocl_emu.so:libalteracl.so:/opt/intel/oneapi/compiler/2023.1.0/linux/lib/x64/libintelocl.so' -ENV ONEAPI_ROOT='/opt/intel/oneapi' -ENV PATH='/opt/intel/oneapi/vtune/2023.1.0/bin64:/opt/intel/oneapi/mpi/2021.9.0//libfabric/bin:/opt/intel/oneapi/mpi/2021.9.0//bin:/opt/intel/oneapi/mkl/2023.1.0/bin/intel64:/opt/intel/oneapi/itac/2021.9.0/bin:/opt/intel/oneapi/inspector/2023.1.0/bin64:/opt/intel/oneapi/dev-utilities/2021.9.0/bin:/opt/intel/oneapi/debugger/2023.1.0/gdb/intel64/bin:/opt/intel/oneapi/compiler/2023.1.0/linux/lib/oclfpga/bin:/opt/intel/oneapi/compiler/2023.1.0/linux/bin/intel64:/opt/intel/oneapi/compiler/2023.1.0/linux/bin:/opt/intel/oneapi/clck/2021.7.3/bin/intel64:/opt/intel/oneapi/advisor/2023.1.0/bin64:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin' -ENV PKG_CONFIG_PATH='/opt/intel/oneapi/vtune/2023.1.0/include/pkgconfig/lib64:/opt/intel/oneapi/tbb/2021.9.0/env/../lib/pkgconfig:/opt/intel/oneapi/mpi/2021.9.0/lib/pkgconfig:/opt/intel/oneapi/mkl/2023.1.0/lib/pkgconfig:/opt/intel/oneapi/ippcp/2021.7.0/lib/pkgconfig:/opt/intel/oneapi/inspector/2023.1.0/include/pkgconfig/lib64:/opt/intel/oneapi/dpl/2022.1.0/lib/pkgconfig:/opt/intel/oneapi/dnnl/2023.1.0/cpu_dpcpp_gpu_dpcpp/../lib/pkgconfig:/opt/intel/oneapi/dal/2023.1.0/lib/pkgconfig:/opt/intel/oneapi/compiler/2023.1.0/lib/pkgconfig:/opt/intel/oneapi/ccl/2021.9.0/lib/pkgconfig:/opt/intel/oneapi/advisor/2023.1.0/include/pkgconfig/lib64:' -ENV PYTHONPATH='/opt/intel/oneapi/advisor/2023.1.0/pythonapi' -ENV SETVARS_COMPLETED='1' -ENV TBBROOT='/opt/intel/oneapi/tbb/2021.9.0/env/..' -ENV VTUNE_PROFILER_2023_DIR='/opt/intel/oneapi/vtune/2023.1.0' -ENV VTUNE_PROFILER_DIR='/opt/intel/oneapi/vtune/2023.1.0' -ENV VT_ADD_LIBS='-ldwarf -lelf -lvtunwind -lm -lpthread' -ENV VT_LIB_DIR='/opt/intel/oneapi/itac/2021.9.0/lib' -ENV VT_MPI='impi4' -ENV VT_ROOT='/opt/intel/oneapi/itac/2021.9.0' -ENV VT_SLIB_DIR='/opt/intel/oneapi/itac/2021.9.0/slib' - -# Set HDF5 and NetCDF-specific Environment variables +# Copyright 2023 - David Minton +# This file is part of Swiftest. +# Swiftest is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. +# Swiftest is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty +# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# You should have received a copy of the GNU General Public License along with Swiftest. +# If not, see: https://www.gnu.org/licenses. +# +# This Dockerfile will build the Swiftest driver program with minimal external dependencies using the Intel Oneapi toolkit. +# This is done by building static versions of a minimal set of libraries that NetCDF-Fortran needs (Netcdf-C, HDF5, and Zlib). +# These, along with the Intel runtime libraries, are linked statically to the executable. Only the OS-specific libraries are linked +# dynamically. + +# This build target compiles all dependencies and the swiftest driver itself +FROM intel/oneapi-hpckit:2023.1.0-devel-ubuntu22.04 as build + +# The MACHINE_CODE_VALUE argument is a string that is used when compiling the swiftest_driver. It is appended to the "-x" compiler +# option: (-x${MACHINE_CODE_VALUE}). The default value is set to "sse2" which allows for certain SIMD instructions to be used while +# remaining # compatible with a wide range of CPUs. To get the highest performance, you can pass "host" as an argument, but the +# compiled binary # would only run on a CPU with an architecture compatible with the one that the build was performed on. +# For more details and other options, see: +# https://www.intel.com/content/www/us/en/docs/fortran-compiler/developer-guide-reference/2023-1/x-qx.html +ARG MACHINE_CODE_VALUE="sse2" + +# Build type options are DEBUG, RELEASE, PROFILE, or TESTING. +ARG BUILD_TYPE="RELEASE" + ENV INSTALL_DIR="/usr/local" -ENV LIB_DIR="${INSTALL_DIR}/lib" -ENV LD_LIBRARY_PATH=${LIB_DIR}:${LD_LIBRARY_PATH} -RUN mkdir -p ${LIB_DIR} - -ENV CC="${INTEL_DIR}/compiler/latest/linux/bin/icx-cc" -ENV FC="${INTEL_DIR}/compiler/latest/linux/bin/ifx" -ENV CXX="${INTEL_DIR}/compiler/latest/linux/bin/icpx" -ENV LDFLAGS="-L${LIB_DIR}" +ENV CC="${ONEAPI_ROOT}/compiler/latest/linux/bin/icx" +ENV FC="${ONEAPI_ROOT}/compiler/latest/linux/bin/ifx" +ENV CXX="${ONEAPI_ROOT}/compiler/latest/linux/bin/icpx" +ENV F77="${FC}" + +# Get the HDF5, NetCDF-C, and NetCDF-Fortran libraries +RUN wget -qO- https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.14/hdf5-1.14.1/src/hdf5-1.14.1-2.tar.gz | tar xvz && \ + wget -qO- https://github.com/Unidata/netcdf-c/archive/refs/tags/v4.9.2.tar.gz | tar xvz && \ + wget -qO- https://github.com/Unidata/netcdf-fortran/archive/refs/tags/v4.6.1.tar.gz | tar xvz && \ + wget -qO- https://www.zlib.net/zlib-1.2.13.tar.gz | tar xvz + +RUN apt-get update && \ + DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + m4 && \ + rm -rf /var/lib/apt/lists/* + +RUN cd zlib-1.2.13 && \ + ./configure --prefix=${INSTALL_DIR} --static && \ + make && \ + make install + +RUN cd hdf5-1.14.1-2 && \ + ./configure --disable-shared \ + --enable-build-mode=production \ + --disable-fortran \ + --disable-java \ + --disable-cxx \ + --prefix=${INSTALL_DIR} \ + --with-zlib=${INSTALL_DIR} && \ + make && \ + make install + +RUN cd netcdf-c-4.9.2 && \ + ./configure --disable-shared \ + --disable-dap \ + --disable-libxml2 \ + --disable-byterange \ + --prefix=${INSTALL_DIR} && \ + make && \ + make install + ENV NCDIR="${INSTALL_DIR}" ENV NFDIR="${INSTALL_DIR}" ENV HDF5_ROOT="${INSTALL_DIR}" @@ -87,39 +75,12 @@ ENV HDF5_LIBDIR="${HDF5_ROOT}/lib" ENV HDF5_INCLUDE_DIR="${HDF5_ROOT}/include" ENV HDF5_PLUGIN_PATH="${HDF5_LIBDIR}/plugin" -# Get the HDF5, NetCDF-C and NetCDF-Fortran libraries -RUN wget -qO- https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.14/hdf5-1.14.1/bin/unix/hdf5-1.14.1-2-Std-ubuntu2004_64-Intel.tar.gz | tar xvz && \ - wget -qO- https://github.com/Unidata/netcdf-c/archive/refs/tags/v4.9.2.tar.gz | tar xvz && \ - wget -qO- https://github.com/Unidata/netcdf-fortran/archive/refs/tags/v4.6.1.tar.gz | tar xvz && \ - wget -qO- https://www.zlib.net/zlib-1.2.13.tar.gz | tar xvz && \ - apt-get update && apt-get upgrade -y && \ - DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ - libxml2-dev libcurl4-gnutls-dev libzstd-dev libbz2-dev libaec-dev m4 && \ - rm -rf /var/lib/apt/lists/* && \ - cd hdf && \ - ./HDF5-1.14.1-Linux.sh --skip-license && \ - cp -R HDF_Group/HDF5/1.14.1/lib/*.a ${HDF5_ROOT}/lib/ && \ - cp -R HDF_Group/HDF5/1.14.1/include/* ${HDF5_ROOT}/include/ && \ - cp /zlib-1.2.13/zlib.h ${HDF5_INCLUDE_DIR}/ - -ENV LD_LIBRARY_PATH="/lib/x86_64-linux-gnu:${LD_LIBRARY_PATH}" -ENV LDFLAGS="-static-intel -lhdf5_hl -lhdf5 -lsz -lm -lz -lzstd -lbz2 -lcurl -lxml2" -RUN cd netcdf-c-4.9.2 && \ - cmake -S . -B build -DCMAKE_PREFIX_PATH="${INSTALL_DIR}" \ - -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} \ - -DCMAKE_POSITION_INDEPENDENT_CODE=ON \ - -DBUILD_SHARED_LIBS=OFF && \ - cmake --build build && \ - cmake --install build - # NetCDF-Fortran library -ENV F77=${FC} ENV CFLAGS="-fPIC" ENV FCFLAGS="${CFLAGS} -standard-semantics" ENV FFLAGS=${CFLAGS} -ENV CPPFLAGS="-I${INSTALL_DIR}/include -I/usr/include -I/usr/include/x86_64-linux-gnu/curl" -ENV LDFLAGS="-static-intel" -ENV LIBS="-L/usr/local/lib -L/usr/lib/x86_64-linux-gnu -lnetcdf -lhdf5_hl -lhdf5 -lsz -lm -lz -lzstd -lbz2 -lcurl -lxml2" +ENV CPPFLAGS="-I${INSTALL_DIR}/include" +ENV LIBS="-L/usr/local/lib -L/usr/lib/x86_64-linux-gnu -lnetcdf -lhdf5_hl -lhdf5 -lm -lz" RUN cd netcdf-fortran-4.6.1 && \ ./configure --disable-shared --prefix=${NFDIR} && \ make && \ @@ -131,38 +92,34 @@ ENV NETCDF_FORTRAN_HOME=${NETCDF_HOME} ENV NETCDF_LIBRARY=${NETCDF_HOME} ENV FOR_COARRAY_NUM_IMAGES=1 ENV OMP_NUM_THREADS=1 -ENV FC="${INTEL_DIR}/mpi/latest/bin/mpiifort" +ENV FC="${ONEAPI_ROOT}/mpi/latest/bin/mpiifort" ENV FFLAGS="-fPIC -standard-semantics" -ENV LDFLAGS="-L/usr/local/lib -L/usr/lib/x86_64-linux-gnu -lnetcdff -lnetcdf -lhdf5_hl -lhdf5 -lsz -lz -lzstd -lbz2 -lcurl -lxml2" +ENV LDFLAGS="-L/usr/local/lib" +ENV LIBS="-lhdf5_hl -lhdf5 -lz" COPY ./cmake/ /swiftest/cmake/ COPY ./src/ /swiftest/src/ COPY ./CMakeLists.txt /swiftest/ -RUN echo 'find_path(NETCDF_INCLUDE_DIR NAMES netcdf.mod HINTS ENV NETCDF_FORTRAN_HOME)\n' \ - 'find_library(NETCDF_FORTRAN_LIBRARY NAMES netcdff HINTS ENV LD_LIBRARY_PATH)\n' \ - 'find_library(NETCDF_LIBRARY NAMES netcdf HINTS ENV LD_LIBRARY_PATH)\n' \ - 'find_library(HDF5_HL_LIBRARY NAMES libhdf5_hl.a HINTS ENV LD_LIBRARY_PATH)\n' \ - 'find_library(HDF5_LIBRARY NAMES libhdf5.a HINTS ENV LD_LIBRARY_PATH)\n' \ - 'find_library(Z_LIBRARY NAMES libz.a HINTS ENV LD_LIBRARY_PATH)\n' \ - 'find_library(ZSTD_LIBRARY NAMES libzstd.a HINTS ENV LD_LIBRARY_PATH)\n' \ - 'find_library(SZ_LIBRARY NAMES libsz.a HINTS ENV LD_LIBRARY_PATH)\n' \ - 'find_library(BZ2_LIBRARY NAMES libbz2.a HINTS ENV LD_LIBRARY_PATH)\n' \ - 'find_library(CURL_LIBRARY NAMES libcurl.a HINTS ENV LD_LIBRARY_PATH)\n' \ - 'find_library(XML2_LIBRARY NAMES libxml2.a HINTS ENV LD_LIBRARY_PATH)\n' \ - 'set(NETCDF_FOUND TRUE)\n' \ - 'set(NETCDF_INCLUDE_DIRS ${NETCDF_INCLUDE_DIR})\n' \ - 'set(NETCDF_LIBRARIES ${NETCDF_FORTRAN_LIBRARY} ${NETCDF_LIBRARY} ${HDF5_HL_LIBRARY} ${HDF5_LIBRARY} ${SZ_LIBRARY} ${Z_LIBRARY} ${ZSTD_LIBRARY} ${BZ2_LIBRARY} ${CURL_LIBRARY} ${XML2_LIBRARY} )\n' \ - 'mark_as_advanced(NETCDF_LIBRARY NETCDF_FORTRAN_LIBRARY NETCDF_INCLUDE_DIR)\n' > /swiftest/cmake/Modules/FindNETCDF.cmake && \ - cd swiftest && \ - cmake -S . -B build -DCMAKE_INSTALL_PREFIX="${INSTALL_DIR}" -DCONTAINERIZE=ON -DUSE_COARRAY=ON -DCMAKE_BUILD_TYPE=RELEASE -DBUILD_SHARED_LIBS=OFF &&\ - cmake --build build && \ - cp bin/swiftest_driver /usr/local/bin/swiftest_driver_caf && \ - rm -rf build && \ - cmake -S . -B build -DCMAKE_INSTALL_PREFIX="${INSTALL_DIR}" -DCONTAINERIZE=ON -DUSE_COARRAY=OFF -DCMAKE_BUILD_TYPE=RELEASE -DBUILD_SHARED_LIBS=OFF &&\ +RUN cd swiftest && \ + cmake -S . -B build -DCMAKE_INSTALL_PREFIX="${INSTALL_DIR}" \ + -DMACHINE_CODE_VALUE=${MACHINE_CODE} \ + -DCMAKE_BUILD_TYPE=${BUILD_TYPE} \ + -DUSE_COARRAY=OFF \ + -DBUILD_SHARED_LIBS=OFF && \ cmake --build build && \ cmake --install build -# Production container -FROM continuumio/miniconda3 +# This build target creates a container that executes just the driver program +FROM ubuntu:22.04 as driver +COPY --from=build /usr/local/bin/swiftest_driver /usr/local/bin/ +ENTRYPOINT ["/usr/local/bin/swiftest_driver"] + +# This build target exports the binary to the host +FROM scratch AS export_driver +COPY --from=build /usr/local/bin/swiftest_driver / + +# This build target creates a container with a conda environment with all dependencies needed to run the Python front end and +# analysis tools +FROM continuumio/miniconda3 as python SHELL ["/bin/bash", "--login", "-c"] ENV SHELL="/bin/bash" ENV PATH="/opt/conda/bin:${PATH}" @@ -170,11 +127,7 @@ ENV LD_LIBRARY_PATH="/usr/local/lib" COPY environment.yml . -RUN apt-get update && apt-get upgrade -y && \ - DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ - libsz2 libcurl3-gnutls libxml2 && \ - rm -rf /var/lib/apt/lists/* && \ - conda update --all -y && \ +RUN conda update --all -y && \ conda install conda-libmamba-solver -y && \ conda config --set solver libmamba && \ conda env create -f environment.yml && \ @@ -183,12 +136,6 @@ RUN apt-get update && apt-get upgrade -y && \ COPY ./python/. /opt/conda/pkgs/ COPY --from=build /usr/local/bin/swiftest_driver /opt/conda/envs/swiftest-env/bin/ -COPY --from=build /usr/local/bin/swiftest_driver /opt/conda/bin/ -COPY --from=build /usr/local/bin/swiftest_driver_caf /opt/conda/envs/swiftest-env/bin/ -COPY --from=build /opt/intel/oneapi/compiler/2023.1.0/linux/compiler/lib/intel64_lin/libicaf.so /opt/conda/envs/swiftest-env/lib/ -COPY --from=build /opt/intel/oneapi/mpi/2021.9.0//lib/release/libmpi.so.12 /opt/conda/envs/swiftest-env/lib/ -COPY --from=build /opt/intel/oneapi/compiler/2023.1.0/linux/compiler/lib/intel64_lin/libintlc.so.5 /opt/conda/envs/swiftest-env/lib/ -COPY --from=build /opt/intel/oneapi/mpi/latest/bin/mpiexec.hydra /opt/conda/envs/swiftest-env/bin/ # Start new shell to activate the environment and install Swiftest RUN cd /opt/conda/pkgs/swiftest && conda develop . && \ @@ -199,6 +146,6 @@ RUN cd /opt/conda/pkgs/swiftest && conda develop . && \ mkdir -p /.config/matplotlib && \ chmod -R 777 /.cache/matplotlib && \ chmod -R 777 /.config/matplotlib && \ - ln -s /opt/conda/bin/swiftest_driver /opt/conda/bin/driver + ln -s /opt/conda/envs/swiftest-env/bin/swiftest_driver /opt/conda/bin/driver ENTRYPOINT ["conda", "run", "--no-capture-output", "-n", "swiftest-env"] \ No newline at end of file diff --git a/cmake/Modules/SetFortranFlags.cmake b/cmake/Modules/SetFortranFlags.cmake index 47361de08..4c8cc9b85 100644 --- a/cmake/Modules/SetFortranFlags.cmake +++ b/cmake/Modules/SetFortranFlags.cmake @@ -46,6 +46,16 @@ ELSE() MESSAGE(FATAL_ERROR "CMAKE_BUILD_TYPE not valid! ${BUILD_TYPE_MSG}") ENDIF(BT STREQUAL "RELEASE") +IF (CMAKE_Fortran_COMPILER_ID STREQUAL "GNU") + IF (APPLE) + SET(MACHINE_CODE_VALUE "tune=native" CACHE STRING "Tells the compiler which processor features it may target, including which instruction sets and optimizations it may generate.") + ELSE () + SET(MACHINE_CODE_VALUE "arch=native" CACHE STRING "Tells the compiler which processor features it may target, including which instruction sets and optimizations it may generate.") + ENDIF () +ELSE () + SET(MACHINE_CODE_VALUE "host" CACHE STRING "Tells the compiler which processor features it may target, including which instruction sets and optimizations it may generate.") +ENDIF () + ######################################################### # If the compiler flags have already been set, return now ######################################################### @@ -105,14 +115,7 @@ SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}" ) -IF (CONTAINERIZE) - # There is some bug where -march=native doesn't work on Mac - IF(APPLE) - SET(GNUNATIVE "-mtune=generic") - ELSE() - SET(GNUNATIVE "-march=generic") - ENDIF() - +IF (NOT BUILD_SHARED_LIBS) # Use static Intel libraries SET_COMPILE_FLAG(CMAKE_Fortran_LINK_FLAGS "${CMAKE_Fortran_LINK_FLAGS}" Fortran "-static-intel" # Intel @@ -127,17 +130,7 @@ IF (CONTAINERIZE) Fortran "-qopenmp-link=static" # Intel ) ENDIF (USE_OPENMP) - -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) - - +ENDIF () IF (USE_SIMD) # Enables OpenMP SIMD compilation when OpenMP parallelization is disabled. @@ -148,21 +141,12 @@ IF (USE_SIMD) ) 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 "-xSSE2" # Intel - "/QxSSE2" # 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) + # Optimize for an old enough processor that it should run on most computers + SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}" + Fortran "-x${MACHINE_CODE_VALUE}" # Intel + "/Qx${MACHINE_CODE_VALUE}" # Intel Windows + "-m${MACHINE_CODE_VALUE}" # GNU + ) # Generate an extended set of vector functions SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}" diff --git a/docker/Dockerfile.swiftest_driver b/docker/Dockerfile.swiftest_driver index 8414f9016..08480c058 100644 --- a/docker/Dockerfile.swiftest_driver +++ b/docker/Dockerfile.swiftest_driver @@ -1,85 +1,60 @@ -FROM ubuntu:20.04 as build +# Copyright 2023 - David Minton +# This file is part of Swiftest. +# Swiftest is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. +# Swiftest is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty +# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# You should have received a copy of the GNU General Public License along with Swiftest. +# If not, see: https://www.gnu.org/licenses. +# +# This Dockerfile will build the Swiftest driver program with minimal external dependencies using the Intel Oneapi toolkit. +# This is done by building static versions of a minimal set of libraries that NetCDF-Fortran needs (Netcdf-C, HDF5, and Zlib). +# These, along with the Intel runtime libraries, are linked statically to the executable. Only the OS-specific libraries are linked +# dynamically. +FROM intel/oneapi-hpckit:2023.1.0-devel-ubuntu20.04 as build -# kick everything off -RUN apt-get update && apt-get upgrade -y && \ - DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ - ca-certificates curl git wget gpg-agent software-properties-common build-essential gnupg pkg-config && \ - rm -rf /var/lib/apt/lists/* && \ - mkdir -p cmake/build && \ - cd cmake/build && \ - curl -LO https://github.com/Kitware/CMake/releases/download/v3.26.2/cmake-3.26.2-linux-x86_64.sh && \ - /bin/bash cmake-3.26.2-linux-x86_64.sh --prefix=/usr/local --skip-license && \ - wget -O- https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB \ - | gpg --dearmor | tee /usr/share/keyrings/oneapi-archive-keyring.gpg > /dev/null && \ - echo "deb [signed-by=/usr/share/keyrings/oneapi-archive-keyring.gpg] https://apt.repos.intel.com/oneapi all main" | tee /etc/apt/sources.list.d/oneAPI.list && \ - apt-get -y update && apt-get upgrade -y && \ - apt-get install -y intel-hpckit +ENV INSTALL_DIR="/usr/local" +ENV CC="${ONEAPI_ROOT}/compiler/latest/linux/bin/icx" +ENV FC="${ONEAPI_ROOT}/compiler/latest/linux/bin/ifx" +ENV CXX="${ONEAPI_ROOT}/compiler/latest/linux/bin/icpx" +ENV F77="${FC}" -# Set Intel compiler environment variables -ENV INTEL_DIR="/opt/intel/oneapi" -ENV LANG=C.UTF-8 -ENV ACL_BOARD_VENDOR_PATH='/opt/Intel/OpenCLFPGA/oneAPI/Boards' -ENV ADVISOR_2023_DIR='/opt/intel/oneapi/advisor/2023.1.0' -ENV APM='/opt/intel/oneapi/advisor/2023.1.0/perfmodels' -ENV CCL_CONFIGURATION='cpu_gpu_dpcpp' -ENV CCL_ROOT='/opt/intel/oneapi/ccl/2021.9.0' -ENV CLASSPATH='/opt/intel/oneapi/mpi/2021.9.0//lib/mpi.jar:/opt/intel/oneapi/dal/2023.1.0/lib/onedal.jar' -ENV CLCK_ROOT='/opt/intel/oneapi/clck/2021.7.3' -ENV CMAKE_PREFIX_PATH='/opt/intel/oneapi/tbb/2021.9.0/env/..:/opt/intel/oneapi/dnnl/2023.1.0/cpu_dpcpp_gpu_dpcpp/../lib/cmake:/opt/intel/oneapi/dal/2023.1.0:/opt/intel/oneapi/compiler/2023.1.0/linux/IntelDPCPP:/opt/intel/oneapi/ccl/2021.9.0/lib/cmake/oneCCL' -ENV CMPLR_ROOT='/opt/intel/oneapi/compiler/2023.1.0' -ENV CPATH='/opt/intel/oneapi/tbb/2021.9.0/env/../include:/opt/intel/oneapi/mpi/2021.9.0//include:/opt/intel/oneapi/mkl/2023.1.0/include:/opt/intel/oneapi/ippcp/2021.7.0/include:/opt/intel/oneapi/ipp/2021.8.0/include:/opt/intel/oneapi/dpl/2022.1.0/linux/include:/opt/intel/oneapi/dnnl/2023.1.0/cpu_dpcpp_gpu_dpcpp/include:/opt/intel/oneapi/dev-utilities/2021.9.0/include:/opt/intel/oneapi/dal/2023.1.0/include:/opt/intel/oneapi/ccl/2021.9.0/include/cpu_gpu_dpcpp' -ENV CPLUS_INCLUDE_PATH='/opt/intel/oneapi/clck/2021.7.3/include' -ENV DAALROOT='/opt/intel/oneapi/dal/2023.1.0' -ENV DALROOT='/opt/intel/oneapi/dal/2023.1.0' -ENV DAL_MAJOR_BINARY='1' -ENV DAL_MINOR_BINARY='1' -ENV DIAGUTIL_PATH='/opt/intel/oneapi/vtune/2023.1.0/sys_check/vtune_sys_check.py:/opt/intel/oneapi/debugger/2023.1.0/sys_check/debugger_sys_check.py:/opt/intel/oneapi/compiler/2023.1.0/sys_check/sys_check.sh:/opt/intel/oneapi/advisor/2023.1.0/sys_check/advisor_sys_check.py:' -ENV DNNLROOT='/opt/intel/oneapi/dnnl/2023.1.0/cpu_dpcpp_gpu_dpcpp' -ENV DPL_ROOT='/opt/intel/oneapi/dpl/2022.1.0' -ENV FI_PROVIDER_PATH='/opt/intel/oneapi/mpi/2021.9.0//libfabric/lib/prov:/usr/lib64/libfabric' -ENV FPGA_VARS_ARGS='' -ENV FPGA_VARS_DIR='/opt/intel/oneapi/compiler/2023.1.0/linux/lib/oclfpga' -ENV GDB_INFO='/opt/intel/oneapi/debugger/2023.1.0/documentation/info/' -ENV INFOPATH='/opt/intel/oneapi/debugger/2023.1.0/gdb/intel64/lib' -ENV INSPECTOR_2023_DIR='/opt/intel/oneapi/inspector/2023.1.0' -ENV INTELFPGAOCLSDKROOT='/opt/intel/oneapi/compiler/2023.1.0/linux/lib/oclfpga' -ENV INTEL_LICENSE_FILE='/opt/intel/licenses:/root/intel/licenses:/opt/intel/oneapi/clck/2021.7.3/licensing:/opt/intel/licenses:/root/intel/licenses:/Users/Shared/Library/Application Support/Intel/Licenses' -ENV INTEL_PYTHONHOME='/opt/intel/oneapi/debugger/2023.1.0/dep' -ENV IPPCP_TARGET_ARCH='intel64' -ENV IPPCRYPTOROOT='/opt/intel/oneapi/ippcp/2021.7.0' -ENV IPPROOT='/opt/intel/oneapi/ipp/2021.8.0' -ENV IPP_TARGET_ARCH='intel64' -ENV I_MPI_ROOT='/opt/intel/oneapi/mpi/2021.9.0' -ENV LD_LIBRARY_PATH='/opt/intel/oneapi/tbb/2021.9.0/env/../lib/intel64/gcc4.8:/opt/intel/oneapi/mpi/2021.9.0//libfabric/lib:/opt/intel/oneapi/mpi/2021.9.0//lib/release:/opt/intel/oneapi/mpi/2021.9.0//lib:/opt/intel/oneapi/mkl/2023.1.0/lib/intel64:/opt/intel/oneapi/itac/2021.9.0/slib:/opt/intel/oneapi/ippcp/2021.7.0/lib/intel64:/opt/intel/oneapi/ipp/2021.8.0/lib/intel64:/opt/intel/oneapi/dnnl/2023.1.0/cpu_dpcpp_gpu_dpcpp/lib:/opt/intel/oneapi/debugger/2023.1.0/gdb/intel64/lib:/opt/intel/oneapi/debugger/2023.1.0/libipt/intel64/lib:/opt/intel/oneapi/debugger/2023.1.0/dep/lib:/opt/intel/oneapi/dal/2023.1.0/lib/intel64:/opt/intel/oneapi/compiler/2023.1.0/linux/lib:/opt/intel/oneapi/compiler/2023.1.0/linux/lib/x64:/opt/intel/oneapi/compiler/2023.1.0/linux/lib/oclfpga/host/linux64/lib:/opt/intel/oneapi/compiler/2023.1.0/linux/compiler/lib/intel64_lin:/opt/intel/oneapi/ccl/2021.9.0/lib/cpu_gpu_dpcpp' -ENV LIBRARY_PATH='/opt/intel/oneapi/tbb/2021.9.0/env/../lib/intel64/gcc4.8:/opt/intel/oneapi/mpi/2021.9.0//libfabric/lib:/opt/intel/oneapi/mpi/2021.9.0//lib/release:/opt/intel/oneapi/mpi/2021.9.0//lib:/opt/intel/oneapi/mkl/2023.1.0/lib/intel64:/opt/intel/oneapi/ippcp/2021.7.0/lib/intel64:/opt/intel/oneapi/ipp/2021.8.0/lib/intel64:/opt/intel/oneapi/dnnl/2023.1.0/cpu_dpcpp_gpu_dpcpp/lib:/opt/intel/oneapi/dal/2023.1.0/lib/intel64:/opt/intel/oneapi/compiler/2023.1.0/linux/compiler/lib/intel64_lin:/opt/intel/oneapi/compiler/2023.1.0/linux/lib:/opt/intel/oneapi/clck/2021.7.3/lib/intel64:/opt/intel/oneapi/ccl/2021.9.0/lib/cpu_gpu_dpcpp' -ENV MANPATH='/opt/intel/oneapi/mpi/2021.9.0/man:/opt/intel/oneapi/itac/2021.9.0/man:/opt/intel/oneapi/debugger/2023.1.0/documentation/man:/opt/intel/oneapi/compiler/2023.1.0/documentation/en/man/common:/opt/intel/oneapi/clck/2021.7.3/man::' -ENV MKLROOT='/opt/intel/oneapi/mkl/2023.1.0' -ENV NLSPATH='/opt/intel/oneapi/mkl/2023.1.0/lib/intel64/locale/%l_%t/%N:/opt/intel/oneapi/compiler/2023.1.0/linux/compiler/lib/intel64_lin/locale/%l_%t/%N' -ENV OCL_ICD_FILENAMES='libintelocl_emu.so:libalteracl.so:/opt/intel/oneapi/compiler/2023.1.0/linux/lib/x64/libintelocl.so' -ENV ONEAPI_ROOT='/opt/intel/oneapi' -ENV PATH='/opt/intel/oneapi/vtune/2023.1.0/bin64:/opt/intel/oneapi/mpi/2021.9.0//libfabric/bin:/opt/intel/oneapi/mpi/2021.9.0//bin:/opt/intel/oneapi/mkl/2023.1.0/bin/intel64:/opt/intel/oneapi/itac/2021.9.0/bin:/opt/intel/oneapi/inspector/2023.1.0/bin64:/opt/intel/oneapi/dev-utilities/2021.9.0/bin:/opt/intel/oneapi/debugger/2023.1.0/gdb/intel64/bin:/opt/intel/oneapi/compiler/2023.1.0/linux/lib/oclfpga/bin:/opt/intel/oneapi/compiler/2023.1.0/linux/bin/intel64:/opt/intel/oneapi/compiler/2023.1.0/linux/bin:/opt/intel/oneapi/clck/2021.7.3/bin/intel64:/opt/intel/oneapi/advisor/2023.1.0/bin64:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin' -ENV PKG_CONFIG_PATH='/opt/intel/oneapi/vtune/2023.1.0/include/pkgconfig/lib64:/opt/intel/oneapi/tbb/2021.9.0/env/../lib/pkgconfig:/opt/intel/oneapi/mpi/2021.9.0/lib/pkgconfig:/opt/intel/oneapi/mkl/2023.1.0/lib/pkgconfig:/opt/intel/oneapi/ippcp/2021.7.0/lib/pkgconfig:/opt/intel/oneapi/inspector/2023.1.0/include/pkgconfig/lib64:/opt/intel/oneapi/dpl/2022.1.0/lib/pkgconfig:/opt/intel/oneapi/dnnl/2023.1.0/cpu_dpcpp_gpu_dpcpp/../lib/pkgconfig:/opt/intel/oneapi/dal/2023.1.0/lib/pkgconfig:/opt/intel/oneapi/compiler/2023.1.0/lib/pkgconfig:/opt/intel/oneapi/ccl/2021.9.0/lib/pkgconfig:/opt/intel/oneapi/advisor/2023.1.0/include/pkgconfig/lib64:' -ENV PYTHONPATH='/opt/intel/oneapi/advisor/2023.1.0/pythonapi' -ENV SETVARS_COMPLETED='1' -ENV TBBROOT='/opt/intel/oneapi/tbb/2021.9.0/env/..' -ENV VTUNE_PROFILER_2023_DIR='/opt/intel/oneapi/vtune/2023.1.0' -ENV VTUNE_PROFILER_DIR='/opt/intel/oneapi/vtune/2023.1.0' -ENV VT_ADD_LIBS='-ldwarf -lelf -lvtunwind -lm -lpthread' -ENV VT_LIB_DIR='/opt/intel/oneapi/itac/2021.9.0/lib' -ENV VT_MPI='impi4' -ENV VT_ROOT='/opt/intel/oneapi/itac/2021.9.0' -ENV VT_SLIB_DIR='/opt/intel/oneapi/itac/2021.9.0/slib' +# Get the HDF5, NetCDF-C, and NetCDF-Fortran libraries +RUN wget -qO- https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.14/hdf5-1.14.1/src/hdf5-1.14.1-2.tar.gz | tar xvz && \ + wget -qO- https://github.com/Unidata/netcdf-c/archive/refs/tags/v4.9.2.tar.gz | tar xvz && \ + wget -qO- https://github.com/Unidata/netcdf-fortran/archive/refs/tags/v4.6.1.tar.gz | tar xvz && \ + wget -qO- https://www.zlib.net/zlib-1.2.13.tar.gz | tar xvz -# Set HDF5 and NetCDF-specific Environment variables -ENV INSTALL_DIR="/usr/local" -ENV LIB_DIR="${INSTALL_DIR}/lib" -ENV LD_LIBRARY_PATH=${LIB_DIR}:${LD_LIBRARY_PATH} -RUN mkdir -p ${LIB_DIR} +RUN apt-get update && \ + DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + m4 && \ + rm -rf /var/lib/apt/lists/* + +RUN cd zlib-1.2.13 && \ + ./configure --prefix=${INSTALL_DIR} --static && \ + make && \ + make install + +RUN cd hdf5-1.14.1-2 && \ + ./configure --disable-shared \ + --enable-build-mode=production \ + --disable-fortran \ + --disable-java \ + --disable-cxx \ + --prefix=${INSTALL_DIR} \ + --with-zlib=${INSTALL_DIR} && \ + make && \ + make install + +RUN cd netcdf-c-4.9.2 && \ + ./configure --disable-shared \ + --disable-dap \ + --disable-libxml2 \ + --disable-byterange \ + --prefix=${INSTALL_DIR} && \ + make && \ + make install -ENV CC="${INTEL_DIR}/compiler/latest/linux/bin/icx-cc" -ENV FC="${INTEL_DIR}/compiler/latest/linux/bin/ifx" -ENV CXX="${INTEL_DIR}/compiler/latest/linux/bin/icpx" -ENV LDFLAGS="-L${LIB_DIR}" ENV NCDIR="${INSTALL_DIR}" ENV NFDIR="${INSTALL_DIR}" ENV HDF5_ROOT="${INSTALL_DIR}" @@ -87,39 +62,12 @@ ENV HDF5_LIBDIR="${HDF5_ROOT}/lib" ENV HDF5_INCLUDE_DIR="${HDF5_ROOT}/include" ENV HDF5_PLUGIN_PATH="${HDF5_LIBDIR}/plugin" -# Get the HDF5, NetCDF-C and NetCDF-Fortran libraries -RUN wget -qO- https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.14/hdf5-1.14.1/bin/unix/hdf5-1.14.1-2-Std-ubuntu2004_64-Intel.tar.gz | tar xvz && \ - wget -qO- https://github.com/Unidata/netcdf-c/archive/refs/tags/v4.9.2.tar.gz | tar xvz && \ - wget -qO- https://github.com/Unidata/netcdf-fortran/archive/refs/tags/v4.6.1.tar.gz | tar xvz && \ - wget -qO- https://www.zlib.net/zlib-1.2.13.tar.gz | tar xvz && \ - apt-get update && apt-get upgrade -y && \ - DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ - libxml2-dev libcurl4-gnutls-dev libzstd-dev libbz2-dev libaec-dev m4 && \ - rm -rf /var/lib/apt/lists/* && \ - cd hdf && \ - ./HDF5-1.14.1-Linux.sh --skip-license && \ - cp -R HDF_Group/HDF5/1.14.1/lib/*.a ${HDF5_ROOT}/lib/ && \ - cp -R HDF_Group/HDF5/1.14.1/include/* ${HDF5_ROOT}/include/ && \ - cp /zlib-1.2.13/zlib.h ${HDF5_INCLUDE_DIR}/ - -ENV LD_LIBRARY_PATH="/lib/x86_64-linux-gnu:${LD_LIBRARY_PATH}" -ENV LDFLAGS="-static-intel -lhdf5_hl -lhdf5 -lsz -lm -lz -lzstd -lbz2 -lcurl -lxml2" -RUN cd netcdf-c-4.9.2 && \ - cmake -S . -B build -DCMAKE_PREFIX_PATH="${INSTALL_DIR}" \ - -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} \ - -DCMAKE_POSITION_INDEPENDENT_CODE=ON \ - -DBUILD_SHARED_LIBS=OFF && \ - cmake --build build && \ - cmake --install build - # NetCDF-Fortran library -ENV F77=${FC} ENV CFLAGS="-fPIC" ENV FCFLAGS="${CFLAGS} -standard-semantics" ENV FFLAGS=${CFLAGS} -ENV CPPFLAGS="-I${INSTALL_DIR}/include -I/usr/include -I/usr/include/x86_64-linux-gnu/curl" -ENV LDFLAGS="-static-intel" -ENV LIBS="-L/usr/local/lib -L/usr/lib/x86_64-linux-gnu -lnetcdf -lhdf5_hl -lhdf5 -lsz -lm -lz -lzstd -lbz2 -lcurl -lxml2" +ENV CPPFLAGS="-I${INSTALL_DIR}/include" +ENV LIBS="-L/usr/local/lib -L/usr/lib/x86_64-linux-gnu -lnetcdf -lhdf5_hl -lhdf5 -lm -lz" RUN cd netcdf-fortran-4.6.1 && \ ./configure --disable-shared --prefix=${NFDIR} && \ make && \ @@ -131,46 +79,21 @@ ENV NETCDF_FORTRAN_HOME=${NETCDF_HOME} ENV NETCDF_LIBRARY=${NETCDF_HOME} ENV FOR_COARRAY_NUM_IMAGES=1 ENV OMP_NUM_THREADS=1 -ENV FC="${INTEL_DIR}/mpi/latest/bin/mpiifort" +ENV FC="${ONEAPI_ROOT}/mpi/latest/bin/mpiifort" ENV FFLAGS="-fPIC -standard-semantics" -ENV LDFLAGS="-L/usr/local/lib -L/usr/lib/x86_64-linux-gnu -lnetcdff -lnetcdf -lhdf5_hl -lhdf5 -lsz -lz -lzstd -lbz2 -lcurl -lxml2" +ENV LDFLAGS="-L/usr/local/lib" +ENV LIBS="-lhdf5_hl -lhdf5 -lz" COPY ./cmake/ /swiftest/cmake/ COPY ./src/ /swiftest/src/ COPY ./CMakeLists.txt /swiftest/ -RUN echo 'find_path(NETCDF_INCLUDE_DIR NAMES netcdf.mod HINTS ENV NETCDF_FORTRAN_HOME)\n' \ - 'find_library(NETCDF_FORTRAN_LIBRARY NAMES netcdff HINTS ENV LD_LIBRARY_PATH)\n' \ - 'find_library(NETCDF_LIBRARY NAMES netcdf HINTS ENV LD_LIBRARY_PATH)\n' \ - 'find_library(HDF5_HL_LIBRARY NAMES libhdf5_hl.a HINTS ENV LD_LIBRARY_PATH)\n' \ - 'find_library(HDF5_LIBRARY NAMES libhdf5.a HINTS ENV LD_LIBRARY_PATH)\n' \ - 'find_library(Z_LIBRARY NAMES libz.a HINTS ENV LD_LIBRARY_PATH)\n' \ - 'find_library(ZSTD_LIBRARY NAMES libzstd.a HINTS ENV LD_LIBRARY_PATH)\n' \ - 'find_library(SZ_LIBRARY NAMES libsz.a HINTS ENV LD_LIBRARY_PATH)\n' \ - 'find_library(BZ2_LIBRARY NAMES libbz2.a HINTS ENV LD_LIBRARY_PATH)\n' \ - 'find_library(CURL_LIBRARY NAMES libcurl.a HINTS ENV LD_LIBRARY_PATH)\n' \ - 'find_library(XML2_LIBRARY NAMES libxml2.a HINTS ENV LD_LIBRARY_PATH)\n' \ - 'set(NETCDF_FOUND TRUE)\n' \ - 'set(NETCDF_INCLUDE_DIRS ${NETCDF_INCLUDE_DIR})\n' \ - 'set(NETCDF_LIBRARIES ${NETCDF_FORTRAN_LIBRARY} ${NETCDF_LIBRARY} ${HDF5_HL_LIBRARY} ${HDF5_LIBRARY} ${SZ_LIBRARY} ${Z_LIBRARY} ${ZSTD_LIBRARY} ${BZ2_LIBRARY} ${CURL_LIBRARY} ${XML2_LIBRARY} )\n' \ - 'mark_as_advanced(NETCDF_LIBRARY NETCDF_FORTRAN_LIBRARY NETCDF_INCLUDE_DIR)\n' > /swiftest/cmake/Modules/FindNETCDF.cmake && \ - cd swiftest && \ - cmake -S . -B build -DCMAKE_INSTALL_PREFIX="${INSTALL_DIR}" -DCONTAINERIZE=ON -DUSE_COARRAY=OFF -DCMAKE_BUILD_TYPE=RELEASE -DBUILD_SHARED_LIBS=OFF &&\ +RUN cd swiftest && \ + cmake -S . -B build -DCMAKE_INSTALL_PREFIX="${INSTALL_DIR}" -DMACHINE_CODE_VALUE="sse2" -DUSE_COARRAY=OFF -DCMAKE_BUILD_TYPE=RELEASE -DBUILD_SHARED_LIBS=OFF && \ cmake --build build && \ cmake --install build # Production container FROM ubuntu:20.04 -RUN apt-get update && apt-get upgrade -y && \ - DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ - libsz2 libcurl3-gnutls libxml2 && \ - rm -rf /var/lib/apt/lists/* - COPY --from=build /usr/local/bin/swiftest_driver /usr/local/bin/ -# COPY --from=build /usr/local/bin/swiftest_driver_caf /usr/local/bin/ -COPY --from=build /opt/intel/oneapi/compiler/2023.1.0/linux/compiler/lib/intel64_lin/libicaf.so /usr/local/lib/ -COPY --from=build /opt/intel/oneapi/mpi/2021.9.0//lib/release/libmpi.so.12 /usr/local/lib/ -COPY --from=build /opt/intel/oneapi/compiler/2023.1.0/linux/compiler/lib/intel64_lin/libintlc.so.5 /usr/local/lib/ -COPY --from=build /opt/intel/oneapi/mpi/latest/bin/mpiexec.hydra /usr/local/bin/ - ENTRYPOINT ["/usr/local/bin/swiftest_driver"] \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index cd7567afc..f360bcdbc 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -108,7 +108,7 @@ SET_SOURCE_FILES_PROPERTIES(${SWIFTEST_src} PROPERTIES Fortran_PREPROCESS ON) # Add the needed libraries and special compiler flags ##################################################### -TARGET_LINK_LIBRARIES(${SWIFTEST_DRIVER} PRIVATE ${NETCDF_FORTRAN_LIBRARIES} ${NETCDF_LIBRARIES}) +TARGET_LINK_LIBRARIES(${SWIFTEST_DRIVER} PRIVATE ${NETCDF_FORTRAN_LIBRARIES} ${NETCDF_LIBRARIES} $ENV{LIBS}) IF(USE_OPENMP) SET_PROPERTY(TARGET ${SWIFTEST_DRIVER} APPEND_STRING PROPERTY COMPILE_FLAGS "${OpenMP_Fortran_FLAGS} ") From 14537731d598b6f6ff4d7a3474948f5208b30c1b Mon Sep 17 00:00:00 2001 From: David Minton Date: Fri, 9 Jun 2023 18:05:04 -0400 Subject: [PATCH 81/95] Addedn environment.yml file to repo so that the conda environment can be created --- .gitignore | 1 + Dockerfile | 8 +-- docker/.gitignore | 1 - docker/Dockerfile.swiftest_driver | 99 ------------------------------- environment.yml | 22 +++++++ 5 files changed, 27 insertions(+), 104 deletions(-) delete mode 100644 docker/Dockerfile.swiftest_driver create mode 100644 environment.yml diff --git a/.gitignore b/.gitignore index e5c25df47..3ec1398e3 100644 --- a/.gitignore +++ b/.gitignore @@ -35,6 +35,7 @@ dump* !singularity/ !Dockerfile !swiftest.def +!environment.yml bin/ build/* diff --git a/Dockerfile b/Dockerfile index 33c82f700..4ac07ec7f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -125,12 +125,12 @@ ENV SHELL="/bin/bash" ENV PATH="/opt/conda/bin:${PATH}" ENV LD_LIBRARY_PATH="/usr/local/lib" -COPY environment.yml . - RUN conda update --all -y && \ conda install conda-libmamba-solver -y && \ - conda config --set solver libmamba && \ - conda env create -f environment.yml && \ + conda config --set solver libmamba + +COPY environment.yml . +RUN conda env create -f environment.yml && \ conda init bash && \ echo "conda activate swiftest-env" >> ~/.bashrc diff --git a/docker/.gitignore b/docker/.gitignore index c876f8c26..5c73deb60 100644 --- a/docker/.gitignore +++ b/docker/.gitignore @@ -4,4 +4,3 @@ !bin !bin/swiftest !bin/swiftest_driver -!Dockerfile.swiftest_driver diff --git a/docker/Dockerfile.swiftest_driver b/docker/Dockerfile.swiftest_driver deleted file mode 100644 index 08480c058..000000000 --- a/docker/Dockerfile.swiftest_driver +++ /dev/null @@ -1,99 +0,0 @@ -# Copyright 2023 - David Minton -# This file is part of Swiftest. -# Swiftest is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. -# Swiftest is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty -# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. -# You should have received a copy of the GNU General Public License along with Swiftest. -# If not, see: https://www.gnu.org/licenses. -# -# This Dockerfile will build the Swiftest driver program with minimal external dependencies using the Intel Oneapi toolkit. -# This is done by building static versions of a minimal set of libraries that NetCDF-Fortran needs (Netcdf-C, HDF5, and Zlib). -# These, along with the Intel runtime libraries, are linked statically to the executable. Only the OS-specific libraries are linked -# dynamically. -FROM intel/oneapi-hpckit:2023.1.0-devel-ubuntu20.04 as build - -ENV INSTALL_DIR="/usr/local" -ENV CC="${ONEAPI_ROOT}/compiler/latest/linux/bin/icx" -ENV FC="${ONEAPI_ROOT}/compiler/latest/linux/bin/ifx" -ENV CXX="${ONEAPI_ROOT}/compiler/latest/linux/bin/icpx" -ENV F77="${FC}" - -# Get the HDF5, NetCDF-C, and NetCDF-Fortran libraries -RUN wget -qO- https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.14/hdf5-1.14.1/src/hdf5-1.14.1-2.tar.gz | tar xvz && \ - wget -qO- https://github.com/Unidata/netcdf-c/archive/refs/tags/v4.9.2.tar.gz | tar xvz && \ - wget -qO- https://github.com/Unidata/netcdf-fortran/archive/refs/tags/v4.6.1.tar.gz | tar xvz && \ - wget -qO- https://www.zlib.net/zlib-1.2.13.tar.gz | tar xvz - -RUN apt-get update && \ - DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ - m4 && \ - rm -rf /var/lib/apt/lists/* - -RUN cd zlib-1.2.13 && \ - ./configure --prefix=${INSTALL_DIR} --static && \ - make && \ - make install - -RUN cd hdf5-1.14.1-2 && \ - ./configure --disable-shared \ - --enable-build-mode=production \ - --disable-fortran \ - --disable-java \ - --disable-cxx \ - --prefix=${INSTALL_DIR} \ - --with-zlib=${INSTALL_DIR} && \ - make && \ - make install - -RUN cd netcdf-c-4.9.2 && \ - ./configure --disable-shared \ - --disable-dap \ - --disable-libxml2 \ - --disable-byterange \ - --prefix=${INSTALL_DIR} && \ - make && \ - make install - -ENV NCDIR="${INSTALL_DIR}" -ENV NFDIR="${INSTALL_DIR}" -ENV HDF5_ROOT="${INSTALL_DIR}" -ENV HDF5_LIBDIR="${HDF5_ROOT}/lib" -ENV HDF5_INCLUDE_DIR="${HDF5_ROOT}/include" -ENV HDF5_PLUGIN_PATH="${HDF5_LIBDIR}/plugin" - -# NetCDF-Fortran library -ENV CFLAGS="-fPIC" -ENV FCFLAGS="${CFLAGS} -standard-semantics" -ENV FFLAGS=${CFLAGS} -ENV CPPFLAGS="-I${INSTALL_DIR}/include" -ENV LIBS="-L/usr/local/lib -L/usr/lib/x86_64-linux-gnu -lnetcdf -lhdf5_hl -lhdf5 -lm -lz" -RUN cd netcdf-fortran-4.6.1 && \ - ./configure --disable-shared --prefix=${NFDIR} && \ - make && \ - make install - -# Swiftest -ENV NETCDF_HOME=${INSTALL_DIR} -ENV NETCDF_FORTRAN_HOME=${NETCDF_HOME} -ENV NETCDF_LIBRARY=${NETCDF_HOME} -ENV FOR_COARRAY_NUM_IMAGES=1 -ENV OMP_NUM_THREADS=1 -ENV FC="${ONEAPI_ROOT}/mpi/latest/bin/mpiifort" -ENV FFLAGS="-fPIC -standard-semantics" -ENV LDFLAGS="-L/usr/local/lib" -ENV LIBS="-lhdf5_hl -lhdf5 -lz" -COPY ./cmake/ /swiftest/cmake/ -COPY ./src/ /swiftest/src/ -COPY ./CMakeLists.txt /swiftest/ -RUN cd swiftest && \ - cmake -S . -B build -DCMAKE_INSTALL_PREFIX="${INSTALL_DIR}" -DMACHINE_CODE_VALUE="sse2" -DUSE_COARRAY=OFF -DCMAKE_BUILD_TYPE=RELEASE -DBUILD_SHARED_LIBS=OFF && \ - cmake --build build && \ - cmake --install build - -# Production container -FROM ubuntu:20.04 - -COPY --from=build /usr/local/bin/swiftest_driver /usr/local/bin/ - -ENTRYPOINT ["/usr/local/bin/swiftest_driver"] \ No newline at end of file diff --git a/environment.yml b/environment.yml new file mode 100644 index 000000000..0e1dbb387 --- /dev/null +++ b/environment.yml @@ -0,0 +1,22 @@ +name: swiftest-env + +channels: + - conda-forge + - defaults + +dependencies: + - numpy + - scipy + - matplotlib + - pandas + - xarray + - h5netcdf + - netcdf4 + - dask + - bottleneck + - astropy + - astroquery + - tqdm + - x264 + - ffmpeg + - conda-build \ No newline at end of file From a0e5edc55ed7a781708ed09d06420f96ae677351 Mon Sep 17 00:00:00 2001 From: David Minton Date: Fri, 9 Jun 2023 19:03:52 -0400 Subject: [PATCH 82/95] Fixed issue that was leading to an incompatibility between glibc versions due to the miniconda3 container being based on an older Ubuntu. --- Dockerfile | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4ac07ec7f..55c22e793 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,7 +13,7 @@ # dynamically. # This build target compiles all dependencies and the swiftest driver itself -FROM intel/oneapi-hpckit:2023.1.0-devel-ubuntu22.04 as build +FROM intel/oneapi-hpckit:2023.1.0-devel-ubuntu20.04 as build # The MACHINE_CODE_VALUE argument is a string that is used when compiling the swiftest_driver. It is appended to the "-x" compiler # option: (-x${MACHINE_CODE_VALUE}). The default value is set to "sse2" which allows for certain SIMD instructions to be used while @@ -135,7 +135,7 @@ RUN conda env create -f environment.yml && \ echo "conda activate swiftest-env" >> ~/.bashrc COPY ./python/. /opt/conda/pkgs/ -COPY --from=build /usr/local/bin/swiftest_driver /opt/conda/envs/swiftest-env/bin/ +COPY --from=build /usr/local/bin/swiftest_driver /opt/conda/bin/swiftest_driver # Start new shell to activate the environment and install Swiftest RUN cd /opt/conda/pkgs/swiftest && conda develop . && \ @@ -145,7 +145,6 @@ RUN cd /opt/conda/pkgs/swiftest && conda develop . && \ mkdir -p /.cache/matplotlib && \ mkdir -p /.config/matplotlib && \ chmod -R 777 /.cache/matplotlib && \ - chmod -R 777 /.config/matplotlib && \ - ln -s /opt/conda/envs/swiftest-env/bin/swiftest_driver /opt/conda/bin/driver + chmod -R 777 /.config/matplotlib ENTRYPOINT ["conda", "run", "--no-capture-output", "-n", "swiftest-env"] \ No newline at end of file From 9a60cee064927b98ba53943872962eaa85a14dc2 Mon Sep 17 00:00:00 2001 From: David Minton Date: Fri, 9 Jun 2023 20:06:24 -0400 Subject: [PATCH 83/95] Minor tweaks to the Dockerfile to isolate the dependency build from the driver build --- .gitignore | 1 - Dockerfile | 40 ++++++++++++++++++++++++---------------- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/.gitignore b/.gitignore index 3ec1398e3..5056a889a 100644 --- a/.gitignore +++ b/.gitignore @@ -34,7 +34,6 @@ dump* !docker/ !singularity/ !Dockerfile -!swiftest.def !environment.yml bin/ diff --git a/Dockerfile b/Dockerfile index 55c22e793..ce3e615c3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,18 +13,7 @@ # dynamically. # This build target compiles all dependencies and the swiftest driver itself -FROM intel/oneapi-hpckit:2023.1.0-devel-ubuntu20.04 as build - -# The MACHINE_CODE_VALUE argument is a string that is used when compiling the swiftest_driver. It is appended to the "-x" compiler -# option: (-x${MACHINE_CODE_VALUE}). The default value is set to "sse2" which allows for certain SIMD instructions to be used while -# remaining # compatible with a wide range of CPUs. To get the highest performance, you can pass "host" as an argument, but the -# compiled binary # would only run on a CPU with an architecture compatible with the one that the build was performed on. -# For more details and other options, see: -# https://www.intel.com/content/www/us/en/docs/fortran-compiler/developer-guide-reference/2023-1/x-qx.html -ARG MACHINE_CODE_VALUE="sse2" - -# Build type options are DEBUG, RELEASE, PROFILE, or TESTING. -ARG BUILD_TYPE="RELEASE" +FROM intel/oneapi-hpckit:2023.1.0-devel-ubuntu20.04 as build_deps ENV INSTALL_DIR="/usr/local" ENV CC="${ONEAPI_ROOT}/compiler/latest/linux/bin/icx" @@ -86,6 +75,25 @@ RUN cd netcdf-fortran-4.6.1 && \ make && \ make install +FROM intel/oneapi-hpckit:2023.1.0-devel-ubuntu20.04 as build_driver +COPY --from=build_deps /usr/local/. /usr/local/ +ENV INSTALL_DIR="/usr/local" +ENV CC="${ONEAPI_ROOT}/compiler/latest/linux/bin/icx" +ENV FC="${ONEAPI_ROOT}/compiler/latest/linux/bin/ifx" +ENV CXX="${ONEAPI_ROOT}/compiler/latest/linux/bin/icpx" +ENV F77="${FC}" + +# The MACHINE_CODE_VALUE argument is a string that is used when compiling the swiftest_driver. It is appended to the "-x" compiler +# option: (-x${MACHINE_CODE_VALUE}). The default value is set to "sse2" which allows for certain SIMD instructions to be used while +# remaining # compatible with a wide range of CPUs. To get the highest performance, you can pass "host" as an argument, but the +# compiled binary # would only run on a CPU with an architecture compatible with the one that the build was performed on. +# For more details and other options, see: +# https://www.intel.com/content/www/us/en/docs/fortran-compiler/developer-guide-reference/2023-1/x-qx.html +ARG MACHINE_CODE_VALUE="sse2" + +# Build type options are DEBUG, RELEASE, PROFILE, or TESTING. +ARG BUILD_TYPE="RELEASE" + # Swiftest ENV NETCDF_HOME=${INSTALL_DIR} ENV NETCDF_FORTRAN_HOME=${NETCDF_HOME} @@ -109,13 +117,13 @@ RUN cd swiftest && \ cmake --install build # This build target creates a container that executes just the driver program -FROM ubuntu:22.04 as driver -COPY --from=build /usr/local/bin/swiftest_driver /usr/local/bin/ +FROM ubuntu:20.04 as driver +COPY --from=build_driver /usr/local/bin/swiftest_driver /usr/local/bin/ ENTRYPOINT ["/usr/local/bin/swiftest_driver"] # This build target exports the binary to the host FROM scratch AS export_driver -COPY --from=build /usr/local/bin/swiftest_driver / +COPY --from=build_driver /usr/local/bin/swiftest_driver / # This build target creates a container with a conda environment with all dependencies needed to run the Python front end and # analysis tools @@ -135,7 +143,7 @@ RUN conda env create -f environment.yml && \ echo "conda activate swiftest-env" >> ~/.bashrc COPY ./python/. /opt/conda/pkgs/ -COPY --from=build /usr/local/bin/swiftest_driver /opt/conda/bin/swiftest_driver +COPY --from=build_driver /usr/local/bin/swiftest_driver /opt/conda/bin/swiftest_driver # Start new shell to activate the environment and install Swiftest RUN cd /opt/conda/pkgs/swiftest && conda develop . && \ From 2da4a93960ef2b0b501fb4b7fa76e2bc7b7ee7ce Mon Sep 17 00:00:00 2001 From: David A Minton Date: Mon, 12 Jun 2023 09:21:25 -0400 Subject: [PATCH 84/95] Fixed some synchronization issues with coarrays --- src/swiftest/swiftest_coarray.f90 | 5 ++++- src/swiftest/swiftest_io.f90 | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/swiftest/swiftest_coarray.f90 b/src/swiftest/swiftest_coarray.f90 index 7dbd1a816..62e44f5ac 100644 --- a/src/swiftest/swiftest_coarray.f90 +++ b/src/swiftest/swiftest_coarray.f90 @@ -42,15 +42,18 @@ module subroutine swiftest_coarray_balance_system(nbody_system, param) write(param%display_unit,*) "ntp_min : " // trim(adjustl(min_str)) write(param%display_unit,*) "ntp_max : " // trim(adjustl(max_str)) write(param%display_unit,*) "difference: " // trim(adjustl(diff_str)) + flush(param%display_unit) + sync all if (ntp_max - ntp_min >= num_images()) then write(param%display_unit,*) trim(adjustl(diff_str)) // ">=" // trim(adjustl(ni_str)) // ": Rebalancing" + flush(param%display_unit) call nbody_system%coarray_collect(param) call nbody_system%coarray_distribute(param) write(param%display_unit,*) "Rebalancing complete" else write(param%display_unit,*) trim(adjustl(diff_str)) // "<" // trim(adjustl(ni_str)) // ": No rebalancing needed" end if - call flush(param%display_unit) + flush(param%display_unit) return end subroutine swiftest_coarray_balance_system diff --git a/src/swiftest/swiftest_io.f90 b/src/swiftest/swiftest_io.f90 index eea186c48..70ddac5f7 100644 --- a/src/swiftest/swiftest_io.f90 +++ b/src/swiftest/swiftest_io.f90 @@ -437,6 +437,7 @@ module subroutine swiftest_io_dump_storage(self, param) call iotimer%stop() sync all call iotimer%report(message="File output :", unit=param%display_unit) + flush(param%display_unit) #endif end associate From aebd7702b5f34e3f9dccbbe687549ea6179c0557 Mon Sep 17 00:00:00 2001 From: carlislewishard <70146819+carlislewishard@users.noreply.github.com> Date: Tue, 27 Jun 2023 10:31:35 -0400 Subject: [PATCH 85/95] Update README.md fixed link to clone repo, also added in cmake flags for gfortran --- README.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3671832cb..e011b8430 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ Parallelization in Swiftest is done with OpenMP. Version 3.1.4 or higher is nece The easiest way to get Swiftest on your machine is to clone the GitHub repository. To do so, open a terminal window and type the following: ``` -$ git clone https://github.itap.purdue.edu/MintonGroup/swiftest.git +$ git clone https://github.com/carlislewishard/swiftest.git ``` If your cloned version is not already set to the master branch: @@ -85,7 +85,7 @@ CMake allows the user to specify a set of compiler flags to use during compilati As a general rule, the release flags are fully optimized and best used when running Swiftest with the goal of generating results. This is the default set of flags. When making changes to the Swiftest source code, it is best to compile Swiftest using the debug set of flags. You may also define your own set of compiler flags. -To build Swiftest with the release flags (default), type the following: +To build Swiftest with the release flags (default) using the Intel fortran compiler (ifort), type the following: ``` $ cmake .. ``` @@ -97,6 +97,11 @@ To build with another set of flags, simply replace ```DEBUG``` in the above line Add ```-CMAKE_PREFIX_PATH=/path/to/netcdf/``` to these commands as needed. +If using the GCC fortran compiler (gfortran), add the following flags: +``` +cmake -DCMAKE_Fortran_FLAGS="-I/usr/lib64/gfortran/modules/ -ffree-line-length-512" ... +``` + After building Swiftest, make the executable using: ``` From f1bfc2fb48090f09b79a039db13f17ea624fdbfe Mon Sep 17 00:00:00 2001 From: carlislewishard <70146819+carlislewishard@users.noreply.github.com> Date: Tue, 27 Jun 2023 10:37:31 -0400 Subject: [PATCH 86/95] Update README.md added flag to specify fortran compiler --- README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e011b8430..f45a812c3 100644 --- a/README.md +++ b/README.md @@ -99,11 +99,14 @@ Add ```-CMAKE_PREFIX_PATH=/path/to/netcdf/``` to these commands as needed. If using the GCC fortran compiler (gfortran), add the following flags: ``` -cmake -DCMAKE_Fortran_FLAGS="-I/usr/lib64/gfortran/modules/ -ffree-line-length-512" ... +-DCMAKE_Fortran_FLAGS="-I/usr/lib64/gfortran/modules/ -ffree-line-length-512" +``` +You can manually specify the compiler you wish to use with the following flag: +``` +c-DCMAKE_Fortran_COMPILER=$(which ifort) ``` After building Swiftest, make the executable using: - ``` $ make ``` From 8feca172adcfe01395ebb49a4a993bc0d9249eb5 Mon Sep 17 00:00:00 2001 From: carlislewishard <70146819+carlislewishard@users.noreply.github.com> Date: Tue, 27 Jun 2023 13:52:46 -0400 Subject: [PATCH 87/95] updated readme to add errors.py --- examples/Basic_Simulation/README.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/Basic_Simulation/README.txt b/examples/Basic_Simulation/README.txt index 9db2d5f54..ae626a9c5 100644 --- a/examples/Basic_Simulation/README.txt +++ b/examples/Basic_Simulation/README.txt @@ -11,13 +11,14 @@ README.txt Swiftest Example : Basic_Simulation Author : Carlisle Wishard and David Minton -Date : December 6, 2022 +Date : June 27, 2023 Included in the Basic_Simulation example directory are the following files: - README.txt : This file - initial_conditions.py : A Python Script that generates and runs a set of initial conditions. - output_reader.py : A Python Script that processes out.nc and generates output.eps + - errors.py : A Python Script that processes out.nc and reports the simulation errors to the terminal This example is intended to be run with Swiftest SyMBA. For details on how to generate, run, and analyze this example, -see the Swiftest User Manual. \ No newline at end of file +see the Swiftest User Manual. From 47b0ad55bd3f7228dc58c3b1c15e6ee3411023bc Mon Sep 17 00:00:00 2001 From: carlislewishard <70146819+carlislewishard@users.noreply.github.com> Date: Tue, 27 Jun 2023 13:53:39 -0400 Subject: [PATCH 88/95] added error analysis python script --- examples/Basic_Simulation/errors.py | 69 +++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 examples/Basic_Simulation/errors.py diff --git a/examples/Basic_Simulation/errors.py b/examples/Basic_Simulation/errors.py new file mode 100644 index 000000000..581677949 --- /dev/null +++ b/examples/Basic_Simulation/errors.py @@ -0,0 +1,69 @@ +#!/usr/bin/env python3 + +""" + Copyright 2023 - David Minton, Carlisle Wishard, Jennifer Pouplin, Jake Elliott, & Dana Singh + This file is part of Swiftest. + Swiftest is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License + as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + Swiftest is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty + of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along with Swiftest. + If not, see: https://www.gnu.org/licenses. +""" + +""" +Reads and processes a Swiftest output file. + +Input +------ +data.nc : A NetCDF file containing the simulation output. + +Output +------ +None +""" + +import swiftest +import xarray as xr +import matplotlib.pyplot as plt + +# Read in the simulation output and store it as an Xarray dataset. +ds = swiftest.Simulation(read_data=True) + +# Calculate the angular momentum error +ds.data['L_tot'] = ds.data['L_orbit'] + ds.data['L_spin'] + ds.data['L_escape'] +ds.data['DL'] = ds.data['L_tot'] - ds.data['L_tot'].isel(time=0) +ds.data['L_error'] = swiftest.tool.magnitude(ds.data,'DL') / swiftest.tool.magnitude(ds.data.isel(time=0), 'L_tot') +L_final = ds.data['L_error'][-1].values + +# Calculate the energy error +ds.data['E_error'] = (ds.data['TE'] - ds.data['TE'].isel(time=0)) / ds.data['TE'].isel(time=0) +E_final = ds.data['E_error'][-1].values + +# Calculate the mass error +ds.data['GMtot'] = ds.data['Gmass'].sum(dim='name',skipna=True) + ds.data['GMescape'] +ds.data['GM_error'] = (ds.data['GMtot'] - ds.data['GMtot'].isel(time=0)) / ds.data['GMtot'].isel(time=0) +GM_final = ds.data['GM_error'][-1].values + +# Print the final errors +print("Final Angular Momentum Error: ", L_final) +print("Final Energy Error: ", E_final) +print("Final Mass Error: ", GM_final) + +# Determine if the errors are within bounds +L_limit = 1e-10 +E_limit = 1e-4 +GM_limit = 1e-14 + +lerror = 0 +if (L_final > L_limit): + lerror = 1 + print("Angular Momentum Error of", L_final, " higher than threshold value of", L_limit, ". Test failed.") +if (E_final > E_limit): + lerror = 1 + print("Energy Error of", E_final, " higher than threshold value of", E_limit, ". Test failed.") +if (GM_final > GM_limit): + lerror = 1 + print("Mass Error of", GM_final, " higher than threshold value of", GM_limit, ". Test failed.") +if (lerror == 0): + print("Test successful.") \ No newline at end of file From 1fc4bef397867cc348b0fb832cc093c7629eb56b Mon Sep 17 00:00:00 2001 From: carlislewishard <70146819+carlislewishard@users.noreply.github.com> Date: Tue, 27 Jun 2023 13:54:14 -0400 Subject: [PATCH 89/95] Update .gitignore to add errors.py --- examples/Basic_Simulation/.gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/Basic_Simulation/.gitignore b/examples/Basic_Simulation/.gitignore index 728fe8873..9e4d02aad 100644 --- a/examples/Basic_Simulation/.gitignore +++ b/examples/Basic_Simulation/.gitignore @@ -2,4 +2,5 @@ !.gitignore !initial_conditions.py !output_reader.py +!errors.py !README.txt From e5181a6890a9e8f32e145d92a7df08a0e7d08e47 Mon Sep 17 00:00:00 2001 From: carlislewishard <70146819+carlislewishard@users.noreply.github.com> Date: Tue, 27 Jun 2023 13:54:56 -0400 Subject: [PATCH 90/95] Updated output_reader python script --- examples/Basic_Simulation/output_reader.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/Basic_Simulation/output_reader.py b/examples/Basic_Simulation/output_reader.py index 851384bf3..b8cf36a70 100644 --- a/examples/Basic_Simulation/output_reader.py +++ b/examples/Basic_Simulation/output_reader.py @@ -43,4 +43,4 @@ ax.text(1.5, 0.35, f"t = {sim.data['time'].isel(time=0).values} years", size=10, ha="left") plt.tight_layout() plt.show() -fig.savefig("output.eps", dpi=300, facecolor='white', transparent=False, bbox_inches="tight") +fig.savefig("../examples/Basic_Simulation/output.eps", dpi=300, facecolor='white', transparent=False, bbox_inches="tight") From 1551a512e86f119ef3795e145098548fbe5b225b Mon Sep 17 00:00:00 2001 From: carlislewishard <70146819+carlislewishard@users.noreply.github.com> Date: Tue, 27 Jun 2023 13:55:49 -0400 Subject: [PATCH 91/95] added automatic test that runs the Basic_Simulation example and generates output --- CMakeLists.txt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 961683f3e..4d36d9612 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -73,3 +73,17 @@ ADD_SUBDIRECTORY(${SRC} ${BIN}) ADD_CUSTOM_TARGET(distclean COMMAND ${CMAKE_COMMAND} -P ${CMAKE_SOURCE_DIR}/distclean.cmake ) + +# Add an automatic test +ADD_CUSTOM_TARGET(Run_Test ALL + COMMAND echo "***Running Python script examples/Basic_Simulation/initial_conditions.py***" + COMMAND python ${CMAKE_SOURCE_DIR}/examples/Basic_Simulation/initial_conditions.py + COMMAND echo "***Saving data to directory examples/Basic_Simulation/simdata***" + COMMAND echo "***Running Python script examples/Basic_Simulation/output_reader.py***" + COMMAND python ${CMAKE_SOURCE_DIR}/examples/Basic_Simulation/output_reader.py + COMMAND echo "***Plotting results as examples/Basic_Simulation/output.eps***" + COMMAND echo "***Calculating errors with Python script examples/Basic_Simulation/errors.py***" + COMMAND python ${CMAKE_SOURCE_DIR}/examples/Basic_Simulation/errors.py + COMMAND echo "***Test Complete***" +) + From 99aff8e3c98bdc3c5ea915162d987e3bb87a8e11 Mon Sep 17 00:00:00 2001 From: carlislewishard <70146819+carlislewishard@users.noreply.github.com> Date: Tue, 27 Jun 2023 13:59:52 -0400 Subject: [PATCH 92/95] prevented output_reader from showing plot --- examples/Basic_Simulation/output_reader.py | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/Basic_Simulation/output_reader.py b/examples/Basic_Simulation/output_reader.py index b8cf36a70..f0b08c98c 100644 --- a/examples/Basic_Simulation/output_reader.py +++ b/examples/Basic_Simulation/output_reader.py @@ -42,5 +42,4 @@ ax.set_ylim(0, 0.4) ax.text(1.5, 0.35, f"t = {sim.data['time'].isel(time=0).values} years", size=10, ha="left") plt.tight_layout() -plt.show() fig.savefig("../examples/Basic_Simulation/output.eps", dpi=300, facecolor='white', transparent=False, bbox_inches="tight") From 8814dffd7e4b076bebcbe679ac4be690619d687d Mon Sep 17 00:00:00 2001 From: carlislewishard <70146819+carlislewishard@users.noreply.github.com> Date: Thu, 29 Jun 2023 11:07:42 -0400 Subject: [PATCH 93/95] Update initial_conditions.py set a seed for the random number generator, clarified names of bodies, and adjusted eccentricity and inclination of bodies to be less energetic --- .../Basic_Simulation/initial_conditions.py | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/examples/Basic_Simulation/initial_conditions.py b/examples/Basic_Simulation/initial_conditions.py index 813bd8dfb..83614fb07 100755 --- a/examples/Basic_Simulation/initial_conditions.py +++ b/examples/Basic_Simulation/initial_conditions.py @@ -39,6 +39,7 @@ #sim = swiftest.Simulation(fragmentation=True, minimum_fragment_mass = 2.5e-11, mtiny=2.5e-8) sim = swiftest.Simulation() sim.clean() +rng = default_rng(seed=123) # Add the modern planets and the Sun using the JPL Horizons Database. sim.add_solar_system_body(["Sun","Mercury","Venus","Earth","Mars","Jupiter","Saturn","Uranus","Neptune","Pluto"]) @@ -47,18 +48,18 @@ npl = 5 density_pl = 3000.0 / (sim.param['MU2KG'] / sim.param['DU2M'] ** 3) -name_pl = ["MassiveBody_01", "MassiveBody_02", "MassiveBody_03", "MassiveBody_04", "MassiveBody_05"] -a_pl = default_rng().uniform(0.3, 1.5, npl) -e_pl = default_rng().uniform(0.0, 0.3, npl) -inc_pl = default_rng().uniform(0.0, 90, npl) -capom_pl = default_rng().uniform(0.0, 360.0, npl) -omega_pl = default_rng().uniform(0.0, 360.0, npl) -capm_pl = default_rng().uniform(0.0, 360.0, npl) -M_pl = np.array([6e23, 8e23, 1e24, 3e24, 5e24]) * sim.KG2MU +name_pl = ["SemiBody_01", "SemiBody_02", "SemiBody_03", "SemiBody_04", "SemiBody_05"] +a_pl = rng.uniform(0.3, 1.5, npl) +e_pl = rng.uniform(0.0, 0.2, npl) +inc_pl = rng.uniform(0.0, 10, npl) +capom_pl = rng.uniform(0.0, 360.0, npl) +omega_pl = rng.uniform(0.0, 360.0, npl) +capm_pl = rng.uniform(0.0, 360.0, npl) +M_pl = np.array([6e20, 8e20, 1e21, 3e21, 5e21]) * sim.KG2MU R_pl = np.full(npl, (3 * M_pl/ (4 * np.pi * density_pl)) ** (1.0 / 3.0)) -Ip_pl = np.full((npl,3),0.4,) -rot_pl = np.zeros((npl,3)) -mtiny = 1.01 * np.max(M_pl) +Ip_pl = np.full((npl,3),0.4,) +rot_pl = np.zeros((npl,3)) +mtiny = 1.1 * np.max(M_pl) sim.add_body(name=name_pl, a=a_pl, e=e_pl, inc=inc_pl, capom=capom_pl, omega=omega_pl, capm=capm_pl, mass=M_pl, radius=R_pl, Ip=Ip_pl, rot=rot_pl) @@ -66,12 +67,12 @@ ntp = 10 name_tp = ["TestParticle_01", "TestParticle_02", "TestParticle_03", "TestParticle_04", "TestParticle_05", "TestParticle_06", "TestParticle_07", "TestParticle_08", "TestParticle_09", "TestParticle_10"] -a_tp = default_rng().uniform(0.3, 1.5, ntp) -e_tp = default_rng().uniform(0.0, 0.3, ntp) -inc_tp = default_rng().uniform(0.0, 90, ntp) -capom_tp = default_rng().uniform(0.0, 360.0, ntp) -omega_tp = default_rng().uniform(0.0, 360.0, ntp) -capm_tp = default_rng().uniform(0.0, 360.0, ntp) +a_tp = rng.uniform(0.3, 1.5, ntp) +e_tp = rng.uniform(0.0, 0.2, ntp) +inc_tp = rng.uniform(0.0, 10, ntp) +capom_tp = rng.uniform(0.0, 360.0, ntp) +omega_tp = rng.uniform(0.0, 360.0, ntp) +capm_tp = rng.uniform(0.0, 360.0, ntp) sim.add_body(name=name_tp, a=a_tp, e=e_tp, inc=inc_tp, capom=capom_tp, omega=omega_tp, capm=capm_tp) sim.set_parameter(tstart=0.0, tstop=1.0e3, dt=0.01, istep_out=100, dump_cadence=0, compute_conservation_values=True, mtiny=mtiny) From 6181c8867ab330fb5331cbaebea081f28940312c Mon Sep 17 00:00:00 2001 From: carlislewishard <70146819+carlislewishard@users.noreply.github.com> Date: Thu, 29 Jun 2023 11:09:53 -0400 Subject: [PATCH 94/95] Update output_reader.py adjusted bounds of plot to account for less excited system --- examples/Basic_Simulation/output_reader.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/Basic_Simulation/output_reader.py b/examples/Basic_Simulation/output_reader.py index f0b08c98c..a46b6cefc 100644 --- a/examples/Basic_Simulation/output_reader.py +++ b/examples/Basic_Simulation/output_reader.py @@ -39,7 +39,7 @@ ax.set(xlabel="Semimajor Axis (AU)", ylabel="Eccentricity", title="Simulation Initial Conditions (t=0)") ax.scatter(sim.data['a'].isel(time=0), sim.data['e'].isel(time=0), c=colors, s=sizes, edgecolor='black') ax.set_xlim(0, 2.0) -ax.set_ylim(0, 0.4) -ax.text(1.5, 0.35, f"t = {sim.data['time'].isel(time=0).values} years", size=10, ha="left") +ax.set_ylim(0, 0.25) +ax.text(1.5, 0.2, f"t = {sim.data['time'].isel(time=0).values} years", size=10, ha="left") plt.tight_layout() fig.savefig("../examples/Basic_Simulation/output.eps", dpi=300, facecolor='white', transparent=False, bbox_inches="tight") From 6a82e69cc2e50cc376bcf50897b060a6be58157e Mon Sep 17 00:00:00 2001 From: carlislewishard <70146819+carlislewishard@users.noreply.github.com> Date: Thu, 29 Jun 2023 11:11:10 -0400 Subject: [PATCH 95/95] Update errors.py adjusted energy error limit slightly to account for less energetic system --- examples/Basic_Simulation/errors.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/Basic_Simulation/errors.py b/examples/Basic_Simulation/errors.py index 581677949..5cbdfaa55 100644 --- a/examples/Basic_Simulation/errors.py +++ b/examples/Basic_Simulation/errors.py @@ -52,7 +52,7 @@ # Determine if the errors are within bounds L_limit = 1e-10 -E_limit = 1e-4 +E_limit = 1e-5 GM_limit = 1e-14 lerror = 0 @@ -66,4 +66,4 @@ lerror = 1 print("Mass Error of", GM_final, " higher than threshold value of", GM_limit, ". Test failed.") if (lerror == 0): - print("Test successful.") \ No newline at end of file + print("Test successful.")