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

Commit

Permalink
Simplified driver program and moved all messaging to io_dump_system. …
Browse files Browse the repository at this point in the history
…Added in Wall time messaging from the Fragmentation branch
  • Loading branch information
daminton committed Aug 11, 2021
1 parent 3774b40 commit e0b071c
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 43 deletions.
68 changes: 42 additions & 26 deletions src/io/io.f90
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ module subroutine io_dump_param(self, param_file_name)
end subroutine io_dump_param


module subroutine io_dump_swiftest(self, param, msg)
module subroutine io_dump_swiftest(self, param)
!! author: David A. Minton
!!
!! Dump massive body data to files
Expand All @@ -140,7 +140,6 @@ module subroutine io_dump_swiftest(self, param, msg)
! Arguments
class(swiftest_base), intent(inout) :: self !! Swiftest base object
class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters
character(*), optional, intent(in) :: msg !! Message to display with dump operation
! Internals
integer(I4B) :: ierr !! Error code
integer(I4B),parameter :: LUN = 7 !! Unit number for dump file
Expand Down Expand Up @@ -168,7 +167,7 @@ module subroutine io_dump_swiftest(self, param, msg)
end subroutine io_dump_swiftest


module subroutine io_dump_system(self, param, msg)
module subroutine io_dump_system(self, param)
!! author: David A. Minton
!!
!! Dumps the state of the system to files in case the simulation is interrupted.
Expand All @@ -178,35 +177,52 @@ module subroutine io_dump_system(self, param, msg)
! Arguments
class(swiftest_nbody_system), intent(inout) :: self !! Swiftest system object
class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters
character(*), optional, intent(in) :: msg !! Message to display with dump operation
! Internals
class(swiftest_parameters), allocatable :: dump_param !! Local parameters variable used to parameters change input file names
!! to dump file-specific values without changing the user-defined values
integer(I4B), save :: idx = 1 !! Index of current dump file. Output flips between 2 files for extra security
!! in case the program halts during writing
character(len=:), allocatable :: param_file_name
real(DP) :: tfrac

allocate(dump_param, source=param)
param_file_name = trim(adjustl(DUMP_PARAM_FILE(idx)))
dump_param%incbfile = trim(adjustl(DUMP_CB_FILE(idx)))
dump_param%inplfile = trim(adjustl(DUMP_PL_FILE(idx)))
dump_param%intpfile = trim(adjustl(DUMP_TP_FILE(idx)))
dump_param%out_form = XV
dump_param%out_stat = 'APPEND'
dump_param%T0 = param%t
call dump_param%dump(param_file_name)

call self%cb%dump(dump_param)
if (self%pl%nbody > 0) call self%pl%dump(dump_param)
if (self%tp%nbody > 0) call self%tp%dump(dump_param)

idx = idx + 1
if (idx > NDUMPFILES) idx = 1

! Print the status message (format code passed in from main driver)
tfrac = (param%t - param%t0) / (param%tstop - param%t0)
write(*,msg) param%t, tfrac, self%pl%nbody, self%tp%nbody
real(DP) :: deltawall, wallperstep, tfrac
integer(I8B) :: clock_count, count_rate, count_max
character(*), parameter :: statusfmt = '("Time = ", ES12.5, "; fraction done = ", F6.3, "; Number of active pl, tp = ", I5, ", ", I5)'
character(len=*), parameter :: walltimefmt = '(" Wall time (s): ", es12.5, "; Wall time/step in this interval (s): ", es12.5)'
logical, save :: lfirst = .true.
real(DP), save :: start, finish

if (lfirst) then
call system_clock(clock_count, count_rate, count_max)
start = clock_count / (count_rate * 1.0_DP)
finish = start
lfirst = .false.
else
allocate(dump_param, source=param)
param_file_name = trim(adjustl(DUMP_PARAM_FILE(idx)))
dump_param%incbfile = trim(adjustl(DUMP_CB_FILE(idx)))
dump_param%inplfile = trim(adjustl(DUMP_PL_FILE(idx)))
dump_param%intpfile = trim(adjustl(DUMP_TP_FILE(idx)))
dump_param%out_form = XV
dump_param%out_stat = 'APPEND'
dump_param%T0 = param%t
call dump_param%dump(param_file_name)

