Moved current_work variable to particle object, and removed threadprivate tag from tally_derivs

This commit is contained in:
John Tramm 2019-12-11 21:58:19 +00:00
parent 70c9b7dd51
commit 1bb03f004a
9 changed files with 11 additions and 34 deletions

View file

@ -22,13 +22,6 @@ namespace simulation {
extern std::vector<Particle::Bank> source_bank;
extern std::vector<Particle::Bank> fission_bank;
//extern std::vector<Particle::Bank> secondary_bank;
#ifdef _OPENMP
extern std::vector<Particle::Bank> master_fission_bank;
#endif
//#pragma omp threadprivate(fission_bank, secondary_bank)
#pragma omp threadprivate(fission_bank)
} // namespace simulation

View file

@ -311,6 +311,8 @@ public:
// Secondary bank
std::vector<Particle::Bank> secondary_bank_;
int64_t current_work_; // current work index
};
} // namespace openmc

View file

@ -28,7 +28,6 @@ namespace simulation {
extern "C" int current_batch; //!< current batch
extern "C" int current_gen; //!< current fission generation
extern "C" int64_t current_work; //!< index in source back of current particle
extern "C" bool initialized; //!< has simulation been initialized?
extern "C" double keff; //!< average k over batches
extern "C" double keff_std; //!< standard deviation of average k
@ -53,7 +52,7 @@ extern std::vector<int64_t> work_index;
// Threadprivate variables
extern "C" bool trace; //!< flag to show debug information
#pragma omp threadprivate(current_work, trace)
#pragma omp threadprivate(trace)
} // namespace simulation

View file

@ -65,13 +65,13 @@ void zero_flux_derivs();
// Explicit vector template specialization declaration of threadprivate variable
// outside of the openmc namespace for the picky Intel compiler.
extern template class std::vector<openmc::TallyDerivative>;
//extern template class std::vector<openmc::TallyDerivative>;
namespace openmc {
namespace model {
extern std::vector<TallyDerivative> tally_derivs;
#pragma omp threadprivate(tally_derivs)
//#pragma omp threadprivate(tally_derivs)
extern std::unordered_map<int, int> tally_deriv_map;
} // namespace model

View file

@ -351,6 +351,7 @@ void calculate_average_keff()
}
}
/*
#ifdef _OPENMP
void join_bank_from_threads()
{
@ -384,6 +385,7 @@ void join_bank_from_threads()
}
}
#endif
*/
int openmc_get_keff(double* k_combined)
{

View file

@ -672,7 +672,7 @@ Particle::write_restart() const
write_dataset(file_id, "id", id_);
write_dataset(file_id, "type", static_cast<int>(type_));
int64_t i = simulation::current_work;
int64_t i = current_work_;
write_dataset(file_id, "weight", simulation::source_bank[i-1].wgt);
write_dataset(file_id, "energy", simulation::source_bank[i-1].E);
write_dataset(file_id, "xyz", simulation::source_bank[i-1].r);

View file

@ -950,8 +950,6 @@ int openmc_next_batch(int* status)
// Start timer for transport
simulation::time_transport.start();
simulation::current_work = 1;
transport();
// Accumulate time for transport
@ -1032,25 +1030,7 @@ void allocate_banks()
simulation::source_bank.resize(simulation::work_per_rank);
if (settings::run_mode == RUN_MODE_EIGENVALUE) {
#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.
#pragma omp parallel
{
if (omp_get_thread_num() == 0) {
simulation::fission_bank.reserve(3*simulation::work_per_rank);
} else {
int n_threads = omp_get_num_threads();
simulation::fission_bank.reserve(3*simulation::work_per_rank / n_threads);
}
}
simulation::master_fission_bank.reserve(3*simulation::work_per_rank);
#else
simulation::fission_bank.reserve(3*simulation::work_per_rank);
#endif
}
}
@ -1269,6 +1249,7 @@ void initialize_history(Particle* p, int64_t index_source)
{
// set defaults
p->from_source(&simulation::source_bank[index_source - 1]);
p->current_work_ = index_source;
// set identifier for particle
p->id_ = simulation::work_index[mpi::rank] + index_source;

View file

@ -83,7 +83,7 @@ read_tally_derivatives(pugi::xml_node node)
{
// Populate the derivatives array. This must be done in parallel because
// the derivatives are threadprivate.
#pragma omp parallel
//#pragma omp parallel
{
for (auto deriv_node : node.children("derivative"))
model::tally_derivs.emplace_back(deriv_node);

View file

@ -1042,7 +1042,7 @@ setup_active_tallies()
void
free_memory_tally()
{
#pragma omp parallel
//#pragma omp parallel
{
model::tally_derivs.clear();
}