diff --git a/src/reports/data/sonata_data.cpp b/src/reports/data/sonata_data.cpp index b43d634..57cb647 100644 --- a/src/reports/data/sonata_data.cpp +++ b/src/reports/data/sonata_data.cpp @@ -23,7 +23,7 @@ SonataData::SonataData(const std::string& report_name, , hdf5_writer_(std::make_unique(report_name)) , nodes_(nodes) { prepare_buffer(max_buffer_size); - index_pointers_.resize(nodes->size() + 1); + index_pointers_.resize(nodes->size()); time_ = {tstart, tend, dt}; reporting_period_ = static_cast(dt / SonataReport::atomic_step_); @@ -207,6 +207,11 @@ void SonataData::prepare_dataset() { total_elements_, element_offset); + int last_rank = Implementation::get_last_rank(report_name_, SonataReport::rank_); + if(SonataReport::rank_ == last_rank) { + index_pointers_.resize(nodes_->size() + 1); + } + // Prepare index pointers if (!index_pointers_.empty()) { index_pointers_[0] = element_offset; diff --git a/src/reports/library/implementation_interface.hpp b/src/reports/library/implementation_interface.hpp index 53bdf8c..9ca5f21 100644 --- a/src/reports/library/implementation_interface.hpp +++ b/src/reports/library/implementation_interface.hpp @@ -33,6 +33,9 @@ struct Implementation { static hsize_t get_offset(const std::string& report_name, hsize_t value) { return TImpl::get_offset(report_name, value); } + static int get_last_rank(const std::string& report_name, int value) { + return TImpl::get_last_rank(report_name, value); + } static hsize_t get_global_dims(const std::string& report_name, hsize_t value) { return TImpl::get_global_dims(report_name, value); } @@ -186,6 +189,12 @@ struct ParallelImplementation { return offset; }; + static int get_last_rank(const std::string& report_name, int value) { + int last_rank = 0; + MPI_Allreduce(&value, &last_rank, 1, MPI_INT, MPI_MAX, get_Comm(report_name)); + return last_rank; + } + static hsize_t get_global_dims(const std::string& report_name, hsize_t value) { hsize_t global_dims = value; MPI_Allreduce(&value, &global_dims, 1, MPI_UNSIGNED_LONG, MPI_SUM, get_Comm(report_name)); @@ -293,6 +302,9 @@ struct SerialImplementation { static hsize_t get_offset(const std::string& /*report_name*/, hsize_t /*value*/) { return 0; }; + static int get_last_rank(const std::string& /*report_name*/, hsize_t /*value*/) { + return 0; + }; static hsize_t get_global_dims(const std::string& /*report_name*/, hsize_t value) { return value; };