call self%cb%dump(dump_param)
if (self%pl%nbody > 0) call self%pl%dump(dump_param)
if (self%tp%nbody > 0) call self%tp%dump(dump_param)

idx = idx + 1
if (idx > NDUMPFILES) idx = 1

tfrac = (param%t - param%t0) / (param%tstop - param%t0)

call system_clock(clock_count, count_rate, count_max)
deltawall = clock_count / (count_rate * 1.0_DP) - finish
wallperstep = deltawall / param%istep_dump
finish = clock_count / (count_rate * 1.0_DP)
end if
write(*, statusfmt) param%t, tfrac, self%pl%nbody, self%tp%nbody
write(*, walltimefmt) finish - start, wallperstep

if (param%lenergy) call self%conservation_report(param, lterminal=.true.)

return
Expand Down
20 changes: 7 additions & 13 deletions src/main/swiftest_driver.f90
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,13 @@ program swiftest_driver
integer(I8B) :: idump !! Dump cadence counter
integer(I8B) :: iout !! Output cadence counter
integer(I8B) :: nloops !! Number of steps to take in the simulation
real(DP) :: start_wall_time !! Wall clock time at start of execution
real(DP) :: finish_wall_time !! Wall clock time when execution has finished
integer(I4B) :: iu !! Unit number of binary file

character(*),parameter :: statusfmt = '("Time = ", ES12.5, "; fraction done = ", F6.3, "; ' // &
'Number of active pl, tp = ", I5, ", ", I5)'

ierr = io_get_args(integrator, param_file_name)
if (ierr /= 0) then
write(*,*) 'Error reading in arguments from the command line'
call util_exit(FAILURE)
end if
!$ start_wall_time = omp_get_wtime()
!> Read in the user-defined parameters file and the initial conditions of the system
select case(integrator)
case(symba)
Expand All @@ -39,21 +33,26 @@ program swiftest_driver
allocate(swiftest_parameters :: param)
end select
param%integrator = integrator

call setup_construct_system(nbody_system, param)
call param%read_from_file(param_file_name)

associate(t => param%t, &
t0 => param%t0, &
dt => param%dt, &
tstop => param%tstop, &
istep_out => param%istep_out, &
istep_dump => param%istep_dump)

call nbody_system%initialize(param)
t = t0
iloop = 0
iout = istep_out
idump = istep_dump
nloops = ceiling(tstop / dt, kind=I8B)
if (istep_out > 0) call nbody_system%write_frame(iu, param)
call nbody_system%dump(param)

!> Define the maximum number of threads
nthreads = 1 ! In the *serial* case
!$ nthreads = omp_get_max_threads() ! In the *parallel* case
Expand Down Expand Up @@ -83,18 +82,13 @@ program swiftest_driver
if (istep_dump > 0) then
idump = idump - 1
if (idump == 0) then
call nbody_system%dump(param, statusfmt)
call nbody_system%dump(param)
idump = istep_dump
end if
end if
!if (t >= tstop) exit
end do

!> Dump the final state of the system to file
!call nbody_system%dump(param, t, dt, statusfmt)
!$ finish_wall_time = omp_get_wtime()
!$ write(*,*) 'Time: ', finish_wall_time - start_wall_time
end associate

call util_exit(SUCCESS)

stop
Expand Down
6 changes: 2 additions & 4 deletions src/modules/swiftest_classes.f90
Original file line number Diff line number Diff line change
Expand Up @@ -550,18 +550,16 @@ module subroutine io_dump_param(self, param_file_name)
character(len=*), intent(in) :: param_file_name !! Parameter input file name (i.e. param.in)
end subroutine io_dump_param

module subroutine io_dump_swiftest(self, param, msg)
module subroutine io_dump_swiftest(self, param)
implicit none
class(swiftest_base), intent(inout) :: self !! Swiftest base object
class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters
character(*), optional, intent(in) :: msg !! Message to display with dump operation
end subroutine io_dump_swiftest

module subroutine io_dump_system(self, param, msg)
module subroutine io_dump_system(self, param)
implicit none
class(swiftest_nbody_system), intent(inout) :: self !! Swiftest system object
class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters
character(*), optional, intent(in) :: msg !! Message to display with dump operation
end subroutine io_dump_system

module function io_get_args(integrator, param_file_name) result(ierr)
Expand Down

0 comments on commit e0b071c

Please sign in to comment.