From fa3b28f737b28ca3615a37387e72c565498d1b94 Mon Sep 17 00:00:00 2001 From: Sterling Harper Date: Sat, 26 Mar 2016 13:49:41 -0400 Subject: [PATCH] Output timing results in statepoint files --- docs/source/usersguide/output/statepoint.rst | 70 +++++++++++++++++++- openmc/statepoint.py | 19 ++++-- src/constants.F90 | 2 +- src/state_point.F90 | 48 +++++++++++--- 4 files changed, 123 insertions(+), 16 deletions(-) diff --git a/docs/source/usersguide/output/statepoint.rst b/docs/source/usersguide/output/statepoint.rst index 2251619653..48313aff3f 100644 --- a/docs/source/usersguide/output/statepoint.rst +++ b/docs/source/usersguide/output/statepoint.rst @@ -4,7 +4,7 @@ State Point File Format ======================= -The current revision of the statepoint file format is 15. +The current revision of the statepoint file format is 16. **/filetype** (*char[]*) @@ -248,7 +248,7 @@ if run_mode == 'k-eigenvalue': Accumulated sum and sum-of-squares for each global tally. The compound type has fields named ``sum`` and ``sum_sq``. -**tallies_present** (*int*) +**/tallies_present** (*int*) Flag indicated if tallies are present in the file. @@ -260,3 +260,69 @@ if (run_mode == 'k-eigenvalue' and source_present > 0) ``wgt``, ``xyz``, ``uvw``, ``E``, ``g``, and ``delayed_group``, which represent the weight, position, direction, energy, energy group, and delayed_group of the source particle, respectively. + +**/runtime/total initialization** (*double*) + + Time (in seconds on the master processor) spent reading inputs, allocating + arrays, etc. + +**/runtime/reading cross sections** (*double*) + + Time (in seconds on the master processor) spent loading cross section + libraries (this is a subset of initialization). + +**/runtime/simulation** (*double*) + + Time (in seconds on the master processor) spent between initialization and + finalization. + +**/runtime/transport** (*double*) + + Time (in seconds on the master processor) spent transporting particles. + +**/runtime/inactive batches** (*double*) + + Time (in seconds on the master processor) spent in the inactive batches + (including non-transport activities like communcating sites). + +**/runtime/active batches** (*double*) + + Time (in seconds on the master processor) spent in the active batches + (including non-transport activities like communcating sites). + +**/runtime/synchronizing fission bank** (*double*) + + Time (in seconds on the master processor) spent sampling source particles + from fission sites and communicating them to other processes for load + balancing. + +**/runtime/sampling source sites** (*double*) + + Time (in seconds on the master processor) spent sampling source particles + from fission sites. + +**/runtime/SEND-RECV source sites** (*double*) + + Time (in seconds on the master processor) spent communicating source sites + between processes for load balancing. + +**/runtime/accumulating tallies** (*double*) + + Time (in seconds on the master processor) spent communicating tally results + and evaluating their statistics. + +**/runtime/CMFD** (*double*) + + Time (in seconds on the master processor) spent evaluating CMFD. + +**/runtime/CMFD building matrices** (*double*) + + Time (in seconds on the master processor) spent buliding CMFD matrices. + +**/runtime/CMFD solving matrices** (*double*) + + Time (in seconds on the master processor) spent solving CMFD matrices. + +**/runtime/total** (*double*) + + Total time spent (in seconds on the master processor) in the program. diff --git a/openmc/statepoint.py b/openmc/statepoint.py index 1644e44ab4..0460192c4c 100644 --- a/openmc/statepoint.py +++ b/openmc/statepoint.py @@ -68,6 +68,9 @@ class StatePoint(object): Working directory for simulation run_mode : str Simulation run mode, e.g. 'k-eigenvalue' + runtime : dict + Dictionary whose keys are strings describing various runtime metrics + and whose values are time values in seconds. seed : Integral Pseudorandom number generator seed source : ndarray of compound datatype @@ -101,13 +104,14 @@ class StatePoint(object): raise IOError('{} is not a statepoint file.'.format(filename)) except AttributeError: raise IOError('Could not read statepoint file. This most likely ' - 'means the statepoint file was produced by a different ' - 'version of OpenMC than the one you are using.') - if self._f['revision'].value != 15: + 'means the statepoint file was produced by a ' + 'different version of OpenMC than the one you are ' + 'using.') + if self._f['revision'].value != 16: raise IOError('Statepoint file has a file revision of {} ' 'which is not consistent with the revision this ' 'version of OpenMC expects ({}).'.format( - self._f['revision'].value, 15)) + self._f['revision'].value, 16)) # Set flags for what data has been read self._meshes_read = False @@ -311,6 +315,13 @@ class StatePoint(object): def run_mode(self): return self._f['run_mode'].value.decode() + @property + def runtime(self): + out = dict() + for key in self._f['runtime'].keys(): + out[key] = self._f['runtime/' + key].value + return out + @property def seed(self): return self._f['seed'].value diff --git a/src/constants.F90 b/src/constants.F90 index 8863ca18c4..473d28af63 100644 --- a/src/constants.F90 +++ b/src/constants.F90 @@ -11,7 +11,7 @@ module constants integer, parameter :: VERSION_RELEASE = 1 ! Revision numbers for binary files - integer, parameter :: REVISION_STATEPOINT = 15 + integer, parameter :: REVISION_STATEPOINT = 16 integer, parameter :: REVISION_PARTICLE_RESTART = 1 integer, parameter :: REVISION_TRACK = 1 integer, parameter :: REVISION_SUMMARY = 3 diff --git a/src/state_point.F90 b/src/state_point.F90 index d8d796d909..4348ad3314 100644 --- a/src/state_point.F90 +++ b/src/state_point.F90 @@ -49,10 +49,8 @@ contains integer, allocatable :: id_array(:) integer, allocatable :: key_array(:) integer(HID_T) :: file_id - integer(HID_T) :: cmfd_group - integer(HID_T) :: tallies_group, tally_group - integer(HID_T) :: meshes_group, mesh_group - integer(HID_T) :: filter_group + integer(HID_T) :: cmfd_group, tallies_group, tally_group, meshes_group, & + mesh_group, filter_group, runtime_group character(20), allocatable :: str_array(:) character(MAX_FILE_LEN) :: filename type(RegularMesh), pointer :: meshp @@ -405,13 +403,45 @@ contains end if call close_group(tallies_group) + + ! Write out the runtime metrics. + runtime_group = create_group(file_id, "runtime") + call write_dataset(runtime_group, "total initialization", & + time_initialize % get_value()) + call write_dataset(runtime_group, "reading cross sections", & + time_read_xs % get_value()) + call write_dataset(runtime_group, "simulation", & + time_inactive % get_value() + time_active % get_value()) + call write_dataset(runtime_group, "transport", & + time_transport % get_value()) + if (run_mode == MODE_EIGENVALUE) then + call write_dataset(runtime_group, "inactive batches", & + time_inactive % get_value()) + end if + call write_dataset(runtime_group, "active batches", & + time_active % get_value()) + if (run_mode == MODE_EIGENVALUE) then + call write_dataset(runtime_group, "synchronizing fission bank", & + time_bank % get_value()) + call write_dataset(runtime_group, "sampling source sites", & + time_bank_sample % get_value()) + call write_dataset(runtime_group, "SEND-RECV source sites", & + time_bank_sendrecv % get_value()) + end if + call write_dataset(runtime_group, "accumulating tallies", & + time_tallies % get_value()) + if (cmfd_run) then + call write_dataset(runtime_group, "CMFD", time_cmfd % get_value()) + call write_dataset(runtime_group, "CMFD building matrices", & + time_cmfdbuild % get_value()) + call write_dataset(runtime_group, "CMFD solving matrices", & + time_cmfdsolve % get_value()) + end if + call write_dataset(runtime_group, "total", time_total % get_value()) + call close_group(runtime_group) + call file_close(file_id) end if - - if (master .and. n_tallies > 0) then - deallocate(id_array) - end if - end subroutine write_state_point !===============================================================================