From 34cc01664a6cd316641287aa68af109c1305ec37 Mon Sep 17 00:00:00 2001
From: bcumming <bcumming@cscs.ch>
Date: Fri, 5 Aug 2016 11:08:10 +0200
Subject: [PATCH] add comments for review of PR68
---
src/model.hpp | 10 ++++++++--
src/util/double_buffer.hpp | 9 +++++++++
2 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/src/model.hpp b/src/model.hpp
index 9862eeee..84dd8429 100644
--- a/src/model.hpp
+++ b/src/model.hpp
@@ -84,9 +84,15 @@ public:
}
time_type run(time_type tfinal, time_type dt) {
- time_type min_delay = communicator_.min_delay()/2;
+ // Calculate the size of the largest possible time integration interval
+ // before communication of spikes is required.
+ // If spike exchange and cell update are serialized, this is the
+ // minimum delay of the network, however we use half this period
+ // to overlap communication and computation.
+ time_type t_interval = communicator_.min_delay()/2;
+
while (t_<tfinal) {
- auto tuntil = std::min(t_+min_delay, tfinal);
+ auto tuntil = std::min(t_+t_interval, tfinal);
event_queues_.exchange();
local_spikes_.exchange();
diff --git a/src/util/double_buffer.hpp b/src/util/double_buffer.hpp
index 34dceb7f..31cffa1b 100644
--- a/src/util/double_buffer.hpp
+++ b/src/util/double_buffer.hpp
@@ -9,6 +9,7 @@ namespace nest {
namespace mc {
namespace util {
+/// double buffer with thread safe exchange/flip operation.
template <typename T>
class double_buffer {
private:
@@ -26,27 +27,35 @@ public:
index_(0)
{}
+ /// remove the copy and move constructors which won't work with std::atomic
double_buffer(double_buffer&&) = delete;
double_buffer(const double_buffer&) = delete;
double_buffer& operator=(const double_buffer&) = delete;
double_buffer& operator=(double_buffer&&) = delete;
+ /// flip the buffers in a thread safe manner
+ /// n calls to exchange will always result in n flips
void exchange() {
+ // use operator^= which is overloaded by std::atomic<>
index_ ^= 1;
}
+ /// get the current/front buffer
value_type& get() {
return buffers_[index_];
}
+ /// get the current/front buffer
const value_type& get() const {
return buffers_[index_];
}
+ /// get the back buffer
value_type& other() {
return buffers_[other_index()];
}
+ /// get the back buffer
const value_type& other() const {
return buffers_[other_index()];
}
--
GitLab