diff options
Diffstat (limited to 'src/lib/netlist/plib/pomp.h')
-rw-r--r-- | src/lib/netlist/plib/pomp.h | 65 |
1 files changed, 34 insertions, 31 deletions
diff --git a/src/lib/netlist/plib/pomp.h b/src/lib/netlist/plib/pomp.h index ecd9eacc41b..b77d3e5ee56 100644 --- a/src/lib/netlist/plib/pomp.h +++ b/src/lib/netlist/plib/pomp.h @@ -1,73 +1,76 @@ -// license:GPL-2.0+ +// license:BSD-3-Clause // copyright-holders:Couriersud -/* - * pomp.h - * - * Wrap all OPENMP stuff here in a hopefully c++ compliant way. - */ #ifndef POMP_H_ #define POMP_H_ +/// +/// \file pomp.h +/// +/// Wrap all OPENMP stuff here in a hopefully c++ compliant way. +/// + #include "pconfig.h" #include "ptypes.h" #include <cstdint> -#if HAS_OPENMP +#if PHAS_OPENMP #include "omp.h" #endif -namespace plib { -namespace omp { +namespace plib::omp { template <typename I, class T> -void for_static(const I start, const I end, const T &what) +void for_static(std::size_t numops, const I start, const I end, const T &what) noexcept(noexcept(what)) { -#if HAS_OPENMP && USE_OPENMP - #pragma omp parallel -#endif + if (numops>1000) { -#if HAS_OPENMP && USE_OPENMP - #pragma omp for //schedule(static) -#endif + #if PHAS_OPENMP && PUSE_OPENMP + #pragma omp parallel for schedule(static) + #endif for (I i = start; i < end; i++) what(i); } + else + for (I i = start; i < end; i++) + what(i); } template <typename I, class T> -void for_static_np(const I start, const I end, const T &what) +void for_static(const I start, const I end, const T &what) noexcept(noexcept(what)) +{ +#if PHAS_OPENMP && PUSE_OPENMP + #pragma omp parallel for schedule(static) +#endif + for (I i = start; i < end; i++) + what(i); +} + +template <typename I, class T> +void for_static_np(const I start, const I end, const T &what) noexcept(noexcept(what)) { for (I i = start; i < end; i++) what(i); } -inline void set_num_threads(const std::size_t threads) +inline void set_num_threads([[maybe_unused]] const std::size_t threads) noexcept { -#if HAS_OPENMP && USE_OPENMP +#if PHAS_OPENMP && PUSE_OPENMP omp_set_num_threads(threads); -#else - plib::unused_var(threads); #endif } -inline std::size_t get_max_threads() +inline std::size_t get_max_threads() noexcept { -#if HAS_OPENMP && USE_OPENMP +#if PHAS_OPENMP && PUSE_OPENMP return omp_get_max_threads(); #else return 1; #endif } +} // namespace plib::omp -// ---------------------------------------------------------------------------------------- -// pdynlib: dynamic loading of libraries ... -// ---------------------------------------------------------------------------------------- - -} // namespace omp -} // namespace plib - -#endif /* PSTRING_H_ */ +#endif // PSTRING_H_ |