Skip to content

Commit

Permalink
core: Reserve vector capacity before MPI gather
Browse files Browse the repository at this point in the history
Co-authored-by: Alexander Reinauer <[email protected]>
  • Loading branch information
jngrad and reinaual authored Aug 7, 2023
1 parent 959ebd4 commit 50af4b1
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/core/observables/utils_histogram.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ template <class Pos>
auto gather(boost::mpi::communicator const &comm,
std::vector<Pos> const &local_pos) {
std::vector<std::vector<Pos>> global_pos{};
global_pos.reserve(comm.size());
boost::mpi::gather(comm, local_pos, global_pos, 0);
return global_pos;
}
Expand All @@ -45,9 +46,12 @@ template <class Pos, class Val>
auto gather(boost::mpi::communicator const &comm,
std::vector<Pos> const &local_pos,
std::vector<Val> const &local_val) {
auto const world_size = comm.size();
std::vector<std::vector<Pos>> global_pos{};
global_pos.reserve(world_size);
boost::mpi::gather(comm, local_pos, global_pos, 0);
std::vector<std::vector<Val>> global_val{};
global_val.reserve(world_size);
boost::mpi::gather(comm, local_val, global_val, 0);
return std::make_pair(global_pos, global_val);
}
Expand Down

0 comments on commit 50af4b1

Please sign in to comment.