AMUN: Slightly polish the main program.

Signed-off-by: Grzegorz Kowal <grzegorz@amuncode.org>
This commit is contained in:
Grzegorz Kowal 2021-11-17 11:57:38 -03:00
parent 7d238b6c1b
commit 0dde0f8122

View File

@ -111,6 +111,8 @@ program amun
! !
real(kind=8), dimension(ntimers) :: tm real(kind=8), dimension(ntimers) :: tm
character(len=*), parameter :: loc = 'AMUN::amun()'
!------------------------------------------------------------------------------- !-------------------------------------------------------------------------------
! !
#ifdef SIGNALS #ifdef SIGNALS
@ -127,7 +129,7 @@ program amun
#endif /* __GFORTRAN__ */ #endif /* __GFORTRAN__ */
if (status /= 0) then if (status /= 0) then
write(error_unit,"('[AMUN::program]: ', a)") & write(error_unit,"('[',a,']: ',a)") trim(loc), &
"Could not initialize the signal handling!" "Could not initialize the signal handling!"
call exit(status) call exit(status)
end if end if
@ -145,7 +147,7 @@ program amun
! !
call initialize_mpitools(status) call initialize_mpitools(status)
if (status /= 0) then if (status /= 0) then
write(error_unit,"('[AMUN::program]: ', a)") & write(error_unit,"('[',a,']: ',a)") trim(loc), &
"Could not initialize module MPITOOLS!" "Could not initialize module MPITOOLS!"
end if end if
if (check_status(status /= 0)) call exit(status) if (check_status(status /= 0)) call exit(status)
@ -165,66 +167,59 @@ program amun
! !
call read_parameters(verbose, status) call read_parameters(verbose, status)
if (status /= 0) then if (status /= 0) then
write(error_unit,"('[AMUN::program]: ', a)") & write(error_unit,"('[',a,']: ',a)") trim(loc), &
"Could not read parameters file!" "Could not read parameters file!"
end if end if
if (check_status(status /= 0)) go to 6000 if (check_status(status /= 0)) go to 6000
! initialize IO early so we can recover a few parameters from ! initialize a few basic modules: IO, PROBLEM, RNG, WORKSPACE
! the restart snapshots
! !
call initialize_io(verbose, status) call initialize_io(verbose, status)
if (status /= 0) then if (status /= 0) then
write(error_unit,"('[AMUN::program]: ', a)") & write(error_unit,"('[',a,']: ',a)") trim(loc), &
"Could not initialize module IO!" "Could not initialize module IO!"
end if end if
if (check_status(status /= 0)) go to 5000 if (check_status(status /= 0)) go to 5000
! initialize module PROBLEM
!
call initialize_problem(verbose, status) call initialize_problem(verbose, status)
if (status /= 0) then if (status /= 0) then
write(error_unit,"('[AMUN::program]: ', a)") & write(error_unit,"('[',a,']: ',a)") trim(loc), &
"Could not initialize module PROBLEM!" "Could not initialize module PROBLEM!"
end if end if
if (check_status(status /= 0)) go to 4000 if (check_status(status /= 0)) go to 4000
! initialize the random number generator
!
call initialize_random(rngtype, 1, 0, nproc, status) call initialize_random(rngtype, 1, 0, nproc, status)
if (status /= 0) then if (status /= 0) then
write(error_unit,"('[AMUN::program]: ', a)") & write(error_unit,"('[',a,']: ',a)") trim(loc), &
"Could not initialize module RANDOM!" "Could not initialize module RANDOM!"
end if end if
if (check_status(status /= 0)) go to 3000 if (check_status(status /= 0)) go to 3000
! initialize the workspace
!
call initialize_workspace(nwork, status) call initialize_workspace(nwork, status)
if (status /= 0) then if (status /= 0) then
write(error_unit,"('[AMUN::program]: ', a)") & write(error_unit,"('[',a,']: ',a)") trim(loc), &
"Problem initializing WORKSPACE module!" "Problem initializing WORKSPACE module!"
end if end if
if (check_status(status /= 0)) go to 2000 if (check_status(status /= 0)) go to 2000
! print module information ! show some info before the simulation starts
! !
call print_problem_info(verbose) call print_problem_info(verbose)
! restore the simulation for restarted job, otherwise initiate a new one ! initiate or resume the simulation
! !
if (resumed) then if (resumed) then
call read_restart_snapshot(status) call read_restart_snapshot(status)
if (status /= 0) then if (status /= 0) then
write(error_unit,"('[AMUN::program]: ', a)") & write(error_unit,"('[',a,']: ',a)") trim(loc), &
"Problem reading the restart snapshot!" "Problem reading the restart snapshot!"
end if end if
if (check_status(status /= 0)) go to 1000 if (check_status(status /= 0)) go to 1000
call build_leaf_list(status) call build_leaf_list(status)
if (status /= 0) then if (status /= 0) then
write(error_unit,"('[AMUN::program]: ', a)") & write(error_unit,"('[',a,']: ',a)") trim(loc), &
"Problem building the list of leafs!" "Problem building the list of leafs!"
end if end if
if (check_status(status /= 0)) go to 1000 if (check_status(status /= 0)) go to 1000
@ -233,12 +228,9 @@ program amun
else else
! generate the initial mesh, refine that mesh to the desired level according to
! the problem setup
!
call generate_mesh(status) call generate_mesh(status)
if (status /= 0) then if (status /= 0) then
write(error_unit,"('[AMUN::program]: ', a)") & write(error_unit,"('[',a,']: ',a)") trim(loc), &
"Problem generating the initial mesh!" "Problem generating the initial mesh!"
end if end if
if (check_status(status /= 0)) go to 1000 if (check_status(status /= 0)) go to 1000
@ -247,14 +239,10 @@ program amun
call initialize_time_step() call initialize_time_step()
! store the initial time statistics and the snapshot
!
call store_integrals() call store_integrals()
call user_time_statistics(time) call user_time_statistics(time)
call write_snapshot(name) call write_snapshot(name)
! store the initial mesh statistics
!
call store_mesh_stats(step, time) call store_mesh_stats(step, time)
end if end if
@ -302,7 +290,7 @@ program amun
call advance(status) call advance(status)
if (status /= 0) then if (status /= 0) then
write(error_unit,"('[AMUN::program]: ', a)") & write(error_unit,"('[',a,']: ',a)") trim(loc), &
"Advancing to the next step failed!" "Advancing to the next step failed!"
end if end if
if (check_status(status /= 0)) go to 1000 if (check_status(status /= 0)) go to 1000
@ -338,7 +326,7 @@ program amun
call write_restart_snapshot(thrs, name, nrun, status) call write_restart_snapshot(thrs, name, nrun, status)
if (status /= 0) then if (status /= 0) then
write(error_unit,"('[AMUN::program]: ', a)") & write(error_unit,"('[',a,']: ',a)") trim(loc), &
"Could not store the restart snapshot!" "Could not store the restart snapshot!"
end if end if
if (check_status(status /= 0)) go to 1000 if (check_status(status /= 0)) go to 1000
@ -396,38 +384,43 @@ program amun
! !
call write_restart_snapshot(1.0d+16, name, nrun, status) call write_restart_snapshot(1.0d+16, name, nrun, status)
if (status /= 0) then if (status /= 0) then
write(error_unit,"('[AMUN::program]: ', a)") & write(error_unit,"('[',a,']: ',a)") trim(loc), &
"Could not store the restart snapshot!" "Could not store the restart snapshot!"
end if end if
! finalize all modules
!
1000 continue 1000 continue
call start_timer(itm) call start_timer(itm)
! finalize all modules
!
call finalize_workspace(status) call finalize_workspace(status)
if (status /= 0) then if (status /= 0) then
write(error_unit,"('[AMUN::program]: ', a)") & write(error_unit,"('[',a,']: ',a)") trim(loc), &
"Problem finalizing WORKSPACE module!" "Problem finalizing WORKSPACE module!"
end if end if
2000 continue 2000 continue
call finalize_random(status) call finalize_random(status)
if (status /= 0) then if (status /= 0) then
write(error_unit,"('[AMUN::program]: ', a)") & write(error_unit,"('[',a,']: ',a)") trim(loc), &
"Could not finalize module RANDOM!" "Could not finalize module RANDOM!"
end if end if
3000 continue 3000 continue
call finalize_problem(verbose, status) call finalize_problem(verbose, status)
if (status /= 0) then if (status /= 0) then
write(error_unit,"('[AMUN::program]: ', a)") & write(error_unit,"('[',a,']: ',a)") trim(loc), &
"Could not finalize module PROBLEM!" "Could not finalize module PROBLEM!"
end if end if
4000 continue 4000 continue
call finalize_io(status) call finalize_io(status)
if (status /= 0) then if (status /= 0) then
write(error_unit,"('[AMUN::program]: ', a)") & write(error_unit,"('[',a,']: ',a)") trim(loc), &
"Problem finalizing IO module!" "Problem finalizing IO module!"
end if end if
5000 continue 5000 continue
call finalize_parameters() call finalize_parameters()
if (initialization_succeeded) then if (initialization_succeeded) then
@ -494,11 +487,11 @@ program amun
end if end if
end if end if
6000 continue 6000 continue
call finalize_mpitools(status) call finalize_mpitools(status)
if (status /= 0) then if (status /= 0) then
write(error_unit,"('[AMUN::program]: ', a)") & write(error_unit,"('[',a,']: ',a)") trim(loc), &
"Problem finalizing MPITOOLS module!" "Problem finalizing MPITOOLS module!"
end if end if
@ -521,7 +514,7 @@ program amun
! !
!=============================================================================== !===============================================================================
! !
integer(kind=4) function signal_handler(sig_num) integer(kind=4) function signal_handler(sig_num)
use iso_fortran_env, only : error_unit use iso_fortran_env, only : error_unit
@ -539,7 +532,7 @@ integer(kind=4) function signal_handler(sig_num)
!------------------------------------------------------------------------------- !-------------------------------------------------------------------------------
! !
end function end function
#else /* __INTEL_COMPILER */ #else /* __INTEL_COMPILER */
! !
!=============================================================================== !===============================================================================
@ -551,7 +544,7 @@ end function
! !
!=============================================================================== !===============================================================================
! !
subroutine signal_handler() subroutine signal_handler()
use iso_fortran_env, only : error_unit use iso_fortran_env, only : error_unit
@ -567,7 +560,7 @@ subroutine signal_handler()
!------------------------------------------------------------------------------- !-------------------------------------------------------------------------------
! !
end subroutine end subroutine
#endif /* __INTEL_COMPILER */ #endif /* __INTEL_COMPILER */
#endif /* SIGNALS */ #endif /* SIGNALS */