Skip to content
This repository was archived by the owner on Mar 20, 2023. It is now read-only.

Commit 8c056fb

Browse files
committed
Improve memory usage in report initialization (#882)
* Use a vector for the report target gids in order to save memory * Add intersection function for the report gids * Clean up target vector after initialization * sync gids and compartment id types to sonata
1 parent 8bea2f0 commit 8c056fb

File tree

10 files changed

+162
-165
lines changed

10 files changed

+162
-165
lines changed

coreneuron/apps/main1.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -428,13 +428,13 @@ static void trajectory_return() {
428428
}
429429
}
430430

431-
std::unique_ptr<ReportHandler> create_report_handler(ReportConfiguration& config,
431+
std::unique_ptr<ReportHandler> create_report_handler(const ReportConfiguration& config,
432432
const SpikesInfo& spikes_info) {
433433
std::unique_ptr<ReportHandler> report_handler;
434434
if (config.format == "Bin") {
435-
report_handler = std::make_unique<BinaryReportHandler>(config);
435+
report_handler = std::make_unique<BinaryReportHandler>();
436436
} else if (config.format == "SONATA") {
437-
report_handler = std::make_unique<SonataReportHandler>(config, spikes_info);
437+
report_handler = std::make_unique<SonataReportHandler>(spikes_info);
438438
} else {
439439
if (nrnmpi_myid == 0) {
440440
printf(" WARNING : Report name '%s' has unknown format: '%s'.\n",
@@ -595,7 +595,7 @@ extern "C" int run_solve_core(int argc, char** argv) {
595595
std::unique_ptr<ReportHandler> report_handler = create_report_handler(configs[i],
596596
spikes_info);
597597
if (report_handler) {
598-
report_handler->create_report(dt, tstop, delay);
598+
report_handler->create_report(configs[i], dt, tstop, delay);
599599
report_handlers.push_back(std::move(report_handler));
600600
}
601601
if (configs[i].report_dt < min_report_dt) {

coreneuron/io/reports/binary_report_handler.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@
1313

1414
namespace coreneuron {
1515

16-
void BinaryReportHandler::create_report(double dt, double tstop, double delay) {
16+
void BinaryReportHandler::create_report(ReportConfiguration& config,
17+
double dt,
18+
double tstop,
19+
double delay) {
1720
#ifdef ENABLE_BIN_REPORTS
1821
records_set_atomic_step(dt);
1922
#endif // ENABLE_BIN_REPORTS
20-
ReportHandler::create_report(dt, tstop, delay);
23+
ReportHandler::create_report(config, dt, tstop, delay);
2124
}
2225

2326
#ifdef ENABLE_BIN_REPORTS
@@ -44,22 +47,22 @@ static void create_custom_extra(const CellMapping& mapping, std::array<int, 5>&
4447
}
4548

4649
void BinaryReportHandler::register_section_report(const NrnThread& nt,
47-
ReportConfiguration& config,
50+
const ReportConfiguration& config,
4851
const VarsToReport& vars_to_report,
4952
bool is_soma_target) {
5053
create_extra_func create_extra = is_soma_target ? create_soma_extra : create_compartment_extra;
5154
register_report(nt, config, vars_to_report, create_extra);
5255
}
5356

5457
void BinaryReportHandler::register_custom_report(const NrnThread& nt,
55-
ReportConfiguration& config,
58+
const ReportConfiguration& config,
5659
const VarsToReport& vars_to_report) {
5760
create_extra_func create_extra = create_custom_extra;
5861
register_report(nt, config, vars_to_report, create_extra);
5962
}
6063

6164
void BinaryReportHandler::register_report(const NrnThread& nt,
62-
ReportConfiguration& config,
65+
const ReportConfiguration& config,
6366
const VarsToReport& vars_to_report,
6467
create_extra_func& create_extra) {
6568
int sizemapping = 1;

coreneuron/io/reports/binary_report_handler.hpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,20 @@ namespace coreneuron {
2020

2121
class BinaryReportHandler: public ReportHandler {
2222
public:
23-
BinaryReportHandler(ReportConfiguration& config)
24-
: ReportHandler(config) {}
25-
26-
void create_report(double dt, double tstop, double delay) override;
23+
void create_report(ReportConfiguration& config, double dt, double tstop, double delay) override;
2724
#ifdef ENABLE_BIN_REPORTS
2825
void register_section_report(const NrnThread& nt,
29-
ReportConfiguration& config,
26+
const ReportConfiguration& config,
3027
const VarsToReport& vars_to_report,
3128
bool is_soma_target) override;
3229
void register_custom_report(const NrnThread& nt,
33-
ReportConfiguration& config,
30+
const ReportConfiguration& config,
3431
const VarsToReport& vars_to_report) override;
3532

3633
private:
3734
using create_extra_func = std::function<void(const CellMapping&, std::array<int, 5>&)>;
3835
void register_report(const NrnThread& nt,
39-
ReportConfiguration& config,
36+
const ReportConfiguration& config,
4037
const VarsToReport& vars_to_report,
4138
create_extra_func& create_extra);
4239
#endif // ENABLE_BIN_REPORTS

coreneuron/io/reports/nrnreport.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ struct ReportConfiguration {
101101
double stop; // stop time of report
102102
int num_gids; // total number of gids
103103
int buffer_size; // hint on buffer size used for this report
104-
std::set<int> target; // list of gids for this report
104+
std::vector<int> target; // list of gids for this report
105105
};
106106

107107
void setup_report_engine(double dt_report, double mindelay);

coreneuron/io/reports/report_configuration_parser.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,14 @@ void register_target_type(ReportConfiguration& report, ReportType report_type) {
106106
std::vector<ReportConfiguration> create_report_configurations(const std::string& conf_file,
107107
const std::string& output_dir,
108108
SpikesInfo& spikes_info) {
109-
std::vector<ReportConfiguration> reports;
110109
std::string report_on;
111110
int target;
112111
std::ifstream report_conf(conf_file);
113112

114113
int num_reports = 0;
115114
report_conf >> num_reports;
116-
for (int i = 0; i < num_reports; i++) {
117-
ReportConfiguration report;
115+
std::vector<ReportConfiguration> reports(num_reports);
116+
for (auto& report: reports) {
118117
report.buffer_size = 4; // default size to 4 Mb
119118

120119
report_conf >> report.name >> report.target_name >> report.type_str >> report_on >>
@@ -147,15 +146,13 @@ std::vector<ReportConfiguration> create_report_configurations(const std::string&
147146
parse_filter_string(report_on, report);
148147
}
149148
if (report.num_gids) {
150-
std::vector<int> new_gids(report.num_gids);
149+
report.target.resize(report.num_gids);
151150
report_conf.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
152-
report_conf.read(reinterpret_cast<char*>(new_gids.data()),
151+
report_conf.read(reinterpret_cast<char*>(report.target.data()),
153152
report.num_gids * sizeof(int));
154-
report.target = std::set<int>(new_gids.begin(), new_gids.end());
155153
// extra new line: skip
156154
report_conf.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
157155
}
158-
reports.push_back(report);
159156
}
160157
// read population information for spike report
161158
int num_populations;

coreneuron/io/reports/report_event.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ namespace coreneuron {
2020

2121
#if defined(ENABLE_BIN_REPORTS) || defined(ENABLE_SONATA_REPORTS)
2222
struct VarWithMapping {
23-
int id;
23+
uint32_t id;
2424
double* var_value;
2525
VarWithMapping(int id_, double* v_)
2626
: id(id_)
2727
, var_value(v_) {}
2828
};
2929

3030
// mapping the set of variables pointers to report to its gid
31-
using VarsToReport = std::unordered_map<int, std::vector<VarWithMapping>>;
31+
using VarsToReport = std::unordered_map<uint64_t, std::vector<VarWithMapping>>;
3232

3333
class ReportEvent: public DiscreteEvent {
3434
public:

0 commit comments

Comments
 (0)