diff --git a/include/openmc/mesh.h b/include/openmc/mesh.h index d4255877e..1817809ff 100644 --- a/include/openmc/mesh.h +++ b/include/openmc/mesh.h @@ -538,7 +538,8 @@ private: // Data members std::unique_ptr m_; //!< pointer to the libMesh mesh instance - std::vector> point_locators_; //!< pointers to locators for each thread + static std::unique_ptr PL_; //!< per-thread point locators + #pragma omp threadprivate(PL_) std::unique_ptr equation_systems_; //!< pointer to the equation systems of the mesh std::string eq_system_name_; //!< name of the equation system holding OpenMC results std::map variable_map_; //!< mapping of variable names (tally scores) to libMesh variable numbers diff --git a/src/mesh.cpp b/src/mesh.cpp index ccaf96efd..194d3e72f 100644 --- a/src/mesh.cpp +++ b/src/mesh.cpp @@ -2088,6 +2088,9 @@ MOABMesh::write(std::string base_filename) const { #endif #ifdef LIBMESH + +std::unique_ptr LibMesh::PL_ = nullptr; + LibMesh::LibMesh(pugi::xml_node node) : UnstructuredMesh(node) { initialize(); } @@ -2118,19 +2121,9 @@ void LibMesh::initialize() { libMesh::ExplicitSystem& eq_sys = equation_systems_->add_system(eq_system_name_); - // setup the point locator - #ifdef _OPENMP - int n_threads = omp_get_max_threads(); - #else - int n_threads = 1; - #endif - - point_locators_ = std::vector>(n_threads); - for (int i = 0; i < n_threads; i++) { - point_locators_[i] = m_->sub_point_locator(); - point_locators_[i]->set_contains_point_tol(FP_COINCIDENT); - point_locators_[i]->enable_out_of_mesh_mode(); - } + PL_ = m_->sub_point_locator(); + PL_->set_contains_point_tol(FP_COINCIDENT); + PL_->enable_out_of_mesh_mode(); first_element_ = *m_->elements_begin(); @@ -2242,13 +2235,7 @@ LibMesh::get_bin(Position r) const // quick rejection check if (!bbox_.contains_point(p)) { return -1; } - #ifdef _OPENMP - int thread = omp_get_thread_num(); - #else - int thread = 0; - #endif - - auto e = (*point_locators_[thread])(p); + auto e = (*LibMesh::PL_)(p); if (!e) { return -1; } else {