diff --git a/src/globals/globals_module.f90 b/src/globals/globals_module.f90 index fa6b18582..fd26b3404 100644 --- a/src/globals/globals_module.f90 +++ b/src/globals/globals_module.f90 @@ -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 diff --git a/src/swiftest/swiftest_coarray.f90 b/src/swiftest/swiftest_coarray.f90 index b2f615712..9d5650cc2 100644 --- a/src/swiftest/swiftest_coarray.f90 +++ b/src/swiftest/swiftest_coarray.f90 @@ -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) @@ -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)) @@ -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) diff --git a/src/swiftest/swiftest_driver.f90 b/src/swiftest/swiftest_driver.f90 index 69b820599..be55dbd6b 100644 --- a/src/swiftest/swiftest_driver.f90 +++ b/src/swiftest/swiftest_driver.f90 @@ -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)') ' ------------------' @@ -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 @@ -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 @@ -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 diff --git a/src/swiftest/swiftest_io.f90 b/src/swiftest/swiftest_io.f90 index 97ace68ed..c36ce9b79 100644 --- a/src/swiftest/swiftest_io.f90 +++ b/src/swiftest/swiftest_io.f90 @@ -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 @@ -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 @@ -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) @@ -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 @@ -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)