From bc2959398295ca9d75ba90f5d7c9409e0232b07e Mon Sep 17 00:00:00 2001 From: couriersud Date: Sun, 7 May 2017 21:34:25 +0200 Subject: Netlist refactoring: - OPENMP refactored. All OPENMP operations are now templatized in pomp.h - We don't need thread-safe priority queue. Event code updating analog outputs now runs outside the parallel code. (nw) --- scripts/src/netlist.lua | 11 ++++--- src/lib/netlist/nl_base.cpp | 2 +- src/lib/netlist/nl_base.h | 5 ++- src/lib/netlist/nl_config.h | 7 ++-- src/lib/netlist/nl_lists.h | 25 ++++++++------- src/lib/netlist/plib/pomp.h | 60 +++++++++++++++++++++++++++++++++++ src/lib/netlist/solver/nld_solver.cpp | 2 +- 7 files changed, 90 insertions(+), 22 deletions(-) create mode 100644 src/lib/netlist/plib/pomp.h diff --git a/scripts/src/netlist.lua b/scripts/src/netlist.lua index a484644306b..d8238e49246 100644 --- a/scripts/src/netlist.lua +++ b/scripts/src/netlist.lua @@ -62,13 +62,14 @@ project "netlist" MAME_DIR .. "src/lib/netlist/plib/plists.h", MAME_DIR .. "src/lib/netlist/plib/pdynlib.cpp", MAME_DIR .. "src/lib/netlist/plib/pdynlib.h", - MAME_DIR .. "src/lib/netlist/plib/pmain.cpp", - MAME_DIR .. "src/lib/netlist/plib/pmain.h", + MAME_DIR .. "src/lib/netlist/plib/pmain.cpp", + MAME_DIR .. "src/lib/netlist/plib/pmain.h", + MAME_DIR .. "src/lib/netlist/plib/pomp.h", MAME_DIR .. "src/lib/netlist/plib/poptions.cpp", MAME_DIR .. "src/lib/netlist/plib/poptions.h", MAME_DIR .. "src/lib/netlist/plib/pparser.cpp", MAME_DIR .. "src/lib/netlist/plib/pparser.h", - MAME_DIR .. "src/lib/netlist/plib/ppmf.h", + MAME_DIR .. "src/lib/netlist/plib/ppmf.h", MAME_DIR .. "src/lib/netlist/plib/pstate.cpp", MAME_DIR .. "src/lib/netlist/plib/pstate.h", MAME_DIR .. "src/lib/netlist/plib/pstring.cpp", @@ -86,11 +87,11 @@ project "netlist" MAME_DIR .. "src/lib/netlist/analog/nld_bjt.h", MAME_DIR .. "src/lib/netlist/analog/nlid_fourterm.cpp", MAME_DIR .. "src/lib/netlist/analog/nlid_fourterm.h", - MAME_DIR .. "src/lib/netlist/analog/nld_fourterm.h", + MAME_DIR .. "src/lib/netlist/analog/nld_fourterm.h", MAME_DIR .. "src/lib/netlist/analog/nld_switches.cpp", MAME_DIR .. "src/lib/netlist/analog/nld_switches.h", MAME_DIR .. "src/lib/netlist/analog/nlid_twoterm.cpp", - MAME_DIR .. "src/lib/netlist/analog/nlid_twoterm.h", + MAME_DIR .. "src/lib/netlist/analog/nlid_twoterm.h", MAME_DIR .. "src/lib/netlist/analog/nld_twoterm.h", MAME_DIR .. "src/lib/netlist/analog/nld_opamps.cpp", MAME_DIR .. "src/lib/netlist/analog/nld_opamps.h", diff --git a/src/lib/netlist/nl_base.cpp b/src/lib/netlist/nl_base.cpp index 75e448427e7..9a513c00804 100644 --- a/src/lib/netlist/nl_base.cpp +++ b/src/lib/netlist/nl_base.cpp @@ -147,7 +147,7 @@ const logic_family_desc_t *family_CD4XXX() // ---------------------------------------------------------------------------------------- detail::queue_t::queue_t(netlist_t &nl) - : timed_queue>(512) + : timed_queue, false>(512) , netlist_ref(nl) , plib::state_manager_t::callback_t() , m_qsize(0) diff --git a/src/lib/netlist/nl_base.h b/src/lib/netlist/nl_base.h index 7afed824630..e56fde89f88 100644 --- a/src/lib/netlist/nl_base.h +++ b/src/lib/netlist/nl_base.h @@ -1186,8 +1186,11 @@ namespace netlist // queue_t // ----------------------------------------------------------------------------- + /* We don't need a thread-safe queue currently. Parallel processing of + * solvers will update inputs after parallel processing. + */ class detail::queue_t : - public timed_queue>, + public timed_queue, false>, public detail::netlist_ref, public plib::state_manager_t::callback_t { diff --git a/src/lib/netlist/nl_config.h b/src/lib/netlist/nl_config.h index 72cb10903be..6a65abac40a 100644 --- a/src/lib/netlist/nl_config.h +++ b/src/lib/netlist/nl_config.h @@ -77,7 +77,9 @@ // General //============================================================ -// The following adds about 10% performance ... +/* The following adds about 10% to 20% performance for analog + * netlists like kidniki. + */ #if !defined(USE_OPENMP) #define USE_OPENMP (0) @@ -85,9 +87,10 @@ // Use nano-second resolution - Sufficient for now #define NETLIST_INTERNAL_RES (UINT64_C(1000000000)) +#define NETLIST_CLOCK (NETLIST_INTERNAL_RES) //#define NETLIST_INTERNAL_RES (UINT64_C(1000000000000)) +//#define NETLIST_CLOCK (UINT64_C(1000000000)) -#define NETLIST_CLOCK (NETLIST_INTERNAL_RES) //#define nl_double float //#define NL_FCONST(x) (x ## f) diff --git a/src/lib/netlist/nl_lists.h b/src/lib/netlist/nl_lists.h index c5026e6b081..1eae38b25fb 100644 --- a/src/lib/netlist/nl_lists.h +++ b/src/lib/netlist/nl_lists.h @@ -26,7 +26,15 @@ // timed queue // ---------------------------------------------------------------------------------------- +/* + * Use -DUSE_HEAP=1 to use stdc++ heap functions instead of linear processing. + * + * This slows down processing by about 25% on a Kaby Lake. + */ + +#ifndef USE_HEAP #define USE_HEAP (0) +#endif namespace netlist { @@ -92,7 +100,8 @@ namespace netlist }; #if !USE_HEAP - template + /* Use TS = true for a threadsafe queue */ + template class timed_queue : plib::nocopyassignmove { public: @@ -183,11 +192,7 @@ namespace netlist constexpr std::size_t size() const noexcept { return static_cast(m_end - &m_list[1]); } constexpr const T & operator[](const std::size_t index) const noexcept { return m_list[ 1 + index]; } private: - #if HAS_OPENMP && USE_OPENMP - using tqmutex = pspin_mutex; - #else - using tqmutex = pspin_mutex; - #endif + using tqmutex = pspin_mutex; using tqlock = std::lock_guard; tqmutex m_lock; @@ -200,7 +205,7 @@ namespace netlist nperfcount_t m_prof_call; }; #else - template + template class timed_queue : plib::nocopyassignmove { public: @@ -282,11 +287,7 @@ namespace netlist constexpr std::size_t size() const noexcept { return m_list.size(); } constexpr const T & operator[](const std::size_t index) const { return m_list[ 0 + index]; } private: - #if HAS_OPENMP && USE_OPENMP - using tqmutex = pspin_mutex; - #else - using tqmutex = pspin_mutex; - #endif + using tqmutex = pspin_mutex; using tqlock = std::lock_guard; tqmutex m_lock; diff --git a/src/lib/netlist/plib/pomp.h b/src/lib/netlist/plib/pomp.h new file mode 100644 index 00000000000..6559207f09d --- /dev/null +++ b/src/lib/netlist/plib/pomp.h @@ -0,0 +1,60 @@ +// license:GPL-2.0+ +// copyright-holders:Couriersud +/* + * pomp.h + * + * Wrap all OPENMP stuff here in a hopefully c++ compliant way. + */ + +#ifndef POMP_H_ +#define POMP_H_ + +#include "pconfig.h" + +#if HAS_OPENMP +#include "omp.h" +#endif + +namespace plib { +namespace omp { + +template +void for_static(const int start, const int end, const T &what) +{ +#if HAS_OPENMP && USE_OPENMP + #pragma omp parallel +#endif + { +#if HAS_OPENMP && USE_OPENMP + #pragma omp for schedule(static) +#endif + for (int i = start; i < end; i++) + what(i); + } +} + +inline void set_num_threads(const int threads) +{ +#if HAS_OPENMP && USE_OPENMP + omp_set_num_threads(threads); +#endif +} + +inline int get_max_threads() +{ +#if HAS_OPENMP && USE_OPENMP + return omp_get_max_threads(); +#else + return 1; +#endif +} + + +// ---------------------------------------------------------------------------------------- +// pdynlib: dynamic loading of libraries ... +// ---------------------------------------------------------------------------------------- + +} +} + +#endif /* PSTRING_H_ */ diff --git a/src/lib/netlist/solver/nld_solver.cpp b/src/lib/netlist/solver/nld_solver.cpp index f856eeacca9..2e2df3c0f05 100644 --- a/src/lib/netlist/solver/nld_solver.cpp +++ b/src/lib/netlist/solver/nld_solver.cpp @@ -102,7 +102,7 @@ NETLIB_UPDATE(solver) if (nthreads > 1 && t_cnt > 1) { plib::omp::set_num_threads(nthreads); - plib::omp::for_static(0, t_cnt, [this, solv](int i) { ATTR_UNUSED const netlist_time ts = this->m_mat_solvers[solv[i]]->solve(); }); + plib::omp::for_static(0, t_cnt, [this, &solv](int i) { ATTR_UNUSED const netlist_time ts = this->m_mat_solvers[solv[i]]->solve(); }); } else for (auto & solver : m_mat_solvers) -- cgit v1.2.3