From e6aca9820a70aa83e54290e9b7a0aaec82366710 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Tue, 17 Jan 2012 16:21:13 -0500 Subject: [PATCH] Added finalize module to better group post-simulation subroutines. --- src/DEPENDENCIES | 7 ++++++- src/OBJECTS | 1 + src/finalize.F90 | 49 ++++++++++++++++++++++++++++++++++++++++++++++ src/initialize.F90 | 3 ++- src/main.F90 | 39 ++++++------------------------------ 5 files changed, 64 insertions(+), 35 deletions(-) create mode 100644 src/finalize.F90 diff --git a/src/DEPENDENCIES b/src/DEPENDENCIES index bdcbc62d06..d13f68d9dd 100644 --- a/src/DEPENDENCIES +++ b/src/DEPENDENCIES @@ -38,6 +38,12 @@ energy_grid.o: datatypes_header.o energy_grid.o: global.o energy_grid.o: output.o +finalize.o: global.o +finalize.o: hdf5_interface.o +finalize.o: output.o +finalize.o: tally.o +finalize.o: timing.o + fission.o: ace_header.o fission.o: constants.o fission.o: error.o @@ -121,7 +127,6 @@ interpolation.o: string.o main.o: constants.o main.o: global.o -main.o: hdf5_interface.o main.o: initialize.o main.o: intercycle.o main.o: output.o diff --git a/src/OBJECTS b/src/OBJECTS index 2cc565cf0e..f817f4cd5b 100644 --- a/src/OBJECTS +++ b/src/OBJECTS @@ -10,6 +10,7 @@ endf.o \ endf_header.o \ energy_grid.o \ error.o \ +finalize.o \ fission.o \ geometry.o \ geometry_header.o \ diff --git a/src/finalize.F90 b/src/finalize.F90 new file mode 100644 index 0000000000..7a4de9e86e --- /dev/null +++ b/src/finalize.F90 @@ -0,0 +1,49 @@ +module finalize + + use global + use output, only: print_runtime + use tally, only: write_tallies, tally_statistics + use timing, only: timer_stop + +#ifdef HDF5 + use hdf5_interface, only: write_hdf5_summary, close_hdf5_output +#endif + + implicit none + +contains + +!=============================================================================== +! FINALIZE_RUN +!=============================================================================== + + subroutine finalize_run() + + ! Calculate statistics for tallies and write to tallies.out + if (.not. plotting) then + call tally_statistics() + if (master) call write_tallies() + end if + + ! show timing statistics + call timer_stop(time_total) + if (master) call print_runtime() + +#ifdef HDF5 + if (master) then + call write_hdf5_summary() + call close_hdf5_output() + end if +#endif + + ! deallocate arrays + call free_memory() + +#ifdef MPI + ! If MPI is in use and enabled, terminate it + call MPI_FINALIZE(mpi_err) +#endif + + end subroutine finalize_run + +end module finalize diff --git a/src/initialize.F90 b/src/initialize.F90 index 86e6b1dba4..c2361d599d 100644 --- a/src/initialize.F90 +++ b/src/initialize.F90 @@ -46,7 +46,8 @@ contains type(Universe), pointer :: univ - ! Start initialization timer + ! Start total and initialization timer + call timer_start(time_total) call timer_start(time_initialize) ! Setup MPI diff --git a/src/main.F90 b/src/main.F90 index 7d651ace14..c712746e6b 100644 --- a/src/main.F90 +++ b/src/main.F90 @@ -2,32 +2,25 @@ program main use constants use global + use finalize, only: finalize_run use initialize, only: initialize_run use intercycle, only: shannon_entropy, calculate_keff, synchronize_bank - use output, only: write_message, header, print_runtime + use output, only: write_message, header use particle_header, only: Particle use plot, only: run_plot use physics, only: transport use random_lcg, only: set_particle_seed use source, only: get_source_particle use string, only: to_str - use tally, only: synchronize_tallies, write_tallies, & - tally_statistics + use tally, only: synchronize_tallies use timing, only: timer_start, timer_stop #ifdef MPI use mpi #endif -#ifdef HDF5 - use hdf5_interface, only: write_hdf5_summary, close_hdf5_output -#endif - implicit none - ! start timer for total run time - call timer_start(time_total) - ! set up problem call initialize_run() @@ -36,30 +29,10 @@ program main call run_plot() else call run_problem() - - ! Calculate statistics for tallies and write to tallies.out - call tally_statistics() - if (master) call write_tallies() - - ! show timing statistics - call timer_stop(time_total) - if (master) call print_runtime() end if - - ! deallocate arrays - call free_memory() - -#ifdef HDF5 - if (master) then - call write_hdf5_summary() - call close_hdf5_output() - end if -#endif - -#ifdef MPI - ! If MPI is in use and enabled, terminate it - call MPI_FINALIZE(mpi_err) -#endif + + ! finalize run + call finalize_run() contains