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

Commit

Permalink
Improved output logging by giving each co-image its own log file
Browse files Browse the repository at this point in the history
  • Loading branch information
daminton committed Apr 25, 2023
1 parent 756ae55 commit 63b8010
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 13 deletions.
6 changes: 5 additions & 1 deletion src/globals/globals_module.f90
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,11 @@ module globals
!> Standard file names
integer(I4B), parameter :: NDUMPFILES = 2
character(*), parameter :: PARAM_RESTART_FILE = "param.restart.in"
character(*), parameter :: SWIFTEST_LOG_FILE = "swiftest.log" !! Name of file to use to log output when using "COMPACT" display style
#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)
#else
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

!> Default file names that can be changed by the user in the parameters file
Expand Down
7 changes: 5 additions & 2 deletions src/swiftest/swiftest_coarray.f90
Original file line number Diff line number Diff line change
Expand Up @@ -487,9 +487,10 @@ module subroutine swiftest_coarray_collect_system(nbody_system, param)

if (.not.param%lcoarray) return

if (this_image() == 1) then
if (this_image() == 1 .or. param%log_output) then
write(image_num_char,*) num_images()
write(param%display_unit,*) " Collecting test particles from " // trim(adjustl(image_num_char)) // " images."
if (param%log_output) flush(param%display_unit)
end if

allocate(cotp[*], source=nbody_system%tp)
Expand Down Expand Up @@ -530,9 +531,10 @@ module subroutine swiftest_coarray_distribute_system(nbody_system, param)

write(image_num_char,*) num_images()

if (this_image() == 1) then
if (this_image() == 1 .or. param%log_output) then
write(ntp_num_char,*) ntot
write(param%display_unit,*) " Distributing " // trim(adjustl(ntp_num_char)) // " test particles across " // trim(adjustl(image_num_char)) // " images."
if (param%log_output) flush(param%display_unit)
end if

allocate(lspill_list(ntot))
Expand Down Expand Up @@ -560,6 +562,7 @@ module subroutine swiftest_coarray_distribute_system(nbody_system, param)
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(tmp, cotp)
Expand Down
9 changes: 5 additions & 4 deletions src/swiftest/swiftest_driver.f90
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ program swiftest_driver
nthreads = 1 ! In the *serial* case
!$ nthreads = omp_get_max_threads() ! In the *parallel* case
#ifdef COARRAY
if (this_image() == 1) then
if (this_image() == 1 .or. param%log_output) then
#endif
!$ write(param%display_unit,'(a)') ' OpenMP parameters:'
!$ write(param%display_unit,'(a)') ' ------------------'
Expand All @@ -87,13 +87,14 @@ program swiftest_driver
write(param%display_unit,*) ' Coarray parameters:'
write(param%display_unit,*) ' -------------------'
write(param%display_unit,*) ' Number of images = ', num_images()
if (param%log_output) write(*,'(a,i3)') ' Coarray: Number of images = ',num_images()
if (param%log_output .and. this_image() == 1) write(*,'(a,i3)') ' Coarray: Number of images = ',num_images()
else
write(param%display_unit,*) ' Coarrays disabled.'
if (param%log_output) write(*,*) ' Coarrays disabled.'
end if
end if
#endif
if (param%log_output) flush(param%display_unit)

#ifdef COARRAY
! The following line lets us read in the input files one image at a time. Letting each image read the input in is faster than broadcasting all of the data
Expand Down Expand Up @@ -151,7 +152,7 @@ program swiftest_driver
call nbody_system%dump(param, system_history)
end if
#ifdef COARRAY
if (this_image() == 1) then
if (this_image() == 1 .or. param%log_output) then
#endif
call integration_timer%report(message="Integration steps:", unit=display_unit)
#ifdef COARRAY
Expand All @@ -160,7 +161,7 @@ program swiftest_driver
call nbody_system%display_run_information(param, integration_timer)
call integration_timer%reset()
#ifdef COARRAY
if (this_image() == 1) then
if (this_image() == 1 .or. param%log_output) then
#endif
if (param%lenergy) call nbody_system%conservation_report(param, lterminal=.true.)
#ifdef COARRAY
Expand Down
22 changes: 16 additions & 6 deletions src/swiftest/swiftest_io.f90
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,13 @@ module subroutine swiftest_io_conservation_report(self, param, lterminal)

nbody_system%Mescape_error = nbody_system%GMescape / nbody_system%GMtot_orig
#ifdef COARRAY
if (this_image() == 1) then
if (this_image() == 1 .or. param%log_output) then
#endif
if (lterminal) write(display_unit, EGYTERMFMT) nbody_system%L_total_error, nbody_system%E_orbit_error, nbody_system%te_error,nbody_system%Mtot_error
if (lterminal) then
write(display_unit, EGYTERMFMT) nbody_system%L_total_error, nbody_system%E_orbit_error, nbody_system%te_error,nbody_system%Mtot_error
if (param%log_output) flush(display_unit)
end if

#ifdef COARRAY
end if ! (this_image() == 1) then
#endif
Expand Down Expand Up @@ -255,7 +259,7 @@ module subroutine swiftest_io_display_run_information(self, param, integration_t
tfrac = (self%t - param%t0) / (param%tstop - param%t0)

#ifdef COARRAY
if (this_image() == 1) then
if (this_image() == 1 .or. param%log_output) then
#endif
if (phase_val == 0) then
if (param%lrestart) then
Expand Down Expand Up @@ -301,14 +305,16 @@ module subroutine swiftest_io_display_run_information(self, param, integration_t
end if

#ifdef COARRAY
if (this_image() == num_images()) then
if (this_image() == num_images() .or. param%log_output) then
#endif
if (phase_val == -1) then
write(param%display_unit, *)" *************** Swiftest stop " // trim(adjustl(param%integrator)) // " *************** "
if (param%display_style == "COMPACT") write(*,*) "SWIFTEST STOP" // trim(adjustl(param%integrator))
end if

#ifdef COARRAY
end if ! this_image() == num_images()
if (param%log_output) flush(param%display_unit)

! Allow the other images to report
if (param%lcoarray .and. (this_image() < num_images())) sync images(this_image() + 1)
Expand Down Expand Up @@ -2443,9 +2449,10 @@ module subroutine swiftest_io_param_reader(self, unit, iotype, v_list, iostat, i

if (.not.param%lrestart) then
#ifdef COARRAY
if (this_image() == 1) then
if (this_image() == 1 .or. param%log_output) then
#endif
call param%writer(unit = param%display_unit, iotype = "none", v_list = [0], iostat = iostat, iomsg = iomsg)
call param%writer(unit = param%display_unit, iotype = "none", v_list = [0], iostat = iostat, iomsg = iomsg)
if (param%log_output) flush(param%display_unit)
#ifdef COARRAY
end if !(this_image() == 1)
#endif
Expand Down Expand Up @@ -3078,6 +3085,9 @@ module subroutine swiftest_io_set_display_param(self, display_style)
self%display_unit = OUTPUT_UNIT !! stdout from iso_fortran_env
self%log_output = .false.
case ('COMPACT', 'PROGRESS')
#ifdef COARRAY
write(SWIFTEST_LOG_FILE,'("swiftest_coimage",I0.3,".log")') this_image()
#endif
inquire(file=SWIFTEST_LOG_FILE, exist=fileExists)
if (self%lrestart.and.fileExists) then
open(unit=SWIFTEST_LOG_OUT, file=SWIFTEST_LOG_FILE, status="OLD", position="APPEND", err = 667, iomsg = errmsg)
Expand Down

0 comments on commit 63b8010

Please sign in to comment.