Continue withering away openmc_init

This commit is contained in:
Paul Romano 2017-08-17 14:53:12 -05:00
parent ab2417575e
commit 9caf6d6611
3 changed files with 117 additions and 125 deletions

View file

@ -21,14 +21,11 @@ module initialize
use material_header, only: Material
use message_passing
use mgxs_data, only: read_mgxs, create_macro_xs
use output, only: print_version, write_message, print_usage, &
print_plot
use output, only: print_version, write_message, print_usage
use random_lcg, only: initialize_prng
use string, only: to_str, starts_with, ends_with, str_to_int
use summary, only: write_summary
use tally_header, only: TallyObject
use tally_filter
use tally, only: init_tally_routines
implicit none
@ -87,37 +84,9 @@ contains
! Read XML input files
call read_input_xml()
if (run_mode /= MODE_PLOTTING) then
! Set up tally procedure pointers
call init_tally_routines()
! Determine how much work each processor should do
call calculate_work()
! Allocate source bank, and for eigenvalue simulations also allocate the
! fission bank
call allocate_banks()
end if
if (master) then
if (run_mode == MODE_PLOTTING) then
! Display plotting information
if (verbosity >= 5) call print_plot()
else
! Write summary information
if (output_summary) call write_summary()
end if
end if
! Check for particle restart run
if (particle_restart_run) run_mode = MODE_PARTICLE
! Warn if overlap checking is on
if (master .and. check_overlaps .and. run_mode /= MODE_PLOTTING) then
call warning("Cell overlap checking is ON.")
end if
! Stop initialization timer
call time_initialize%stop()
@ -389,91 +358,4 @@ contains
end subroutine read_command_line
!===============================================================================
! CALCULATE_WORK determines how many particles each processor should simulate
!===============================================================================
subroutine calculate_work()
integer :: i ! loop index
integer :: remainder ! Number of processors with one extra particle
integer(8) :: i_bank ! Running count of number of particles
integer(8) :: min_work ! Minimum number of particles on each proc
integer(8) :: work_i ! Number of particles on rank i
allocate(work_index(0:n_procs))
! Determine minimum amount of particles to simulate on each processor
min_work = n_particles/n_procs
! Determine number of processors that have one extra particle
remainder = int(mod(n_particles, int(n_procs,8)), 4)
i_bank = 0
work_index(0) = 0
do i = 0, n_procs - 1
! Number of particles for rank i
if (i < remainder) then
work_i = min_work + 1
else
work_i = min_work
end if
! Set number of particles
if (rank == i) work = work_i
! Set index into source bank for rank i
i_bank = i_bank + work_i
work_index(i+1) = i_bank
end do
end subroutine calculate_work
!===============================================================================
! ALLOCATE_BANKS allocates memory for the fission and source banks
!===============================================================================
subroutine allocate_banks()
integer :: alloc_err ! allocation error code
! Allocate source bank
allocate(source_bank(work), STAT=alloc_err)
! Check for allocation errors
if (alloc_err /= 0) then
call fatal_error("Failed to allocate source bank.")
end if
if (run_mode == MODE_EIGENVALUE) then
#ifdef _OPENMP
! If OpenMP is being used, each thread needs its own private fission
! bank. Since the private fission banks need to be combined at the end of
! a generation, there is also a 'master_fission_bank' that is used to
! collect the sites from each thread.
n_threads = omp_get_max_threads()
!$omp parallel
thread_id = omp_get_thread_num()
if (thread_id == 0) then
allocate(fission_bank(3*work))
else
allocate(fission_bank(3*work/n_threads))
end if
!$omp end parallel
allocate(master_fission_bank(3*work), STAT=alloc_err)
#else
allocate(fission_bank(3*work), STAT=alloc_err)
#endif
! Check for allocation errors
if (alloc_err /= 0) then
call fatal_error("Failed to allocate fission bank.")
end if
end if
end subroutine allocate_banks
end module initialize

View file

