Skip to content

Commit

Permalink
Remove steps_recorded_ since we go 1 step at a time now
Browse files Browse the repository at this point in the history
Changed in neuron required to check for flush every simulation step
  • Loading branch information
jorblancoa committed May 31, 2024
1 parent ea01d1d commit b96a296
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 47 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ option(SONATA_REPORT_ENABLE_CONVERTER "Enable binary report converter" OFF)
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMake)
set(CMAKE_SKIP_INSTALL_ALL_DEPENDENCY true)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(SONATA_REPORT_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include)
Expand Down
70 changes: 25 additions & 45 deletions src/data/sonata_data.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <algorithm>
#include <filesystem>
#include <iostream>
#include <memory>

Expand Down Expand Up @@ -46,7 +47,7 @@ SonataData::SonataData(const std::string& report_name)
void SonataData::prepare_buffer(size_t max_buffer_size) {
if (SonataReport::rank_ == 0) {
logger->debug("PREPARING BUFFER for report {} and population {}",
report_name_,
std::filesystem::path(report_name_).filename().string(),
population_name_);
}

Expand Down Expand Up @@ -115,25 +116,15 @@ void SonataData::record_data(double step, const std::vector<uint64_t>& node_ids)
uint32_t offset = static_cast<uint32_t>((step - last_step_recorded_) / reporting_period_);
uint32_t local_position = last_position_ + total_elements_ * offset;

if (steps_recorded_ >= steps_to_write_) {
if (SonataReport::rank_ == 0) {
logger->trace("Already recorded {} steps, skipping report recording for {} population",
steps_recorded_,
population_name_);
}
return;
}

if (SonataReport::rank_ == 0) {
logger->trace(
"Recording data for population {}, step={} last_step_recorded={} steps recorded {} "
"Recording data for population {}, step={} last_step_recorded={} "
"first node_id={} "
"buffer_size={} "
"and offset={}",
population_name_,
step,
last_step_recorded_,
steps_recorded_,
node_ids[0],
report_buffer_.size(),
local_position);
Expand All @@ -150,22 +141,16 @@ void SonataData::record_data(double step, const std::vector<uint64_t>& node_ids)

// Increase steps recorded when all nodes from specific rank has been already recorded
if (nodes_recorded_.size() == nodes_->size()) {
steps_recorded_++;
current_step_++;
last_position_ += total_elements_;
last_step_recorded_ += reporting_period_;
nodes_recorded_.clear();
}
}

void SonataData::record_data(double step) {
uint32_t local_position = last_position_;

if (steps_recorded_ >= steps_to_write_) {
if (SonataReport::rank_ == 0) {
logger->trace("Already recorded {} steps, skipping report recording for {} population",
steps_recorded_,
population_name_);
}
return;
}

if (SonataReport::rank_ == 0) {
logger->trace(
"Recording data for step={} last_step_recorded={} buffer_size={} and offset={}",
Expand Down Expand Up @@ -193,41 +178,36 @@ void SonataData::check_and_write(double timestep) {
}

if (SonataReport::rank_ == 0) {
logger->debug("UPDATING timestep t={} for report {} and population {}",
timestep,
report_name_,
population_name_);
logger->debug(
"UPDATING timestep t={} for report {} and population {} current_step_={} "
"steps_to_write_={}",
timestep,
std::filesystem::path(report_name_).filename().string(),
population_name_,
current_step_,
steps_to_write_);
}
current_step_ += steps_recorded_;
last_position_ += total_elements_ * steps_recorded_;
last_step_recorded_ += reporting_period_ * steps_recorded_;
nodes_recorded_.clear();

// Write when buffer is full, finish all remaining recordings or when record several steps in a
// row
if (current_step_ == steps_to_write_ || current_step_ == remaining_steps_ ||
steps_recorded_ > 1) {

// Write when buffer is full or finish all remaining recordings
if (current_step_ == steps_to_write_ || current_step_ == remaining_steps_) {
if (SonataReport::rank_ == 0) {
logger->trace(
"Writing to file {}! population {} steps_to_write={}, current_step={}, "
"remaining_steps={} "
"steps_recorded={}",
report_name_,
"Writing to file {}! population {} current_step={}, steps_to_write={}, "
"remaining_steps={} ",
std::filesystem::path(report_name_).filename().string(),
population_name_,
steps_to_write_,
current_step_,
remaining_steps_,
steps_recorded_);
steps_to_write_,
remaining_steps_);
}
flush();
}
steps_recorded_ = 0;
}

void SonataData::prepare_dataset() {
if (SonataReport::rank_ == 0) {
logger->debug("PREPARING HEADER for report {} and population {}",
report_name_,
std::filesystem::path(report_name_).filename().string(),
population_name_);
}
// Prepare /report
Expand Down Expand Up @@ -342,7 +322,7 @@ void SonataData::write_data(const std::vector<float>& buffered_data, uint32_t st
}
if (SonataReport::rank_ == 0) {
logger->debug("WRITING timestep data to file {} in population {}",
report_name_,
std::filesystem::path(report_name_).filename().string(),
population_name_);
}
hdf5_writer_->write_2D(buffered_data, steps_to_write, total_elements_);
Expand Down
1 change: 0 additions & 1 deletion src/data/sonata_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ class SonataData
uint32_t num_steps_ = 0;
uint32_t steps_to_write_ = 0;
uint32_t current_step_ = 0;
uint32_t steps_recorded_ = 0;
uint32_t last_position_ = 0;
uint32_t remaining_steps_ = 0;
uint32_t reporting_period_ = 0;
Expand Down

0 comments on commit b96a296

Please sign in to comment.