From c06d89b068bbf2a651cf83f705bb375832b2d4dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Atgeirr=20Fl=C3=B8=20Rasmussen?= Date: Thu, 16 Jan 2025 13:56:19 +0100 Subject: [PATCH] Use the createThreadIterators() utility. --- opm/simulators/flow/FIBlackoilModel.hpp | 27 ++++++++----------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/opm/simulators/flow/FIBlackoilModel.hpp b/opm/simulators/flow/FIBlackoilModel.hpp index 08000972b..5c7c67be0 100644 --- a/opm/simulators/flow/FIBlackoilModel.hpp +++ b/opm/simulators/flow/FIBlackoilModel.hpp @@ -33,6 +33,8 @@ #include +#include + #include #include @@ -73,29 +75,16 @@ public: { if constexpr (gridIsUnchanging) { const auto& gv = this->gridView_; + int nt = 1; #ifdef _OPENMP - const int nt = omp_get_max_threads(); + nt = omp_get_max_threads(); +#endif + constexpr int max_chunk_size = 1000; + int chunk_size = -1; + grid_chunk_iterators_ = createThreadIterators(gv, nt, max_chunk_size, chunk_size); if (nt > 1) { - const auto num_elements = gv.size(0); - constexpr int max_chunk_size = 1000; - const int chunk_size = std::clamp(num_elements / nt, 1, max_chunk_size); OpmLog::debug("Using chunk size " + std::to_string(chunk_size) + " for property evaluation with " + std::to_string(nt) + " OpenMP threads."); - grid_chunk_iterators_.reserve(num_elements / chunk_size + 2); - auto it = gv.template begin<0>(); - const auto end = gv.template end<0>(); - for (int count = 0; it != end; ++it, ++count) { - if (count % chunk_size == 0) { - grid_chunk_iterators_.push_back(it); - } - } - grid_chunk_iterators_.push_back(end); - } else -#endif - { - // With one thread, or without OpenMP, we use a single chunk. - grid_chunk_iterators_.push_back(gv.template begin<0>()); - grid_chunk_iterators_.push_back(gv.template end<0>()); } } }