From 471f846895be8091246471e00efad49ab40dc298 Mon Sep 17 00:00:00 2001 From: "w.klijn" <nonoice@gmail.com> Date: Tue, 9 Aug 2016 10:34:40 +0200 Subject: [PATCH] Building code, missing is the sending of the spikes --- src/communication/communicator.hpp | 12 +++++++++++- src/communication/exporter_interface.hpp | 4 ++++ src/communication/exporter_spike_file.hpp | 8 ++++++++ src/communication/exporter_spike_single_file.hpp | 12 ++++++++++++ src/model.hpp | 14 ++++++++++++-- 5 files changed, 47 insertions(+), 3 deletions(-) diff --git a/src/communication/communicator.hpp b/src/communication/communicator.hpp index 8c72430f..27981695 100644 --- a/src/communication/communicator.hpp +++ b/src/communication/communicator.hpp @@ -4,6 +4,7 @@ #include <iostream> #include <vector> #include <random> +#include <functional> #include <spike.hpp> #include <util/double_buffer.hpp> @@ -90,8 +91,17 @@ public: /// Returns a vector of event queues, with one queue for each local cell group. The /// events in each queue are all events that must be delivered to targets in that cell /// group as a result of the global spike exchange. - std::vector<event_queue> exchange(const std::vector<spike_type>& local_spikes) { + std::vector<event_queue> exchange(const std::vector<spike_type>& local_spikes, + std::function<void ()> export_function) //const std::vector<spike_type>& + { // global all-to-all to gather a local copy of the global spike list on each node. + + bool file_per_rank = true; + if (file_per_rank) { + export_function(); //local_spikes + } + + auto global_spikes = communication_policy_.gather_spikes( local_spikes ); num_spikes_ += global_spikes.size(); diff --git a/src/communication/exporter_interface.hpp b/src/communication/exporter_interface.hpp index ecb2f7e8..579577e3 100644 --- a/src/communication/exporter_interface.hpp +++ b/src/communication/exporter_interface.hpp @@ -24,6 +24,10 @@ public: // Does not do the actual export virtual void add_data(std::vector<spike_type>) = 0; + + virtual void add_and_export() = 0; + + // Internal state is ok // Export might encounter problems in a separate thread. virtual bool ok() const = 0; diff --git a/src/communication/exporter_spike_file.hpp b/src/communication/exporter_spike_file.hpp index 68b2f3c4..8c313851 100644 --- a/src/communication/exporter_spike_file.hpp +++ b/src/communication/exporter_spike_file.hpp @@ -85,6 +85,14 @@ public: std::begin(spikes), std::end(spikes)); } + // Add and export data to file in a single function + void add_and_export() override //std::vector<spike_type>spikes + { + std::vector<spike_type>spikes; + add_data(spikes); + do_export(); + } + // Internal state is ok // We are working with fstreams possibly on a seperate thread // We need a way to assertain the status of the stream diff --git a/src/communication/exporter_spike_single_file.hpp b/src/communication/exporter_spike_single_file.hpp index a10205fe..c3eaa287 100644 --- a/src/communication/exporter_spike_single_file.hpp +++ b/src/communication/exporter_spike_single_file.hpp @@ -98,6 +98,18 @@ public: std::begin(spikes), std::end(spikes)); } + // Add and export data to file in a single function + void add_and_export() override + { + std::vector<spike_type>spikes; + if (!communication_policy_.id() == 0) { + return; + } + + add_data(spikes); + do_export(); + } + // Internal state is ok // We are working with fstreams possibly on a seperate thread // We need a way to assertain the status of the stream diff --git a/src/model.hpp b/src/model.hpp index b92ca4a8..2ebaf14f 100644 --- a/src/model.hpp +++ b/src/model.hpp @@ -13,6 +13,7 @@ #include <communication/communicator.hpp> #include <communication/global_policy.hpp> #include <communication/exporter_interface.hpp> +#include <communication/exporter_spike_single_file.hpp> #include <profiling/profiler.hpp> #include "trace_sampler.hpp" @@ -70,6 +71,12 @@ public: } communicator_.construct(); + bool single_file = true; + if (single_file == true) { + exporter_ = nest::mc::util::make_unique<exporter_spike_single_file_type>( + "file_name", "./","gdf"); + } + // Allocate an empty queue buffer for each cell group // These must be set initially to ensure that a queue is available for each // cell group for the first time step. @@ -130,7 +137,8 @@ public: auto exchange = [&] () { PE("stepping", "exchange"); auto local_spikes = previous_spikes().gather(); - future_events() = communicator_.exchange(local_spikes); + future_events() = communicator_.exchange(local_spikes, + [&] { exporter_->add_and_export(); }); PL(2); }; @@ -184,7 +192,9 @@ private: using local_spike_store_type = thread_private_spike_store<time_type>; util::double_buffer< local_spike_store_type > local_spikes_; - using exporter_interface_type = nest::mc::communication::exporter_interface<time_type, communicator_type>; + using exporter_interface_type = nest::mc::communication::exporter_interface<time_type, communication::global_policy>; + using exporter_spike_single_file_type = nest::mc::communication::exporter_spike_single_file<time_type, communication::global_policy>; + std::unique_ptr<exporter_interface_type> exporter_; // Convenience functions that map the spike buffers and event queues onto // the appropriate integration interval. -- GitLab