@ -23,7 +23,7 @@ module input_xml
use mgxs_data, only: create_macro_xs, read_mgxs
use mgxs_header
use multipole, only: multipole_read
use output, only: write_message, title, header
use output, only: write_message, title, header, print_plot
use plot_header
use random_lcg, only: prn, seed, initialize_prng
use surface_header
@ -32,6 +32,7 @@ module input_xml
use string, only: to_lower, to_str, str_to_int, str_to_real, &
starts_with, ends_with, tokenize, split_string, &
zero_padded
use summary, only: write_summary
use tally_header, only: openmc_extend_tallies, openmc_tally_set_type
use tally_filter_header, only: TallyFilterContainer
use tally_filter
@ -83,11 +84,22 @@ contains
call time_read_xs % stop()
end if
! Normalize atom/weight percents
if (run_mode /= MODE_PLOTTING) call normalize_ao()
if (run_mode == MODE_PLOTTING) then
! Read plots.xml if it exists
call read_plots_xml()
if (master .and. verbosity >= 5) call print_plot()
! Read plots.xml if it exists
if (run_mode == MODE_PLOTTING) call read_plots_xml()
else
! Normalize atom/weight percents
call normalize_ao()
! Write summary information
if (master .and. output_summary) call write_summary()
! Warn if overlap checking is on
if (master .and. check_overlaps) &
call warning("Cell overlap checking is ON.")
end if
end subroutine read_input_xml

View file

@ -20,7 +20,8 @@ module simulation
use source, only: initialize_source, sample_external_source
use state_point, only: write_state_point, write_source_point, load_state_point
use string, only: to_str
use tally, only: accumulate_tallies, setup_active_tallies
use tally, only: accumulate_tallies, setup_active_tallies, &
init_tally_routines
use tally_header, only: configure_tallies
use trigger, only: check_triggers
use tracking, only: transport
@ -372,6 +373,16 @@ contains
subroutine initialize_simulation()
! Set up tally procedure pointers
call init_tally_routines()
! Determine how much work each processor should do
call calculate_work()
! Allocate source bank, and for eigenvalue simulations also allocate the
! fission bank
call allocate_banks()
! Allocate tally results arrays if they're not allocated yet
call configure_tallies()
@ -473,4 +484,91 @@ contains
end subroutine finalize_simulation
!===============================================================================
! CALCULATE_WORK determines how many particles each processor should simulate
!===============================================================================
subroutine calculate_work()
integer :: i ! loop index
integer :: remainder ! Number of processors with one extra particle
integer(8) :: i_bank ! Running count of number of particles
integer(8) :: min_work ! Minimum number of particles on each proc
integer(8) :: work_i ! Number of particles on rank i
allocate(work_index(0:n_procs))
! Determine minimum amount of particles to simulate on each processor
min_work = n_particles/n_procs
! Determine number of processors that have one extra particle
remainder = int(mod(n_particles, int(n_procs,8)), 4)
i_bank = 0
work_index(0) = 0
do i = 0, n_procs - 1
! Number of particles for rank i
if (i < remainder) then
work_i = min_work + 1
else
work_i = min_work
end if
! Set number of particles
if (rank == i) work = work_i
! Set index into source bank for rank i
i_bank = i_bank + work_i
work_index(i+1) = i_bank
end do
end subroutine calculate_work
!===============================================================================
! ALLOCATE_BANKS allocates memory for the fission and source banks
!===============================================================================
subroutine allocate_banks()
integer :: alloc_err ! allocation error code
! Allocate source bank
allocate(source_bank(work), STAT=alloc_err)
! Check for allocation errors
if (alloc_err /= 0) then
call fatal_error("Failed to allocate source bank.")
end if
if (run_mode == MODE_EIGENVALUE) then
#ifdef _OPENMP
! If OpenMP is being used, each thread needs its own private fission
! bank. Since the private fission banks need to be combined at the end of
! a generation, there is also a 'master_fission_bank' that is used to
! collect the sites from each thread.
n_threads = omp_get_max_threads()
!$omp parallel
thread_id = omp_get_thread_num()
if (thread_id == 0) then
allocate(fission_bank(3*work))
else
allocate(fission_bank(3*work/n_threads))
end if
!$omp end parallel
allocate(master_fission_bank(3*work), STAT=alloc_err)
#else
allocate(fission_bank(3*work), STAT=alloc_err)
#endif
! Check for allocation errors
if (alloc_err /= 0) then
call fatal_error("Failed to allocate fission bank.")
end if
end if
end subroutine allocate_banks
end module simulation