summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib/netlist
diff options
context:
space:
mode:
author couriersud <couriersud@gmx.org>2017-05-07 21:34:25 +0200
committer couriersud <couriersud@gmx.org>2017-05-27 00:11:14 +0200
commitbc2959398295ca9d75ba90f5d7c9409e0232b07e (patch)
tree44e25f4d15866996c89dfd831228b62dbdbf7afe /src/lib/netlist
parent01f8ace29685a59e3b1a3fcc0a4dce9c5e1a43b5 (diff)
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)
Diffstat (limited to 'src/lib/netlist')
-rw-r--r--src/lib/netlist/nl_base.cpp2
-rw-r--r--src/lib/netlist/nl_base.h5
-rw-r--r--src/lib/netlist/nl_config.h7
-rw-r--r--src/lib/netlist/nl_lists.h25
-rw-r--r--src/lib/netlist/plib/pomp.h60
-rw-r--r--src/lib/netlist/solver/nld_solver.cpp2
6 files changed, 84 insertions, 17 deletions
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<pqentry_t<net_t *, netlist_time>>(512)
+ : timed_queue<pqentry_t<net_t *, netlist_time>, 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<pqentry_t<net_t *, netlist_time>>,
+ public timed_queue<pqentry_t<net_t *, netlist_time>, 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 <class T, class QueueOp = typename T::QueueOp>
+ /* Use TS = true for a threadsafe queue */
+ template <class T, bool TS, class QueueOp = typename T::QueueOp>
class timed_queue : plib::nocopyassignmove
{
public:
@@ -183,11 +192,7 @@ namespace netlist
constexpr std::size_t size() const noexcept { return static_cast<std::size_t>(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<true>;
- #else
- using tqmutex = pspin_mutex<false>;
- #endif
+ using tqmutex = pspin_mutex<TS>;
using tqlock = std::lock_guard<tqmutex>;
tqmutex m_lock;
@@ -200,7 +205,7 @@ namespace netlist
nperfcount_t m_prof_call;
};
#else
- template <class T, class QueueOp = typename T::QueueOp>
+ template <class T, bool TS, class QueueOp = typename T::QueueOp>
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<true>;
- #else
- using tqmutex = pspin_mutex<false>;
- #endif
+ using tqmutex = pspin_mutex<TS>;
using tqlock = std::lock_guard<tqmutex>;
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 <class T>
+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)