Skip to content
Snippets Groups Projects
Commit fa39792c authored by Benjamin Cumming's avatar Benjamin Cumming
Browse files

streamling global and local spike file output

* single file per rank output creates one file per rank
* global file output creates one file only from rank 0
parent ff87bf96
No related branches found
No related tags found
No related merge requests found
......@@ -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");
}
}
......
......@@ -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 {
......
......@@ -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.
......
......@@ -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.
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment