From 0dde0f81222c44dd9e2ce51b2586596cf14039a9 Mon Sep 17 00:00:00 2001 From: Grzegorz Kowal Date: Wed, 17 Nov 2021 11:57:38 -0300 Subject: [PATCH] AMUN: Slightly polish the main program. Signed-off-by: Grzegorz Kowal --- sources/amun.F90 | 107 ++++++++++++++++++++++------------------------- 1 file changed, 50 insertions(+), 57 deletions(-) diff --git a/sources/amun.F90 b/sources/amun.F90 index ba9c94c..a0ba891 100644 --- a/sources/amun.F90 +++ b/sources/amun.F90 @@ -111,6 +111,8 @@ program amun ! real(kind=8), dimension(ntimers) :: tm + character(len=*), parameter :: loc = 'AMUN::amun()' + !------------------------------------------------------------------------------- ! #ifdef SIGNALS @@ -127,7 +129,7 @@ program amun #endif /* __GFORTRAN__ */ if (status /= 0) then - write(error_unit,"('[AMUN::program]: ', a)") & + write(error_unit,"('[',a,']: ',a)") trim(loc), & "Could not initialize the signal handling!" call exit(status) end if @@ -145,7 +147,7 @@ program amun ! call initialize_mpitools(status) if (status /= 0) then - write(error_unit,"('[AMUN::program]: ', a)") & + write(error_unit,"('[',a,']: ',a)") trim(loc), & "Could not initialize module MPITOOLS!" end if if (check_status(status /= 0)) call exit(status) @@ -165,66 +167,59 @@ program amun ! call read_parameters(verbose, status) if (status /= 0) then - write(error_unit,"('[AMUN::program]: ', a)") & + write(error_unit,"('[',a,']: ',a)") trim(loc), & "Could not read parameters file!" end if if (check_status(status /= 0)) go to 6000 -! initialize IO early so we can recover a few parameters from -! the restart snapshots +! initialize a few basic modules: IO, PROBLEM, RNG, WORKSPACE ! call initialize_io(verbose, status) if (status /= 0) then - write(error_unit,"('[AMUN::program]: ', a)") & + write(error_unit,"('[',a,']: ',a)") trim(loc), & "Could not initialize module IO!" end if if (check_status(status /= 0)) go to 5000 -! initialize module PROBLEM -! call initialize_problem(verbose, status) if (status /= 0) then - write(error_unit,"('[AMUN::program]: ', a)") & + write(error_unit,"('[',a,']: ',a)") trim(loc), & "Could not initialize module PROBLEM!" end if if (check_status(status /= 0)) go to 4000 -! initialize the random number generator -! call initialize_random(rngtype, 1, 0, nproc, status) if (status /= 0) then - write(error_unit,"('[AMUN::program]: ', a)") & + write(error_unit,"('[',a,']: ',a)") trim(loc), & "Could not initialize module RANDOM!" end if if (check_status(status /= 0)) go to 3000 -! initialize the workspace -! call initialize_workspace(nwork, status) if (status /= 0) then - write(error_unit,"('[AMUN::program]: ', a)") & + write(error_unit,"('[',a,']: ',a)") trim(loc), & "Problem initializing WORKSPACE module!" end if if (check_status(status /= 0)) go to 2000 -! print module information +! show some info before the simulation starts ! call print_problem_info(verbose) -! restore the simulation for restarted job, otherwise initiate a new one +! initiate or resume the simulation ! if (resumed) then call read_restart_snapshot(status) if (status /= 0) then - write(error_unit,"('[AMUN::program]: ', a)") & + write(error_unit,"('[',a,']: ',a)") trim(loc), & "Problem reading the restart snapshot!" end if if (check_status(status /= 0)) go to 1000 call build_leaf_list(status) if (status /= 0) then - write(error_unit,"('[AMUN::program]: ', a)") & + write(error_unit,"('[',a,']: ',a)") trim(loc), & "Problem building the list of leafs!" end if if (check_status(status /= 0)) go to 1000 @@ -233,12 +228,9 @@ program amun else -! generate the initial mesh, refine that mesh to the desired level according to -! the problem setup -! call generate_mesh(status) if (status /= 0) then - write(error_unit,"('[AMUN::program]: ', a)") & + write(error_unit,"('[',a,']: ',a)") trim(loc), & "Problem generating the initial mesh!" end if if (check_status(status /= 0)) go to 1000 @@ -247,14 +239,10 @@ program amun call initialize_time_step() -! store the initial time statistics and the snapshot -! call store_integrals() call user_time_statistics(time) call write_snapshot(name) -! store the initial mesh statistics -! call store_mesh_stats(step, time) end if @@ -302,7 +290,7 @@ program amun call advance(status) if (status /= 0) then - write(error_unit,"('[AMUN::program]: ', a)") & + write(error_unit,"('[',a,']: ',a)") trim(loc), & "Advancing to the next step failed!" end if if (check_status(status /= 0)) go to 1000 @@ -338,7 +326,7 @@ program amun call write_restart_snapshot(thrs, name, nrun, status) if (status /= 0) then - write(error_unit,"('[AMUN::program]: ', a)") & + write(error_unit,"('[',a,']: ',a)") trim(loc), & "Could not store the restart snapshot!" end if if (check_status(status /= 0)) go to 1000 @@ -396,38 +384,43 @@ program amun ! call write_restart_snapshot(1.0d+16, name, nrun, status) if (status /= 0) then - write(error_unit,"('[AMUN::program]: ', a)") & + write(error_unit,"('[',a,']: ',a)") trim(loc), & "Could not store the restart snapshot!" end if -! finalize all modules -! 1000 continue call start_timer(itm) + +! finalize all modules +! call finalize_workspace(status) if (status /= 0) then - write(error_unit,"('[AMUN::program]: ', a)") & + write(error_unit,"('[',a,']: ',a)") trim(loc), & "Problem finalizing WORKSPACE module!" end if 2000 continue + call finalize_random(status) if (status /= 0) then - write(error_unit,"('[AMUN::program]: ', a)") & + write(error_unit,"('[',a,']: ',a)") trim(loc), & "Could not finalize module RANDOM!" end if 3000 continue + call finalize_problem(verbose, status) if (status /= 0) then - write(error_unit,"('[AMUN::program]: ', a)") & + write(error_unit,"('[',a,']: ',a)") trim(loc), & "Could not finalize module PROBLEM!" end if 4000 continue + call finalize_io(status) if (status /= 0) then - write(error_unit,"('[AMUN::program]: ', a)") & + write(error_unit,"('[',a,']: ',a)") trim(loc), & "Problem finalizing IO module!" end if 5000 continue + call finalize_parameters() if (initialization_succeeded) then @@ -494,11 +487,11 @@ program amun end if end if - 6000 continue + call finalize_mpitools(status) if (status /= 0) then - write(error_unit,"('[AMUN::program]: ', a)") & + write(error_unit,"('[',a,']: ',a)") trim(loc), & "Problem finalizing MPITOOLS module!" end if @@ -521,25 +514,25 @@ 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 - implicit none + implicit none - integer(kind=4), intent(in) :: sig_num + integer(kind=4), intent(in) :: sig_num !------------------------------------------------------------------------------- ! - quit = sig_num - write(error_unit,*) - write(error_unit,*) "Received signal:", iterm - write(error_unit,*) "Closing program..." - signal_handler = 1 + quit = sig_num + write(error_unit,*) + write(error_unit,*) "Received signal:", iterm + write(error_unit,*) "Closing program..." + signal_handler = 1 !------------------------------------------------------------------------------- ! -end function + end function #else /* __INTEL_COMPILER */ ! !=============================================================================== @@ -551,23 +544,23 @@ end function ! !=============================================================================== ! -subroutine signal_handler() + subroutine signal_handler() - use iso_fortran_env, only : error_unit + use iso_fortran_env, only : error_unit - implicit none + implicit none !------------------------------------------------------------------------------- ! - quit = 15 - write(error_unit,*) - write(error_unit,*) "Received signal: 2, 9, or 15" - write(error_unit,*) "Closing program..." - return + quit = 15 + write(error_unit,*) + write(error_unit,*) "Received signal: 2, 9, or 15" + write(error_unit,*) "Closing program..." + return !------------------------------------------------------------------------------- ! -end subroutine + end subroutine #endif /* __INTEL_COMPILER */ #endif /* SIGNALS */