diff --git a/sources/amun.F90 b/sources/amun.F90 index 80cc568..7d4554b 100644 --- a/sources/amun.F90 +++ b/sources/amun.F90 @@ -31,13 +31,8 @@ ! program amun - use blocks , only : get_nleafs - use evolution , only : advance, new_time_step - use evolution , only : step, time, dt, errtol use helpers , only : print_welcome, print_section, print_parameter use io , only : initialize_io, finalize_io - use io , only : write_restart_snapshot - use io , only : update_dtp use iso_fortran_env, only : error_unit use mpitools , only : initialize_mpitools, finalize_mpitools #ifdef MPI @@ -46,9 +41,10 @@ program amun use mpitools , only : master, nprocs, nproc, check_status use parameters , only : read_parameters, finalize_parameters use problem , only : initialize_problem, finalize_problem - use problem , only : print_problem_info, prepare_problem, store_problem + use problem , only : print_problem_info, prepare_problem + use problem , only : evolve_problem, store_problem use problem , only : resumed, nrun, name, rngtype - use problem , only : tmax, trun, nwork, nmax + use problem , only : tmax, trun, nwork, nmax, quit, nsteps use random , only : initialize_random, finalize_random use timers , only : initialize_timers, finalize_timers use timers , only : start_timer, stop_timer, set_timer, get_timer @@ -62,26 +58,18 @@ program amun ! logical :: initialization_succeeded logical :: verbose = .true. - logical :: proceed = .true. - integer :: quit = 0 integer :: status = 0 ! timer indices, iteration number and other time variables ! integer :: iin, iev, itm integer :: i, ed, eh, em, es, ec - integer :: nsteps = 1 - real(kind=8) :: tbeg = 0.0d+00, thrs - real(kind=8) :: tm_curr, tm_exec, tm_conv, tm_last = 0.0d+00 + real(kind=8) :: tm_exec, tm_conv ! the format string ! character(len=80) :: sfmt -! vectors for improved estimation of the remaining simulation time -! - real(kind=8), dimension(8) :: tprv, tm_prev - ! an array pointer for timings ! real(kind=8), dimension(:), allocatable :: tm @@ -213,139 +201,15 @@ program amun ! call start_timer(iev) -! initiate the progress info -! - if (verbose) then - - tbeg = time - tprv(:) = time - tm_prev(:) = get_timer_total() - - ed = 9999 - eh = 23 - em = 59 - es = 59 - - write(*,*) - write(*,"(1x,a)" ) "Evolving the system:" - write(*,"(4x,'step',5x,'time',11x,'timestep',6x,'err/tol',4x," // & - "'blocks',7x,'ETA')") -#ifdef __INTEL_COMPILER - write(*,"(i8,2(1x,1es14.6),1x,1es10.2,2x,i8,2x," // & - "1i4.1,'d',1i2.2,'h',1i2.2,'m',1i2.2,'s',15x,a1,$)") & - step, time, dt, errtol, get_nleafs(), ed, eh, em, es, char(13) -#else /* __INTEL_COMPILER */ - write(*,"(i8,2(1x,1es14.6),1x,1es10.2,2x,i8,2x," // & - "1i4.1,'d',1i2.2,'h',1i2.2,'m',1i2.2,'s',15x,a1)",advance="no") & - step, time, dt, errtol, get_nleafs(), ed, eh, em, es, char(13) -#endif /* __INTEL_COMPILER */ - + call evolve_problem(verbose, status) + if (status /= 0) then + write(error_unit,"('[',a,']: ',a)") trim(loc), & + "Problem execution failed!" end if - - proceed = (nsteps <= nmax) .and. (time < tmax) .and. proceed - -! the integration loop -! - do while(proceed) - - call advance(status) - if (status /= 0) then - write(error_unit,"('[',a,']: ',a)") trim(loc), & - "Advancing to the next step failed!" - end if - if (check_status(status /= 0)) go to 1000 - -! increase the iteration number and time -! - time = time + dt - step = step + 1 - nsteps = nsteps + 1 - -! update the time step for the precise snapshots -! - call update_dtp() - -! estimate the next time step -! - call new_time_step() - -! store problem's progress -! - call store_problem(status) - if (status /= 0) then - write(error_unit,"('[',a,']: ',a)") trim(loc), & - "Could not store the problem's progress!" - end if - -! estimate the elapsed time to trigger the restart snapshot storage -! - tm_curr = get_timer_total() - thrs = tm_curr / 3.6d+03 - - call write_restart_snapshot(thrs, name, nrun, status) - if (status /= 0) then - write(error_unit,"('[',a,']: ',a)") trim(loc), & - "Could not store the restart snapshot!" - end if - if (check_status(status /= 0)) go to 1000 - -! check conditions for the integration interruption -! - proceed = (nsteps <= nmax) .and. (time < tmax) .and. & - (thrs <= trun) .and. .not. check_status(quit /= 0) - - if (verbose) then - -! update the vectors for the remaining time estimation -! - tm_prev(1) = tm_curr - tprv(1) = time - tm_prev = cshift(tm_prev, 1) - tprv = cshift(tprv , 1) - - if (time >= tmax .or. (tm_curr - tm_last) >= 1.0d+00) then - - ec = int((tm_curr - tm_prev(1)) * (tmax - time) & - / max(1.0d-03, time - tprv(1)), kind = 4) - es = max(0, min(863999999, ec)) - ed = es / 86400 - es = es - 86400 * ed - eh = es / 3600 - es = es - 3600 * eh - em = es / 60 - es = es - 60 * em - -! print the progress info -! -#ifdef __INTEL_COMPILER - write(*,"(i8,2(1x,1es14.6),1x,1es10.2,2x,i8,2x," // & - "1i4.1,'d',1i2.2,'h',1i2.2,'m',1i2.2,'s',15x,a1,$)") & - step, time, dt, errtol, get_nleafs(), ed, eh, em, es, char(13) -#else /* __INTEL_COMPILER */ - write(*,"(i8,2(1x,1es14.6),1x,1es10.2,2x,i8,2x," // & - "1i4.1,'d',1i2.2,'h',1i2.2,'m',1i2.2,'s',15x,a1)",advance="no")& - step, time, dt, errtol, get_nleafs(), ed, eh, em, es, char(13) -#endif /* __INTEL_COMPILER */ - - tm_last = tm_curr - - end if - end if - - end do ! main loop - - if (verbose) write(*,*) + if (check_status(status /= 0)) go to 1000 call stop_timer(iev) -! store the final restart snapshot -! - call write_restart_snapshot(1.0d+16, name, nrun, status) - if (status /= 0) then - write(error_unit,"('[',a,']: ',a)") trim(loc), & - "Could not store the restart snapshot!" - end if - 1000 continue call start_timer(itm) diff --git a/sources/problem.F90 b/sources/problem.F90 index 11a9284..8ba88ea 100644 --- a/sources/problem.F90 +++ b/sources/problem.F90 @@ -38,10 +38,18 @@ module problem ! logical, save :: resumed = .false. +! the flag indicating that the problem evolution should be interrupted +! + integer, save :: quit = 0 + ! the number of resumed run ! integer, save :: nrun = 0 +! the number of iterations executed during the evolution +! + integer, save :: nsteps = 1 + ! the problem's permament parameters ! character(len=64) , save :: name = "none" @@ -67,10 +75,11 @@ module problem integer , save :: nwork = 4194304 ! 32MiB private - public :: initialize_problem, finalize_problem, prepare_problem, store_problem + public :: initialize_problem, finalize_problem + public :: prepare_problem, evolve_problem, store_problem public :: print_problem_info - public :: resumed, name, nrun, eqsys, eos, ncells, nghosts, maxlev - public :: bdims, dbnds, rngtype, nmax, ndat, tmax, trun, tsav, nwork + public :: resumed, name, nrun, eqsys, eos, ncells, nghosts, maxlev, nsteps + public :: bdims, dbnds, rngtype, nmax, ndat, tmax, trun, tsav, nwork, quit !- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ! @@ -428,30 +437,163 @@ module problem ! !=============================================================================== ! -! subroutine EXECUTE_PROBLEM: -! --------------------------- +! subroutine EVOLVE_PROBLEM: +! ------------------------- ! -! Subroutine executes the problem by performing its time evolution. +! Subroutine performed the time evolution of the problem. ! ! Arguments: ! -! status - the subroutine call status; +! verbose - the verbose flag; +! status - the subroutine call status; ! !=============================================================================== ! - subroutine execute_problem(status) + subroutine evolve_problem(verbose, status) + + use blocks , only : get_nleafs + use evolution , only : step, time, dt, errtol + use evolution , only : advance, new_time_step + use io , only : update_dtp, write_restart_snapshot + use iso_fortran_env, only : error_unit + use mpitools , only : check_status + use timers , only : get_timer_total implicit none + logical, intent(in) :: verbose integer, intent(out) :: status + logical :: proceed = .true. + integer :: ed, eh, em, es, ec + real(kind=8) :: tbeg = 0.0d+00, thrs + real(kind=8) :: tm_curr, tm_exec, tm_conv, tm_last = 0.0d+00 + + real(kind=8), dimension(8) :: tprv, tm_prev + + character(len=*), parameter :: loc = 'PROBLEM::evolve_problem()' + !------------------------------------------------------------------------------- ! status = 0 + if (verbose) then + + tbeg = time + tprv(:) = time + tm_prev(:) = get_timer_total() + + ed = 9999 + eh = 23 + em = 59 + es = 59 + + write(*,*) + write(*,"(1x,a)" ) "Evolving the system:" + write(*,"(4x,'step',5x,'time',11x,'timestep',6x,'err/tol',4x," // & + "'blocks',7x,'ETA')") +#ifdef __INTEL_COMPILER + write(*,"(i8,2(1x,1es14.6),1x,1es10.2,2x,i8,2x," // & + "1i4.1,'d',1i2.2,'h',1i2.2,'m',1i2.2,'s',15x,a1,$)") & + step, time, dt, errtol, get_nleafs(), ed, eh, em, es, char(13) +#else /* __INTEL_COMPILER */ + write(*,"(i8,2(1x,1es14.6),1x,1es10.2,2x,i8,2x," // & + "1i4.1,'d',1i2.2,'h',1i2.2,'m',1i2.2,'s',15x,a1)",advance="no") & + step, time, dt, errtol, get_nleafs(), ed, eh, em, es, char(13) +#endif /* __INTEL_COMPILER */ + + end if + + proceed = (nsteps <= nmax) .and. (time < tmax) .and. proceed + + do while(proceed) + + call advance(status) + if (status /= 0) then + write(error_unit,"('[',a,']: ',a)") trim(loc), & + "Advancing to the next step failed!" + end if + if (check_status(status /= 0)) return + + time = time + dt + step = step + 1 + nsteps = nsteps + 1 + + call update_dtp() + + call new_time_step() + + call store_problem(status) + if (status /= 0) then + write(error_unit,"('[',a,']: ',a)") trim(loc), & + "Could not store the problem's progress!" + end if + if (check_status(status /= 0)) return + + tm_curr = get_timer_total() + thrs = tm_curr / 3.6d+03 + + call write_restart_snapshot(thrs, name, nrun, status) + if (status /= 0) then + write(error_unit,"('[',a,']: ',a)") trim(loc), & + "Could not store the restart snapshot!" + end if + if (check_status(status /= 0)) return + +! check conditions for the integration interruption +! + proceed = (nsteps <= nmax) .and. (time < tmax) .and. & + (thrs <= trun) .and. .not. check_status(quit /= 0) + + if (verbose) then + +! update the vectors for the remaining time estimation +! + tm_prev(1) = tm_curr + tprv(1) = time + tm_prev = cshift(tm_prev, 1) + tprv = cshift(tprv , 1) + + if (time >= tmax .or. (tm_curr - tm_last) >= 1.0d+00) then + + ec = int((tm_curr - tm_prev(1)) * (tmax - time) & + / max(1.0d-03, time - tprv(1)), kind = 4) + es = max(0, min(863999999, ec)) + ed = es / 86400 + es = es - 86400 * ed + eh = es / 3600 + es = es - 3600 * eh + em = es / 60 + es = es - 60 * em + +#ifdef __INTEL_COMPILER + write(*,"(i8,2(1x,1es14.6),1x,1es10.2,2x,i8,2x,1i4.1," // & + "'d',1i2.2,'h',1i2.2,'m',1i2.2,'s',15x,a1,$)") & + step, time, dt, errtol, get_nleafs(), ed, eh, em, es, char(13) +#else /* __INTEL_COMPILER */ + write(*,"(i8,2(1x,1es14.6),1x,1es10.2,2x,i8,2x,1i4.1," // & + "'d',1i2.2,'h',1i2.2,'m',1i2.2,'s',15x,a1)",advance="no") & + step, time, dt, errtol, get_nleafs(), ed, eh, em, es, char(13) +#endif /* __INTEL_COMPILER */ + + tm_last = tm_curr + + end if + end if + + end do ! main loop + + if (verbose) write(*,*) + + call write_restart_snapshot(1.0d+16, name, nrun, status) + if (status /= 0) then + write(error_unit,"('[',a,']: ',a)") trim(loc), & + "Could not store the restart snapshot!" + end if + !------------------------------------------------------------------------------- ! - end subroutine execute_problem + end subroutine evolve_problem ! !=============================================================================== !