mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-27 13:45:36 -04:00
Remove thread_id and n_threads global variables
This commit is contained in:
parent
d980b4a5ea
commit
49bf4523c3
13 changed files with 37 additions and 81 deletions
|
|
@ -730,15 +730,6 @@ sections.
|
|||
|
||||
*Default*: 10 K
|
||||
|
||||
---------------------
|
||||
``<threads>`` Element
|
||||
---------------------
|
||||
|
||||
The ``<threads>`` element indicates the number of OpenMP threads to be used for
|
||||
a simulation. It has no attributes and accepts a positive integer value.
|
||||
|
||||
*Default*: None (Determined by environment variable :envvar:`OMP_NUM_THREADS`)
|
||||
|
||||
.. _trace:
|
||||
|
||||
-------------------
|
||||
|
|
|
|||
|
|
@ -44,12 +44,8 @@ extern std::vector<int64_t> work_index;
|
|||
|
||||
// Threadprivate variables
|
||||
extern "C" bool trace; //!< flag to show debug information
|
||||
#ifdef _OPENMP
|
||||
extern "C" int n_threads; //!< number of OpenMP threads
|
||||
extern "C" int thread_id; //!< ID of a given thread
|
||||
#endif
|
||||
|
||||
#pragma omp threadprivate(current_work, thread_id, trace)
|
||||
#pragma omp threadprivate(current_work, trace)
|
||||
|
||||
} // namespace simulation
|
||||
|
||||
|
|
|
|||
|
|
@ -130,8 +130,6 @@ class Settings(object):
|
|||
range. 'multipole' is a boolean indicating whether or not the windowed
|
||||
multipole method should be used to evaluate resolved resonance cross
|
||||
sections.
|
||||
threads : int
|
||||
Number of OpenMP threads
|
||||
trace : tuple or list
|
||||
Show detailed information about a single particle, indicated by three
|
||||
integers: the batch number, generation number, and particle number
|
||||
|
|
@ -197,7 +195,6 @@ class Settings(object):
|
|||
self._statepoint = {}
|
||||
self._sourcepoint = {}
|
||||
|
||||
self._threads = None
|
||||
self._no_reduce = None
|
||||
|
||||
self._verbosity = None
|
||||
|
|
@ -312,10 +309,6 @@ class Settings(object):
|
|||
def statepoint(self):
|
||||
return self._statepoint
|
||||
|
||||
@property
|
||||
def threads(self):
|
||||
return self._threads
|
||||
|
||||
@property
|
||||
def no_reduce(self):
|
||||
return self._no_reduce
|
||||
|
|
@ -623,12 +616,6 @@ class Settings(object):
|
|||
|
||||
self._temperature = temperature
|
||||
|
||||
@threads.setter
|
||||
def threads(self, threads):
|
||||
cv.check_type('number of threads', threads, Integral)
|
||||
cv.check_greater_than('number of threads', threads, 0)
|
||||
self._threads = threads
|
||||
|
||||
@trace.setter
|
||||
def trace(self, trace):
|
||||
cv.check_type('trace', trace, Iterable, Integral)
|
||||
|
|
@ -885,11 +872,6 @@ class Settings(object):
|
|||
else:
|
||||
element.text = str(value)
|
||||
|
||||
def _create_threads_subelement(self, root):
|
||||
if self._threads is not None:
|
||||
element = ET.SubElement(root, "threads")
|
||||
element.text = str(self._threads)
|
||||
|
||||
def _create_trace_subelement(self, root):
|
||||
if self._trace is not None:
|
||||
element = ET.SubElement(root, "trace")
|
||||
|
|
@ -980,7 +962,6 @@ class Settings(object):
|
|||
self._create_entropy_mesh_subelement(root_element)
|
||||
self._create_trigger_subelement(root_element)
|
||||
self._create_no_reduce_subelement(root_element)
|
||||
self._create_threads_subelement(root_element)
|
||||
self._create_verbosity_subelement(root_element)
|
||||
self._create_tabular_legendre_subelements(root_element)
|
||||
self._create_temperature_subelements(root_element)
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ std::vector<Particle::Bank> master_fission_bank;
|
|||
void free_memory_bank()
|
||||
{
|
||||
simulation::source_bank.clear();
|
||||
#pragma omp parallel
|
||||
#pragma omp parallel
|
||||
{
|
||||
simulation::fission_bank.clear();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,10 @@
|
|||
#include "openmc/timer.h"
|
||||
#include "openmc/tallies/tally.h"
|
||||
|
||||
#ifdef _OPENMP
|
||||
#include <omp.h>
|
||||
#endif
|
||||
|
||||
#include <algorithm> // for min
|
||||
#include <array>
|
||||
#include <cmath> // for sqrt, abs, pow
|
||||
|
|
@ -348,11 +352,13 @@ void calculate_average_keff()
|
|||
#ifdef _OPENMP
|
||||
void join_bank_from_threads()
|
||||
{
|
||||
int n_threads = omp_get_max_threads();
|
||||
|
||||
#pragma omp parallel
|
||||
{
|
||||
// Copy thread fission bank sites to one shared copy
|
||||
#pragma omp for ordered schedule(static)
|
||||
for (int i = 0; i < simulation::n_threads; ++i) {
|
||||
for (int i = 0; i < n_threads; ++i) {
|
||||
#pragma omp ordered
|
||||
{
|
||||
std::copy(
|
||||
|
|
@ -367,7 +373,7 @@ void join_bank_from_threads()
|
|||
#pragma omp barrier
|
||||
|
||||
// Now copy the shared fission bank sites back to the master thread's copy.
|
||||
if (simulation::thread_id == 0) {
|
||||
if (omp_get_thread_num() == 0) {
|
||||
simulation::fission_bank = simulation::master_fission_bank;
|
||||
simulation::master_fission_bank.clear();
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -196,13 +196,13 @@ parse_command_line(int argc, char* argv[])
|
|||
|
||||
#ifdef _OPENMP
|
||||
// Read and set number of OpenMP threads
|
||||
simulation::n_threads = std::stoi(argv[i]);
|
||||
if (simulation::n_threads < 1) {
|
||||
int n_threads = std::stoi(argv[i]);
|
||||
if (n_threads < 1) {
|
||||
std::string msg {"Number of threads must be positive."};
|
||||
strcpy(openmc_err_msg, msg.c_str());
|
||||
return OPENMC_E_INVALID_ARGUMENT;
|
||||
}
|
||||
omp_set_num_threads(simulation::n_threads);
|
||||
omp_set_num_threads(n_threads);
|
||||
#else
|
||||
if (mpi::master)
|
||||
warning("Ignoring number of threads specified on command line.");
|
||||
|
|
|
|||
|
|
@ -11,7 +11,9 @@
|
|||
#include <unordered_map>
|
||||
#include <utility> // for pair
|
||||
|
||||
#ifdef _OPENMP
|
||||
#include <omp.h>
|
||||
#endif
|
||||
#include "xtensor/xview.hpp"
|
||||
|
||||
#include "openmc/capi.h"
|
||||
|
|
|
|||
|
|
@ -590,7 +590,7 @@ Particle::mark_as_lost(const char* message)
|
|||
|
||||
// Increment number of lost particles
|
||||
alive_ = false;
|
||||
#pragma omp atomic
|
||||
#pragma omp atomic
|
||||
simulation::n_lost_particles += 1;
|
||||
|
||||
// Count the total number of simulated particles (on this processor)
|
||||
|
|
@ -615,7 +615,7 @@ Particle::write_restart() const
|
|||
filename << settings::path_output << "particle_" << simulation::current_batch
|
||||
<< '_' << id_ << ".h5";
|
||||
|
||||
#pragma omp critical (WriteParticleRestart)
|
||||
#pragma omp critical (WriteParticleRestart)
|
||||
{
|
||||
// Create file
|
||||
hid_t file_id = file_open(filename.str(), 'w');
|
||||
|
|
|
|||
|
|
@ -174,22 +174,19 @@ absorption(Particle* p)
|
|||
{
|
||||
if (settings::survival_biasing) {
|
||||
// Determine weight absorbed in survival biasing
|
||||
p->wgt_absorb_ = p->wgt_ *
|
||||
p->macro_xs_.absorption / p->macro_xs_.total;
|
||||
p->wgt_absorb_ = p->wgt_ * p->macro_xs_.absorption / p->macro_xs_.total;
|
||||
|
||||
// Adjust weight of particle by the probability of absorption
|
||||
p->wgt_ -= p->wgt_absorb_;
|
||||
p->wgt_last_ = p->wgt_;
|
||||
|
||||
// Score implicit absorpion estimate of keff
|
||||
#pragma omp atomic
|
||||
global_tally_absorption += p->wgt_absorb_ *
|
||||
p->macro_xs_.nu_fission /
|
||||
p->macro_xs_.absorption;
|
||||
#pragma omp atomic
|
||||
global_tally_absorption += p->wgt_absorb_ * p->macro_xs_.nu_fission /
|
||||
p->macro_xs_.absorption;
|
||||
} else {
|
||||
if (p->macro_xs_.absorption >
|
||||
prn() * p->macro_xs_.total) {
|
||||
#pragma omp atomic
|
||||
if (p->macro_xs_.absorption > prn() * p->macro_xs_.total) {
|
||||
#pragma omp atomic
|
||||
global_tally_absorption += p->wgt_ * p->macro_xs_.nu_fission /
|
||||
p->macro_xs_.absorption;
|
||||
p->alive_ = false;
|
||||
|
|
|
|||
|
|
@ -141,7 +141,7 @@ extern "C" void
|
|||
openmc_set_seed(int64_t new_seed)
|
||||
{
|
||||
seed = new_seed;
|
||||
#pragma omp parallel
|
||||
#pragma omp parallel
|
||||
{
|
||||
for (int i = 0; i < N_STREAMS; i++) {
|
||||
prn_seed[i] = seed + i;
|
||||
|
|
|
|||
|
|
@ -383,20 +383,8 @@ void read_settings_xml()
|
|||
|
||||
// Number of OpenMP threads
|
||||
if (check_for_node(root, "threads")) {
|
||||
#ifdef _OPENMP
|
||||
if (simulation::n_threads == 0) {
|
||||
simulation::n_threads = std::stoi(get_node_value(root, "threads"));
|
||||
if (simulation::n_threads < 1) {
|
||||
std::stringstream msg;
|
||||
msg << "Invalid number of threads: " << simulation::n_threads;
|
||||
fatal_error(msg);
|
||||
}
|
||||
omp_set_num_threads(simulation::n_threads);
|
||||
}
|
||||
#else
|
||||
if (mpi::master) warning("OpenMC was not compiled with OpenMP support; "
|
||||
"ignoring number of threads.");
|
||||
#endif
|
||||
if (mpi::master) warning("The <threads> element has been deprecated. Use "
|
||||
"the OMP_NUM_THREADS environment variable to set the number of threads.");
|
||||
}
|
||||
|
||||
// ==========================================================================
|
||||
|
|
|
|||
|
|
@ -20,7 +20,9 @@
|
|||
#include "openmc/tallies/tally.h"
|
||||
#include "openmc/tallies/trigger.h"
|
||||
|
||||
#ifdef _OPENMP
|
||||
#include <omp.h>
|
||||
#endif
|
||||
#include "xtensor/xview.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
|
|
@ -59,7 +61,7 @@ int openmc_simulation_init()
|
|||
calculate_work();
|
||||
|
||||
// Allocate array for matching filter bins
|
||||
#pragma omp parallel
|
||||
#pragma omp parallel
|
||||
{
|
||||
simulation::filter_matches.resize(model::tally_filters.size());
|
||||
}
|
||||
|
|
@ -136,7 +138,7 @@ int openmc_simulation_finalize()
|
|||
// Write tally results to tallies.out
|
||||
if (settings::output_tallies && mpi::master) write_tallies();
|
||||
|
||||
#pragma omp parallel
|
||||
#pragma omp parallel
|
||||
{
|
||||
simulation::filter_matches.clear();
|
||||
}
|
||||
|
|
@ -186,7 +188,7 @@ int openmc_next_batch(int* status)
|
|||
// ====================================================================
|
||||
// LOOP OVER PARTICLES
|
||||
|
||||
#pragma omp parallel for schedule(runtime)
|
||||
#pragma omp parallel for schedule(runtime)
|
||||
for (int64_t i_work = 1; i_work <= simulation::work; ++i_work) {
|
||||
simulation::current_work = i_work;
|
||||
|
||||
|
|
@ -250,10 +252,6 @@ std::vector<int64_t> work_index;
|
|||
|
||||
// Threadprivate variables
|
||||
bool trace; //!< flag to show debug information
|
||||
#ifdef _OPENMP
|
||||
int n_threads {-1}; //!< number of OpenMP threads
|
||||
int thread_id; //!< ID of a given thread
|
||||
#endif
|
||||
|
||||
} // namespace simulation
|
||||
|
||||
|
|
@ -273,15 +271,13 @@ void allocate_banks()
|
|||
// a generation, there is also a 'master_fission_bank' that is used to
|
||||
// collect the sites from each thread.
|
||||
|
||||
simulation::n_threads = omp_get_max_threads();
|
||||
|
||||
#pragma omp parallel
|
||||
#pragma omp parallel
|
||||
{
|
||||
simulation::thread_id = omp_get_thread_num();
|
||||
if (simulation::thread_id == 0) {
|
||||
if (omp_get_thread_num() == 0) {
|
||||
simulation::fission_bank.reserve(3*simulation::work);
|
||||
} else {
|
||||
simulation::fission_bank.reserve(3*simulation::work / simulation::n_threads);
|
||||
int n_threads = omp_get_num_threads();
|
||||
simulation::fission_bank.reserve(3*simulation::work / n_threads);
|
||||
}
|
||||
}
|
||||
simulation::master_fission_bank.reserve(3*simulation::work);
|
||||
|
|
@ -403,9 +399,9 @@ void finalize_generation()
|
|||
auto& gt = simulation::global_tallies;
|
||||
|
||||
// Update global tallies with the omp private accumulation variables
|
||||
#pragma omp parallel
|
||||
#pragma omp parallel
|
||||
{
|
||||
#pragma omp critical(increment_global_tallies)
|
||||
#pragma omp critical(increment_global_tallies)
|
||||
{
|
||||
if (settings::run_mode == RUN_MODE_EIGENVALUE) {
|
||||
gt(K_COLLISION, RESULT_VALUE) += global_tally_collision;
|
||||
|
|
|
|||
|
|
@ -36,7 +36,6 @@ def test_export_to_xml(run_in_tmpdir):
|
|||
s.tabular_legendre = {'enable': True, 'num_points': 50}
|
||||
s.temperature = {'default': 293.6, 'method': 'interpolation',
|
||||
'multipole': True, 'range': (200., 1000.)}
|
||||
s.threads = 8
|
||||
s.trace = (10, 1, 20)
|
||||
s.track = [1, 1, 1, 2, 1, 1]
|
||||
s.ufs_mesh = mesh
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue