diff --git a/miniapp/io.cpp b/miniapp/io.cpp index 0ee643bfa29ef9164a27c8caaff9f5c4a50e053d..27b7b8bde17bfa3375b6fc9ccbf82a1d24070a32 100644 --- a/miniapp/io.cpp +++ b/miniapp/io.cpp @@ -132,7 +132,7 @@ cl_options read_options(int argc, char** argv) { true, // Overwrite outputfile if exists "./", // output path "spikes", // file name - "gdf" // file extention + "gdf" // file extension }; cl_options options; @@ -218,7 +218,7 @@ cl_options read_options(int argc, char** argv) { update_option(options.over_write, fopts, "over_write"); update_option(options.output_path, fopts, "output_path"); update_option(options.file_name, fopts, "file_name"); - update_option(options.file_extention, fopts, "file_extention"); + update_option(options.file_extension, fopts, "file_extension"); } } diff --git a/miniapp/io.hpp b/miniapp/io.hpp index 9de6299f2a582dccda0913fb520cf133d2546bc4..c18e688c33ceff0c3966b5d66ae8eb1680bc48a1 100644 --- a/miniapp/io.hpp +++ b/miniapp/io.hpp @@ -32,7 +32,7 @@ struct cl_options { bool over_write; std::string output_path; std::string file_name; - std::string file_extention; + std::string file_extension; }; class usage_error: public std::runtime_error { diff --git a/miniapp/miniapp.cpp b/miniapp/miniapp.cpp index cf7592cd319d8cc3365f8e6465976fd0f31a3a34..3f68692dec962d8d97c2cea47e5eafd165aa8c6c 100644 --- a/miniapp/miniapp.cpp +++ b/miniapp/miniapp.cpp @@ -69,36 +69,31 @@ int main(int argc, char** argv) { model_type m(*recipe, cell_range.first, cell_range.second); - // File output is depending on the input arguments - std::unique_ptr<file_export_type> file_exporter; - std::function<void(const std::vector<spike_type>&)> do_nothing{ - util::nop_function }; - if (!options.spike_file_output) { - m.set_global_spike_callback(do_nothing); - m.set_local_spike_callback(do_nothing); - } - else { - // The exporter is the same for both global and local output - // just registered as a different callback - file_exporter = + auto register_exporter = [] (const io::cl_options& options) { + return util::make_unique<file_export_type>( options.file_name, options.output_path, - options.file_extention, options.over_write); + options.file_extension, options.over_write); + }; + // File output is depending on the input arguments + std::unique_ptr<file_export_type> file_exporter; + if (options.spike_file_output) { + auto id = communication::global_policy::id(); if (options.single_file_per_rank) { - m.set_global_spike_callback(do_nothing); - m.set_local_spike_callback( - [&](const std::vector<spike_type>& spikes) { - file_exporter->output(spikes); - }); - } - else { - m.set_global_spike_callback( - [&](const std::vector<spike_type>& spikes) { + file_exporter = register_exporter(options); + m.set_local_spike_callback( + [&](const std::vector<spike_type>& spikes) { file_exporter->output(spikes); - }); - m.set_local_spike_callback(do_nothing); - } + }); + } + else if(communication::global_policy::id()==0) { + file_exporter = register_exporter(options); + m.set_global_spike_callback( + [&](const std::vector<spike_type>& spikes) { + file_exporter->output(spikes); + }); + } } // inject some artificial spikes, 1 per 20 neurons. diff --git a/src/model.hpp b/src/model.hpp index 823fcd45662cfc414b7a04964bc7fb91b9b78281..4fa778e06cf366826774fe4c980f1270b52c3cb1 100644 --- a/src/model.hpp +++ b/src/model.hpp @@ -14,6 +14,7 @@ #include <profiling/profiler.hpp> #include <recipe.hpp> #include <thread_private_spike_store.hpp> +#include <util/nop.hpp> #include "trace_sampler.hpp" @@ -139,8 +140,8 @@ public: PE("stepping", "exchange"); auto local_spikes = previous_spikes().gather(); local_export_callback_(local_spikes); - future_events() = communicator_.exchange( - local_spikes, global_export_callback_); + future_events() = + communicator_.exchange(local_spikes, global_export_callback_); PL(2); }; @@ -182,14 +183,12 @@ public: // register a callback that will perform a export of the global // spike vector void set_global_spike_callback(spike_export_function export_callback) { - global_export_callback_ = export_callback; } // register a callback that will perform a export of the rank local // spike vector void set_local_spike_callback(spike_export_function export_callback) { - local_export_callback_ = export_callback; } @@ -207,8 +206,8 @@ private: using local_spike_store_type = thread_private_spike_store<time_type>; util::double_buffer< local_spike_store_type > local_spikes_; - spike_export_function global_export_callback_; - spike_export_function local_export_callback_; + spike_export_function global_export_callback_ = util::nop_function; + spike_export_function local_export_callback_ = util::nop_function; // Convenience functions that map the spike buffers and event queues onto // the appropriate integration interval.