Skip to content
Snippets Groups Projects
Commit 91781ba1 authored by w.klijn's avatar w.klijn
Browse files

source formatting

parent a7cac9e4
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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
......
......@@ -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"),
......
......@@ -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;
......
......@@ -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
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