diff --git a/src/communication/exporter_interface.hpp b/src/communication/exporter_interface.hpp index 6c22fddeca667cb34d3df5469979ef25895ed908..d0370a92b609773b06cb8663563129a242385cb1 100644 --- a/src/communication/exporter_interface.hpp +++ b/src/communication/exporter_interface.hpp @@ -13,7 +13,8 @@ namespace communication { // interface for exporters. // Exposes one virtual functions: // do_export(vector<type>) receiving a vector of parameters to export -template <typename Time, typename CommunicationPolicy> // TODO: Templating on data type + +template <typename Time, typename CommunicationPolicy> class exporter_interface { public: @@ -24,7 +25,7 @@ public: virtual void do_export(const std::vector<spike_type>&) = 0; // Returns the status of the exporter - bool good() const; + virtual bool good() const = 0; }; } //communication diff --git a/src/communication/exporter_spike_file.hpp b/src/communication/exporter_spike_file.hpp index adf185d8520f37b6bc4f7d7ec3bf9a7fa3fe2bcb..cad61fbb7774594d234fd3761c740738f12c7bc6 100644 --- a/src/communication/exporter_spike_file.hpp +++ b/src/communication/exporter_spike_file.hpp @@ -18,7 +18,7 @@ namespace nest { namespace mc { namespace communication { -template <typename Time, typename CommunicationPolicy> // TODO: Templating on data type, for now only spike_type +template <typename Time, typename CommunicationPolicy> class exporter_spike_file : public exporter_interface<Time, CommunicationPolicy> { public: @@ -35,12 +35,14 @@ public: const std::string& file_extention, bool over_write=true) { auto file_path = - create_output_file_path(file_name, path, file_extention, communication_policy_.id()); + create_output_file_path(file_name, path, file_extention, + communication_policy_.id()); //test if the file exist and depending on over_write throw or delete if (!over_write && file_exists(file_path)) { - std::string error_string("Tried opening file for writing but it exists and over_write is false: " + file_path); + std::string error_string("Tried opening file for writing but it exists and over_write is false: " + + file_path); throw std::runtime_error(error_string); } @@ -48,27 +50,30 @@ public: } // Performs the a export of the spikes to file - // one id and spike time with 4 decimals after the comma on a line space separated + // one id and spike time with 4 decimals after the comma on a + // line space separated void do_export(const std::vector<spike_type>& spikes) override { for (auto spike : spikes) { char linebuf[45]; - auto n = std::snprintf(linebuf, sizeof(linebuf), "%u %.4f\n", spike.source.gid, spike.time); + auto n = std::snprintf(linebuf, sizeof(linebuf), "%u %.4f\n", + spike.source.gid, spike.time); file_handle_.write(linebuf, n); } } - bool good() const + bool good() const override { return file_handle_.good(); } // Creates an indexed filename - static std::string create_output_file_path(const std::string& file_name, const std::string& path, - const std::string& file_extention, unsigned index) + static std::string create_output_file_path(const std::string& file_name, + const std::string& path, const std::string& file_extention, + unsigned index) { - std::string file_path = path + file_name + "_" + std::to_string(index) + - "." + file_extention; + std::string file_path = path + file_name + "_" + + std::to_string(index) + "." + file_extention; // Nest does not produce the indexing for nrank == 0 // I have the feeling this disrupts consistent output. Id rather // always put the zero in. it allows a simpler regex when opening diff --git a/tests/global_communication/test_exporter_spike_file.cpp b/tests/global_communication/test_exporter_spike_file.cpp index 00808e12856ee55392eaf7f259f2f86e5b733294..85065a0c64b81be75a6797ffde8eb3308546210b 100644 --- a/tests/global_communication/test_exporter_spike_file.cpp +++ b/tests/global_communication/test_exporter_spike_file.cpp @@ -16,17 +16,19 @@ protected: using time_type = float; using communicator_type = nest::mc::communication::global_policy; - using spike_type = nest::mc::communication::exporter_spike_file<time_type, + using spike_type = + nest::mc::communication::exporter_spike_file<time_type, communicator_type>::spike_type; - using exporter_type = nest::mc::communication::exporter_spike_file<time_type, communicator_type>; + using exporter_type = + nest::mc::communication::exporter_spike_file<time_type, + communicator_type>; std::string file_name; std::string path; std::string extention; unsigned index; - exporter_spike_file_fixture() - : + exporter_spike_file_fixture() : file_name("spikes_exporter_spike_file_fixture"), path("./"), extention("gdf"), diff --git a/tests/performance/io/disk_io.cpp b/tests/performance/io/disk_io.cpp index 791cf07d94f85c209a0e9097fbab136c3f4d19e0..a93d627f028519ae02d564ba4b73cf1c412b6dc3 100644 --- a/tests/performance/io/disk_io.cpp +++ b/tests/performance/io/disk_io.cpp @@ -46,14 +46,16 @@ int main(int argc, char** argv) if (nr_spikes == 0) { std::cout << "disk_io <nrspikes>" << std::endl; - std::cout << " nrspikes should be a valid integer higher then zero" << std::endl; + std::cout << " nrspikes should be a valid integer higher then zero" + << std::endl; exit(1); } int nr_repeats = atoi(argv[2]); if (nr_repeats == 0) { std::cout << "disk_io <nrspikes>" << std::endl; - std::cout << " nr_repeats should be a valid integer higher then zero" << std::endl; + std::cout << " nr_repeats should be a valid integer higher then zero" + << std::endl; exit(1); } @@ -121,7 +123,8 @@ int main(int argc, char** argv) std::vector<double> diff(timings.size()); std::transform(timings.begin(), timings.end(), diff.begin(), std::bind2nd(std::minus<double>(), mean)); - double sq_sum = std::inner_product(diff.begin(), diff.end(), diff.begin(), 0.0); + double sq_sum = std::inner_product(diff.begin(), diff.end(), diff.begin(), + 0.0); double stdev = std::sqrt(sq_sum / timings.size()); if (communication_policy.id() != 0) { @@ -135,9 +138,12 @@ int main(int argc, char** argv) stdev / double(CLOCKS_PER_SEC) * 1000; } else { - std::cout << "total time (ms): " << time_total / double(CLOCKS_PER_SEC) * 1000 << std::endl; - std::cout << "mean time (ms): " << mean / double(CLOCKS_PER_SEC) * 1000 << std::endl; - std::cout << "stdev time (ms): " << stdev / double(CLOCKS_PER_SEC) * 1000 << std::endl; + std::cout << "total time (ms): " + << time_total / double(CLOCKS_PER_SEC) * 1000 << std::endl; + std::cout << "mean time (ms): " + << mean / double(CLOCKS_PER_SEC) * 1000 << std::endl; + std::cout << "stdev time (ms): " + << stdev / double(CLOCKS_PER_SEC) * 1000 << std::endl; } return 0; diff --git a/tests/performance/io/disk_io.py b/tests/performance/io/disk_io.py index d813c7e3721025f87cc87ff902da2f83e52ba34d..17d8b29fae423ade937b7eb4cd4cbfb5cd5618c9 100644 --- a/tests/performance/io/disk_io.py +++ b/tests/performance/io/disk_io.py @@ -10,11 +10,10 @@ range_nr_rank = [1, 2, 4, 8, 16, 24, 32, 48, 64] mean = [] std = [] for n_rank in range_nr_rank: - # open the disk_io executable - p1 = subprocess.Popen(["mpirun", "-n",str(n_rank), + # open the disk_io executable + p1 = subprocess.Popen(["mpirun", "-n",str(n_rank), os.path.join(current_script_dir, "disk_io.exe"), - str(spikes_to_save), str(10), "true" ,"true"], - + str(spikes_to_save), str(10), "true" ,"true"], stdout=subprocess.PIPE) #and grab the raw stats @@ -26,11 +25,11 @@ for n_rank in range_nr_rank: mean.append(float(stats[1])) std.append(float(stats[2])) - print ( "performed test for n_rank= " + str(n_rank)) + print ("performed test for n_rank= " + str(n_rank)) -print ( range_nr_rank ) -print ( mean ) -print ( std ) +print (range_nr_rank) +print (mean) +print (std) plt.errorbar(range_nr_rank, mean, yerr=std, fmt='-o') plt.show() \ No newline at end of file