From 02470bc630cb15c7a5a72f92a6c6a2dc4d1aa44c Mon Sep 17 00:00:00 2001 From: John Tramm Date: Mon, 27 Jan 2020 17:02:39 +0000 Subject: [PATCH] Incorporation of comments from code review. --- docs/source/io_formats/settings.rst | 8 +++---- include/openmc/settings.h | 4 ++-- include/openmc/shared_array.h | 20 ++++++++-------- openmc/settings.py | 36 ++++++++++++++--------------- src/relaxng/settings.rnc | 2 +- src/relaxng/settings.rng | 2 +- src/settings.cpp | 8 +++---- src/simulation.cpp | 4 ++-- 8 files changed, 43 insertions(+), 41 deletions(-) diff --git a/docs/source/io_formats/settings.rst b/docs/source/io_formats/settings.rst index d14a57667..2e2648237 100644 --- a/docs/source/io_formats/settings.rst +++ b/docs/source/io_formats/settings.rst @@ -142,7 +142,7 @@ materials in the problem and is specified using a :ref:`mesh_element`. ---------------------------- Determines whether to use event-based parallelism instead of the default -history based parallelism. +history-based parallelism. *Default*: false @@ -227,9 +227,9 @@ to false. *Default*: true ------------------------ -```` Element ------------------------ +---------------------------------------- +```` Element +---------------------------------------- This element indicates the number of neutrons to run in flight concurrently when using event-based parallelism. A higher value uses more memory, but diff --git a/include/openmc/settings.h b/include/openmc/settings.h index 65b4266bc..cbc0c488b 100644 --- a/include/openmc/settings.h +++ b/include/openmc/settings.h @@ -31,6 +31,7 @@ extern "C" bool cmfd_run; //!< is a CMFD run? extern "C" bool dagmc; //!< indicator of DAGMC geometry extern bool delayed_photon_scaling; //!< Scale fission photon yield to include delayed extern "C" bool entropy_on; //!< calculate Shannon entropy? +extern bool event_based; //!< use event-based mode (instead of history-based) extern bool legendre_to_tabular; //!< convert Legendre distributions to tabular? extern bool material_cell_offsets; //!< create material cells offsets? extern "C" bool output_summary; //!< write summary.h5? @@ -52,7 +53,6 @@ extern bool ufs_on; //!< uniform fission site method on? extern bool urr_ptables_on; //!< use unresolved resonance prob. tables? extern bool write_all_tracks; //!< write track files for every particle? extern bool write_initial_source; //!< write out initial source file? -extern bool event_based; //!< use event-based mode (instead of history-based) // Paths to various files extern std::string path_cross_sections; //!< path to cross_sections.xml @@ -69,7 +69,7 @@ extern "C" int32_t gen_per_batch; //!< number of generations per batch extern "C" int64_t n_particles; //!< number of particles per generation -extern "C" int64_t max_in_flight_particles; //!< Max num. event-based particles in flight +extern int64_t max_particles_in_flight; //!< Max num. event-based particles in flight extern ElectronTreatment electron_treatment; //!< how to treat secondary electrons extern std::array energy_cutoff; //!< Energy cutoff in [eV] for each particle type diff --git a/include/openmc/shared_array.h b/include/openmc/shared_array.h index 8d08ae3aa..c473143ae 100644 --- a/include/openmc/shared_array.h +++ b/include/openmc/shared_array.h @@ -4,7 +4,7 @@ //! \file shared_array.h //! \brief Shared array data structure -#include +#include namespace openmc { @@ -24,14 +24,6 @@ namespace openmc { template class SharedArray { -private: - //========================================================================== - // Data members - - std::unique_ptr data_; //!< A pointer to hold the data - int64_t size_ {0}; //!< The current size of the SharedArray. - int64_t capacity_ {0}; //!< The maximum capacity of the SharedArray. - public: //========================================================================== // Constructors @@ -55,6 +47,7 @@ public: //! Return a reference to the element at specified location i. No bounds //! checking is performed. T& operator[](int64_t i) {return data_[i];} + const T& operator[](int64_t i) const { return data_[i]; } //! Allocate space in the container for the specified number of elements. //! reserve() does not change the size of the container. @@ -116,6 +109,15 @@ public: //! Return pointer to the underlying array serving as element storage. T* data() {return data_.get();} + const T* data() const {return data_.get();} + +private: + //========================================================================== + // Data members + + std::unique_ptr data_; //!< A pointer to hold the data + int64_t size_ {0}; //!< The current size of the SharedArray. + int64_t capacity_ {0}; //!< The maximum capacity of the SharedArray. }; diff --git a/openmc/settings.py b/openmc/settings.py index 80f679a01..3730d7bd7 100644 --- a/openmc/settings.py +++ b/openmc/settings.py @@ -71,7 +71,7 @@ class Settings(object): material_cell_offsets : bool Generate an "offset table" for material cells by default. These tables are necessary when a particular instance of a cell needs to be tallied. - max_in_flight_particles : int + max_particles_in_flight : int Number of neutrons to run concurrently when using event-based parallelism. max_order : None or int @@ -236,7 +236,7 @@ class Settings(object): self._dagmc = False self._event_based = None - self._max_in_flight_particles = None + self._max_particles_in_flight = None @property def run_mode(self): @@ -391,8 +391,8 @@ class Settings(object): return self._event_based @property - def max_in_flight_particles(self): - return self._max_in_flight_particles + def max_particles_in_flight(self): + return self._max_particles_in_flight @run_mode.setter def run_mode(self, run_mode): @@ -727,11 +727,11 @@ class Settings(object): cv.check_type('event based', value, bool) self._event_based = value - @max_in_flight_particles.setter - def max_in_flight_particles(self, value): - cv.check_type('max in flight particles', value, Integral) - cv.check_greater_than('max in flight particles', value, 0) - self._max_in_flight_particles = value + @max_particles_in_flight.setter + def max_particles_in_flight(self, value): + cv.check_type('max particles in flight', value, Integral) + cv.check_greater_than('max particles in flight', value, 0) + self._max_particles_in_flight = value @material_cell_offsets.setter def material_cell_offsets(self, value): @@ -982,10 +982,10 @@ class Settings(object): elem = ET.SubElement(root, "event_based") elem.text = str(self._event_based).lower() - def _create_max_in_flight_particles_subelement(self, root): - if self._max_in_flight_particles is not None: - elem = ET.SubElement(root, "max_in_flight_particles") - elem.text = str(self._max_in_flight_particles).lower() + def _create_max_particles_in_flight_subelement(self, root): + if self._max_particles_in_flight is not None: + elem = ET.SubElement(root, "max_particles_in_flight") + elem.text = str(self._max_particles_in_flight).lower() def _create_material_cell_offsets_subelement(self, root): if self._material_cell_offsets is not None: @@ -1233,10 +1233,10 @@ class Settings(object): if text is not None: self.event_based = text in ('true', '1') - def _max_in_flight_particles_from_xml_element(self, root): - text = get_text(root, 'max_in_flight_particles') + def _max_particles_in_flight_from_xml_element(self, root): + text = get_text(root, 'max_particles_in_flight') if text is not None: - self.max_in_flight_particles = int(text) + self.max_particles_in_flight = int(text) def _material_cell_offsets_from_xml_element(self, root): text = get_text(root, 'material_cell_offsets') @@ -1299,7 +1299,7 @@ class Settings(object): self._create_create_fission_neutrons_subelement(root_element) self._create_delayed_photon_scaling_subelement(root_element) self._create_event_based_subelement(root_element) - self._create_max_in_flight_particles_subelement(root_element) + self._create_max_particles_in_flight_subelement(root_element) self._create_material_cell_offsets_subelement(root_element) self._create_log_grid_bins_subelement(root_element) self._create_dagmc_subelement(root_element) @@ -1368,7 +1368,7 @@ class Settings(object): settings._create_fission_neutrons_from_xml_element(root) settings._delayed_photon_scaling_from_xml_element(root) settings._event_based_from_xml_element(root) - settings._max_in_flight_particles_from_xml_element(root) + settings._max_particles_in_flight_from_xml_element(root) settings._material_cell_offsets_from_xml_element(root) settings._log_grid_bins_from_xml_element(root) settings._dagmc_from_xml_element(root) diff --git a/src/relaxng/settings.rnc b/src/relaxng/settings.rnc index 8fcb61670..94347f864 100644 --- a/src/relaxng/settings.rnc +++ b/src/relaxng/settings.rnc @@ -39,7 +39,7 @@ element settings { element material_cell_offsets { xsd:boolean }? & - element max_in_flight_particles { xsd:positiveInteger }? & + element max_particles_in_flight { xsd:positiveInteger }? & element max_order { xsd:nonNegativeInteger }? & diff --git a/src/relaxng/settings.rng b/src/relaxng/settings.rng index 6cb080670..ab6dcc328 100644 --- a/src/relaxng/settings.rng +++ b/src/relaxng/settings.rng @@ -93,7 +93,7 @@ - + diff --git a/src/settings.cpp b/src/settings.cpp index aeb095dff..8251a39dc 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -82,7 +82,7 @@ int32_t n_inactive {0}; int32_t gen_per_batch {1}; int64_t n_particles {-1}; -int64_t max_in_flight_particles {100000}; +int64_t max_particles_in_flight {100000}; ElectronTreatment electron_treatment {ElectronTreatment::TTB}; std::array energy_cutoff {0.0, 1000.0, 0.0, 0.0}; @@ -132,9 +132,9 @@ void get_run_parameters(pugi::xml_node node_base) } // Get maximum number of in flight particles for event-based mode - if (check_for_node(node_base, "max_in_flight_particles")) { - max_in_flight_particles = std::stoll(get_node_value(node_base, - "max_in_flight_particles")); + if (check_for_node(node_base, "max_particles_in_flight")) { + max_particles_in_flight = std::stoll(get_node_value(node_base, + "max_particles_in_flight")); } // Get number of basic batches diff --git a/src/simulation.cpp b/src/simulation.cpp index 495080472..086d74059 100644 --- a/src/simulation.cpp +++ b/src/simulation.cpp @@ -77,7 +77,7 @@ int openmc_simulation_init() // and event queues if (settings::event_based) { int64_t event_buffer_length = std::min(simulation::work_per_rank, - settings::max_in_flight_particles); + settings::max_particles_in_flight); init_event_queues(event_buffer_length); } @@ -617,7 +617,7 @@ void transport_event_based() // loop is executed multiple times until all particles have been completed. while (remaining_work > 0) { // Figure out # of particles to run for this subiteration - int64_t n_particles = std::min(remaining_work, settings::max_in_flight_particles); + int64_t n_particles = std::min(remaining_work, settings::max_particles_in_flight); // Initialize all particle histories for this subiteration process_init_events(n_particles, source_offset);