diff --git a/src/communication/communicator.hpp b/src/communication/communicator.hpp index 8c72430f5c4646ce7747c76cac088bee65a58df8..27981695c1818b41948fcae8b6d0682fb26a205a 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 ecb2f7e89e014176c622578cf3534c8458e4fc9e..579577e369b2a53c11cdf9c9a5cd51a5f53e930d 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 68b2f3c40640398002afd9296398d9dfc591fdc4..8c31385166218437e108bd314125c377268aa409 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 a10205fe447e18ed37ac074164cbe9bbb5d864ba..c3eaa287ea3eb3d5ca9814425ba71af9fcc1ec85 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 b92ca4a89a2e28ea8ced46def014dc9b2b8cd07c..2ebaf14f85c45267bdd3e0f122e8b02ca3db191c 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.